I am trying to limit the width of an A html element which so it would be snortened and avoid taking too much space on screen.
At this moment I do not have the flexibility of changing the structure of the document so I am looking for a pure CSS solution.
I tried this but it didn't had any effect, the text still takes all the space available.
<html>
<head>
<style>
a.data {
color: red;
text-overflow: ellipsis;
width: 4ch;
max-width: 4ch;
overflow: hidden;
}
</style>
</head>
<body>
<span>
<a class="data">012345668</a>
and some other text
</span>
</body>
</html>
Changing the a's display property to inline-block will do the trick:
a.data {
color: red;
text-overflow: ellipsis;
width: 4ch;
max-width: 4ch;
overflow: hidden;
display: inline-block;
}
<span><a class="data">012345668</a> and some other text</span>
The reason is that the default display for a is inline. inline elements don't accept width, max-width, min-width and the same for height.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With