Centering lists in Zurb Foundation

核能气质少年 提交于 2019-12-06 00:16:03

问题


I am having trouble centering inline lists when using Zurb's Foundation 4.

The prebuilt css classes of 'text-center' and 'centered' work fine for other elements but not with lists.

A review of an older question concerning images has similar results.

This doesnt work:

    <div class="row">
      <div class="large-12 columns text-center">
        <ul class="inline-list">
          <li><a href="#">One</a></li>
          <li><a href="#">Two</a></li>
          <li><a href="#">Three</a></li>
          <li><a href="#">Four</a></li>
          <li><a href="#">Five</a></li>
        </ul>
      </div>
    </div>

However, when removing the this does work (but obviously is not preferred markup):

    <div class="row">
      <div class="large-12 columns text-center">
          <a href="#">One</a>
          <a href="#">Two</a>
          <a href="#">Three</a>
          <a href="#">Four</a>
          <a href="#">Five</a>
      </div>
    </div>

Do you have a suggestion on how lists can be affected by this style.

Thanks.


回答1:


I think it is as simple as adding the following to your CSS file:

.inline-list{
     display: table;
     margin: 0 auto;
}

You can also remove the text-center class from your column div. I created a codepen, http://cdpn.io/rwJjf, as an example. I used Foundation 5.0.3 in my example, but I don't think it will matter.

Here are the resouces I used:

  • Centering List Items Horizontally (Slightly Trickier Than You Might Think)
  • display
  • The display declaration

I hope that helps.




回答2:


I couldn't get Adam's solution to work, but found that Foundation's .inline-list floats <li> to the left, so it's easier to just apply the CSS to a <ul class="text-center">:

ul {
 list-style-type:none;
}

li {
 display: inline-block;
}

Here it is working: http://cdpn.io/eGsky

As answered here: http://foundation.zurb.com/forum/posts/1096-centering-an-inline-list



来源:https://stackoverflow.com/questions/20518615/centering-lists-in-zurb-foundation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!