Using margin with display table-cell [duplicate]

删除回忆录丶 提交于 2019-12-10 13:30:29

问题


I have try adding margin-left/margin-right in li but it doesn't give them a space in between. What should I add to make a space in between the list ?

CSS:

.btn-top {
    float: right;
    height: 40px;
    margin-right: 10px;
    margin-top: 10px;
}
.btn-top ul {
     height: 100%;
     padding: 0;
}
.btn-top ul li {
    list-style-type: none;
    display: table-cell;
    width: 100px;
    height: 30px;
    vertical-align: middle;
    text-align: center;
    border-style: solid;
    border-color: #333;
    border-width: 2px;
    border-radius: 10px;
}

HTML:

<div class="btn-top"><ul>
     <li><a href="#"><span class="btn" =>btn1</span></a></li>
     <li style="width:150px"><a href="#"><span class="btn">btn2</span></a></li>
</ul>

回答1:


display: table-cell makes your element display just as if it were in a <table>, where, unfortunately, doesn't work well with margins. You could add another <div> inside this element and give this one a margin, or simply give it padding. It depends on the desired design, really.



来源:https://stackoverflow.com/questions/20827393/using-margin-with-display-table-cell

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