当前位置: 动力学知识库 > 问答 > 编程问答 >

nav with display: inline-block not centering in css?

问题描述:

I am trying to center my nav with display:inline-block in css?

nav {

position: fixed;

width: 100%;

}

nav ul {

width: 100%;

margin: auto;

}

nav ul li {

display: inline-block;

margin: 5px 20px 5px 20px;

text-align: center;

}

网友答案:

Simply add text-align:center; to the parent element of the inline-block element.

nav {
position: fixed;
width: 100%;
}

nav ul {
width: 100%;
margin: auto;
text-align:center;
}

nav ul li {
display: inline-block; 
margin: 5px 20px 5px 20px;
text-align: center; 
}
分享给朋友:
您可能感兴趣的文章:
随机阅读: