Padding-top not working

…衆ロ難τιáo~ 提交于 2019-12-18 18:37:53

问题



Why doesn't padding-top work? The height of the div is set.

HTML:

<div class="menu">
    <a href="#">APIE MUS</a>
    <a href="#">REKLAMA</a>
    <a href="#">PARTNERIAI</a>
</div>

CSS:

 .menu {
      width: 300px;
      height: 30px;
      background: red;
 }
 .menu a {
      padding-top: 10px;
 }

回答1:


Your example (with margin) does not work because you can't apply margin to inline elements like a, span, b.

Take a look:

  • http://www.webdesignfromscratch.com/html-css/css-block-and-inline/
  • http://webdesign.about.com/od/htmltags/qt/block_vs_inline_elements.htm

To fix your issue:

Just add display:inline-block;

This value (inline-block) causes an element to generate an inline-level block container. The inside of an inline-block is formatted as a block box, and the element itself is formatted as an atomic inline-level box. Source: http://www.w3.org/TR/CSS2/visuren.html#inline-level

So this will fix your issue:

.menu a{
    margin-top: 10px;
    display:inline-block;
}


来源:https://stackoverflow.com/questions/14604541/padding-top-not-working

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