I’ve tried it adding a width, but the links are set to be responsive. I’ve also tried adding width: 100% which makes it the width of the longest link text.
You know by now that an inline element doesn’t obey width don’t you?
If the links are inline elements then you will need to set them to display:inline-block and then they will shrink wrap the content but still obey max-width.
The button element is a replaced element and behaves just like display:inline-block by default which is why the button in my example honours the width (or a max-width).
Here’s an example using an anchor.
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Untitled Document</title>
<style>
ul{margin:0;padding:0;list-style:none;}
.category-groups{
padding:10px;
max-width:150px;/* for testing*/
margin:auto;
}
.category-groups li{font-size:0;}/* dirty white-space hack*/
.category-groups ul li a{
display:inline-block;
box-shadow: none;
border-left: 7px solid #f9dc5c;
padding:2px;
margin-bottom:16px;
background: #fdfdfd;
font-size: 16px;
color: #444;
white-space:nowrap;
text-overflow:ellipsis;
overflow:hidden;
max-width:100%;
text-decoration:none;
}
.category-groups ul li a:hover{overflow:visible;z-index:10;}
</style>
</head>
<body>
<div class="category-groups">
<ul>
<li><a href="#">This is some overflowing text</a></li>
<li><a href="#">This is text</a></li>
<li><a href="#">This is some overflowing text a bit longer</a></li>
<li><a href="#">Text</a></li>
<li><a href="#">This is some text</a></li>
<li><a href="#">This is some overflowing text</a></li>
<li><a href="#">This is some text></a></li>
</ul>
</div>
</body>
</html>
The inner span is only needed if you need to style the overflowing text.
I had to set the link to display:block as they were appearing different widths.
The hover works great, but sometimes the text overlaps the counter I have on the right hand side. I’m wondering is it possible to have the hover has a scroll effect that will slowly scroll to the left so it displays the full text to the right?
I’m guessing I will need to set a negative left on hover?
I meant to reply to this before I went out but there are a few things you can try if you can’t wait until I get back to a computer.
My first thoughts are to remove the overflow ellipsis on hover and set the text to text-align:right and add a transition so it doesn’t happen immediately.
If that doesn’t work then you could use transform on the span to translate it left with a negative percentage. You will still need to negate the ellipsis on hover.
There’s probably a load of other ways to do this also but those were my first thoughts
The text-align:right didn’t work but text-indent seems to work ok.
e.g.
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Untitled Document</title>
<style>
ul{margin:0;padding:0;list-style:none;}
.category-groups{
padding:10px;
max-width:150px;/* for testing*/
margin:auto;
}
.category-groups li{font-size:0;}
.category-groups ul li a{
display:inline-block;
box-shadow: none;
border-left: 7px solid #f9dc5c;
padding:2px;
margin-bottom:16px;
background: #fdfdfd;
font-size: 16px;
color: #444;
white-space:nowrap;
text-overflow:ellipsis;
overflow:hidden;
max-width:100%;
text-decoration:none;
transition: all 1s ease;
}
.category-groups ul li a:hover{
text-overflow:unset;
text-indent:-100%;
transition: all 1s ease;
}
</style>
</head>
<body>
<div class="category-groups">
<ul>
<li><a href="#">This is some overflowing text</a></li>
<li><a href="#">This is text</a></li>
<li><a href="#">This is some overflowing text a bit longer</a></li>
<li><a href="#">Text</a></li>
<li><a href="#">This is some text</a></li>
<li><a href="#">This is some overflowing text</a></li>
<li><a href="#">This is some text</a></li>
</ul>
</div>
</body>
</html>
It doesn’t need the extra span with this method.
It may be better to use an animation instead so that it goes backwards and forwards and doesn’t leave touch users in the hover state.
e.g.
However there may still be an issue for touch users as they would need to touch somewhere else if they wanted to see the message again and of course if these are real links the page may navigate away anyway.
Thank you so much for the reply, that looks amazing! I think with mobile, it would be ok as the links become full width so all text would be displayed.