text-overflow:ellipsis;
only works when the following are true:
px
(pixels). Width in %
(percentage) won't work.overflow:hidden
and white-space:nowrap
set.The reason you're having problems here is because the width
of your a
element isn't constrained. You do have a width
setting, but because the element is set to display:inline
(i.e. the default) it is ignoring it, and nothing else is constraining its width either.
You can fix this by doing one of the following:
display:inline-block
or display:block
(probably the former, but depends on your layout needs).display:block
and give that element a fixed width
or max-width
.float:left
or float:right
(probably the former, but again, either should have the same effect as far as the ellipsis is concerned).I'd suggest display:inline-block
, since this will have the minimum collateral impact on your layout; it works very much like the display:inline
that it's using currently as far as the layout is concerned, but feel free to experiment with the other points as well; I've tried to give as much info as possible to help you understand how these things interact together; a large part of understanding CSS is about understanding how various styles work together.
Here's a snippet with your code, with a display:inline-block
added, to show how close you were.
.app a {_x000D_
height: 18px;_x000D_
width: 140px;_x000D_
padding: 0;_x000D_
overflow: hidden;_x000D_
position: relative;_x000D_
display: inline-block;_x000D_
margin: 0 5px 0 5px;_x000D_
text-align: center;_x000D_
text-decoration: none;_x000D_
text-overflow: ellipsis;_x000D_
white-space: nowrap;_x000D_
color: #000;_x000D_
}
_x000D_
<div class="app">_x000D_
<a href="">Test Test Test Test Test Test</a>_x000D_
</div>
_x000D_
Useful references: