我是HTML的新手,我正在尝试弄清楚如何将UL列表项对齐在一行中。
我刚刚开始学习HTML。我已经检查了10多个Stack Overflow问题,但没有一个是有效的。这是代码:
display :inline;
float: right;
margin: 0px;
padding: 0px;
这是我的html标记,你能帮我检查一下是否有错误吗?
@font-face {
font-family:'BrandonGrotesqueBold';
src: url('file:///C:/Users/MyName/Desktop/project/fonts/BrandonGrotesqueBold.ttf');
}
@font-face {
font-family:'BrandonGrotesqueLight';
src: url('file:///C:/Users/MyName/Desktop/project/fonts/BrandonGrotesqueLight.ttf');
}
body {
padding-top: 105px;
color: #CDCDCD;
font-family:'BrandonGrotesqueBold';
}
.mainHeader {
margin-left: auto;
margin-right: auto;
padding-left: 20px;
padding-right: 20px;
width: 1060px;
font-size: 22px;
font-stretch: none;
}
.mainNav {
margin-bottom: 70px;
}
.mainLogo {
font-weight: 500;
s color: black;
font-size: 40px;
}
.thinMainLogo {
font-family:'BrandonGrotesquelight';
}
li {
list-style-type: none;
}
.mainLoc {
float: right;
display: inline;
}

<!DOCTYPE html>
<title>My Company Name</title>
<link rel="stylesheet" href="css/main.css">
</head>
<body>
<header class="mainHeader">
<nav class="mainNav">
<h1 class="mainLogo">My <span class="thinMainLogo">Logo</span></h1>
<ul class="mainLoc">
<li>About</li>
<li>PortFolio</li>
<li>Contact</li>
<li>Blog</li>
</ul>
</nav>
</header>
</body>
</html>
&#13;
答案 0 :(得分:4)
这是您将它们放在同一行上所需的CSS:
ul.mainLoc li {
display: inline-block;
margin-left: 10px; // for item spacing
}
答案 1 :(得分:1)
立即检查http://jsfiddle.net/bLc5eqgp/3/
.mainLoc li {
padding: 0 10px;
display: inline;
}
将css添加到你的小提琴上。
答案 2 :(得分:0)
将display: inline
添加到.mainLogo
,将display: inline-block
添加到li
以下是完整的 CSS
body {
padding-top: 105px;
color: #CDCDCD;
font-family:'BrandonGrotesqueBold';
}
.mainHeader {
margin-left: auto;
margin-right: auto;
padding-left: 20px;
padding-right: 20px;
width: 1060px;
font-size: 22px;
font-stretch: none;
}
.mainNav {
margin-bottom: 70px;
}
.mainLogo {
font-weight: 500;
color: black;
font-size: 40px;
display: inline;
}
.thinMainLogo {
font-family:'BrandonGrotesquelight';
}
li {
display: inline-block;
list-style-type: none;
}
.mainLoc {
float: right;
display: inline;
}
检查此JS Fiddle