简体   繁体   English

<ul>显示内联块不起作用

[英]<ul> display inline-block not working

My jsFiddle is here : https://jsfiddle.net/r1s6651y/1/ 我的jsFiddle在这里: https ://jsfiddle.net/r1s6651y/1/

I am not able to get Navigation with Numerals to be aligned horizontally. 我无法将“数字导航”水平对齐。

I have applied display : inline-block for upper ul but still the next menu item begins on the second line. 我已将display : inline-block用于上ul但下一个菜单项仍从第二行开始。

Any clues ? 有什么线索吗?

It should be stacked as : 它应堆叠为:

1111111    22222222

AAAAAAAAAAAAA

BBBBBBBBBBBBB

You can't have li with width: 100%; liwidth: 100%;不能为width: 100%; and then expect them to align next to eachother. 然后期望它们彼此对齐。 Ofcourse they naturally fall to 2 lines instead of 1, they're inline elements after all (Think of it like this: the <p> tag is also "inline" bu default. When the text in a <p> is too long, the text "breaks" to a new line. As will your li when it is set to be inline) . 当然,它们自然会降为2行而不是1行,它们毕竟是内联元素(这样想: <p>标签也是默认的“ inline”。当<p>的文本太长时,文字会“换行”到新行。当您将li设置为inline时,也会如此 You also want the li to next to eachother, not the ul which is what contains the li . 您还希望li到旁边的海誓山盟,而不是ul这正是包含了li So apply the display: inline-block; 因此,应用display: inline-block; to the (correct) li elements (正确的) li元素

    ul#myRow li {
      width: auto; //could also be set to 50%  if it's just 2 li elements
      display: inline-block;
    }

Two things. 两件事情。 As already noted, you want the li items to be display:inline . 如前所述,您希望li项目display:inline You also need to remove the width:100% from the li s of #myRow . 您还需要从#myRowli删除width:100% Then it will collapse and display inline as long as the container is wide enough for them (otherwise it will wrap). 然后,只要容器对它们足够宽,它就会折叠并内联显示(否则它将包装)。

 li { background: #00945f; border-bottom: 1px solid #016e39; clear: both; float: none; height: 62px; margin: 0; padding: 0 30px 30px; width: 100%; } ul { list-style-type: none; } ul#myRow li { display:inline-block; width: auto; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <section> <ul id="myRow" class="row"> <li> <a href="" class="active">11111111</a> </li> <li> <a href="">2222222</a> </li> </ul> <ul class="row"> <li> <a href="">AAAAAAAAAAAAAAa</a> </li> <li> <a href="">BBBBBBBBBBBBBBB</a> </li> </ul> </section> 

Man, you do some mistakes. 伙计,你犯了一些错误。 I fixed it at: https://jsfiddle.net/r1s6651y/4/ 我将其修复为: https : //jsfiddle.net/r1s6651y/4/

li {
    display: inline-block;
    background: #00945f;
    border-bottom: 1px solid #016e39;
    margin: 0;
    padding: 10px 20px;
}

put a class on the li you want horizontal, then add css display: inline 将一个class放在想要水平放置的li ,然后添加css display: inline

 .horiz { display: inline; } 
 <section> <ul id="myRow" class="row"> <li class="horiz"> <a href="" class="active">11111111</a> </li> <li class="horiz"> <a href="">2222222</a> </li> </ul> <ul class="row"> <li> <a href="">AAAAAAAAAAAAAAa</a> </li> <li> <a href="">BBBBBBBBBBBBBBB</a> </li> </ul> </section> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM