Reputation: 121
HTML:
<ul>
<li><a href="">someloooooooooooooooooooooong text </a></li>
<li><a href="">someloooooooooooooooooooooong text </a></li>
</ul>
How can I add borders like this?
My CSS:
ul {
display: block;
width: 255px;
border: 1px solid #007ab6;
}
ul a {
width: 225px;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
}
ul a:hover {
overflow: visible;
width: unset;
display: inline-block;
border: 1px solid;
background: #ebf7fd;
}
This is how it looks, but it is not exactly what I want.
Upvotes: 2
Views: 1352
Reputation: 36
.wrapper{
display: flex;
align-items: flex-start;
flex-direction: column;
border-collapse: collapse;
}
a{
flex:1;
border:1px solid red;
}
[is this what you are going for to some extent?][1] [1]: https://i.sstatic.net/Wpp01.png
<div class="wrapper">
<a>SOMElongtexttt</a>
<a>SOMMMMMMMMMMMMMMMMMMEEEEEEEEEEEEEEEE</a>
</div>
Upvotes: 0
Reputation: 3137
Well, technically, it is possible with overlapping blocks with a negative margin, but a bit tricky. You can see an example in the snippet below.
ul {
display: block;
width: 255px;
list-style: none;
margin: 0;
padding: 0;
font-size: 0;
line-height: 0;
}
ul li {
font-size: 16px;
box-sizing: border-box;
line-height: 2;
padding: 0 10px;
width: 100%;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
display: inline-block;
border: 1px solid #007ab6;
border-bottom-color: transparent;
border-top-color: transparent;
background: #ebf7fd;
position: relative;
z-index: 1;
margin: -1px 0;
}
ul li:first-child {border-top-color: #007ab6;}
ul li:last-child {border-bottom-color: #007ab6;}
ul li:hover {
overflow: visible;
width: auto;
min-width: 100%;
border-color: #007ab6;
margin: 0;
z-index: 0;
line-height: calc(2em - 2px);
}
ul li:first-child:hover,
ul li:last-child:hover {
margin: -1px 0;
line-height: 2;
}
<ul>
<li><a href="">someloooooooooooooooooooooong text </a></li>
<li><a href="">text </a></li>
<li><a href="">someloooooooooooooooooooooong text </a></li>
<li><a href="">someloooooooooooooooooooooong text </a></li>
</ul>
UPD: Now it works with hover
effect.
Upvotes: -1
Reputation: 761
I have used pseudo elements for adding border and background color on hover. Also you can add as many lists as you want. No need to handle each list separately.
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
ul {
display: block;
width: 255px;
border: 1px solid #007ab6;
list-style: none;
background: #fff;
margin: 10px;
}
ul li {
white-space: nowrap;
overflow: hidden;
width: 100%;
text-overflow: ellipsis;
display: inline-block;
position: relative;
vertical-align: middle;
}
ul li:before {
content: '';
position: absolute;
top: -1px;
left: -1px;
right: -1px;
bottom: -1px;
background: #ffffff;
border: 1px solid;
z-index: -3;
box-sizing: border-box;
}
ul li:after {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: #fff;
z-index: -2;
}
ul li:hover {
overflow: visible;
width: auto;
}
ul li a {
position: relative;
z-index: 1;
text-decoration: none;
background: #fff;
padding: 10px;
display: inline-block;
}
<ul>
<li><a href="">someloooooooooooooooooooooong text </a></li>
<li><a href="">someloooooooooooooooooooooong text </a></li>
<li><a href="">someloooooooooooooooooooooong text </a></li>
<li><a href="">someloooooooooooooooooooooong text </a></li>
</ul>
Upvotes: 3