Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ignore element in width

Tags:

css

I'm making a menu that hides information in the buttons. Take a look at the demo code:

ul{
  list-style: none;
  width: 300px;
  height: 300px;
  border: 1px solid black;
  padding: 10px;
}
li{
  display: inline-block;
  float: right;
  clear: both;
  border-radius: 20px;
  border: 1px solid black;
  padding: 10px;
  min-width: 0%;
  margin-bottom: 10px;

  transition: all 0.3s ease;
}
li > span{
  color: gray;
  margin-left: 5px;
  opacity: 0;

  transition: opacity 0.3s ease;
}
li:hover{
  min-width: 100%;
}
li:hover > span{
  opacity: 1;
}

*{
  box-sizing: border-box;
}
<ul>
  <li>FOO<span>BAR</span></li>
  <li>BUTTON<span>More info</span></li>
</ul>

https://jsfiddle.net/DerekL/g8wn74xe/

The li tags should ignore the text in the span as if they are not there (when calculating the width). Is it possible to achieve this effect?

like image 227
Derek 朕會功夫 Avatar asked Mar 10 '26 14:03

Derek 朕會功夫


1 Answers

Set the span font-size to 0 and re-set it on hover

ul{
    list-style: none;
    width: 300px;
    height: 300px;
    border: 1px solid black;
    padding: 10px;
}
li{
    display: inline-block;
    float: right;
    clear: both;
    border-radius: 20px;
    border: 1px solid black;
    padding: 10px;
    min-width: 0%;
    margin-bottom: 10px;
    
    transition: all 0.3s ease;
}
li > span{
    color: gray;
    margin-left: 5px;
    opacity: 0;
    font-size:0;
    
    transition: all 0.3s ease;
}
li:hover{
    min-width: 100%;
}
li:hover > span{
    opacity: 1;
    font-size:inherit;
}

*{
    box-sizing: border-box;
}
<ul>
    <li>FOO<span>BAR</span></li>
    <li>BUTTON<span>More info</span></li>
</ul>
like image 64
Paulie_D Avatar answered Mar 16 '26 21:03

Paulie_D



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!