how to set css width equal to length of longest text

前端 未结 3 866
时光取名叫无心
时光取名叫无心 2020-12-14 18:18

I have quite a challenging task.

I have this menu here... http://jsfiddle.net/K2Zzh/6/

If you hover over \'treatments\', the width for the dropdown menu is s

相关标签:
3条回答
  • 2020-12-14 18:59

    Put the width to "li" instead of "a" , and you can use padding too

    .dropdown ul li {
        width: auto;
        padding:5px;
        display:block;
    }​
    

    i think it should works

    0 讨论(0)
  • 2020-12-14 19:04

    first step: remove fixed width from .dropdown ul li a

    second step: add the css li li {width:100%;}

    third step: add .mainNav li a {white-space:nowrap;}

    It's ready: http://jsfiddle.net/K2Zzh/10/

    0 讨论(0)
  • 2020-12-14 19:09

    Try white-space: nowrap and width: auto in your .dropdown ul li a class

    http://jsfiddle.net/K2Zzh/8/

    0 讨论(0)
提交回复
热议问题