我是学习HTML和CSS的新手,我真的很难应对响应式设计。我想让我的导航栏响应,我认为最好的方法是编辑填充。如果有人能给我一些指示,我会非常感激。
.navbar-left {
float: left;
font-size: 16px;
color: black;
text-align: center;
padding: 36px 29px;
text-decoration: none;
font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
}
.navbar-center {
float: left;
font-size: 30px;
color: black;
text-align: center;
padding: 27px 311px;
text-decoration: none;
font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
}
.navbar-right {
float: left;
font-size: 16px;
color: black;
text-align: center;
padding: 36px 29px;
text-decoration: none;
font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
}
.navbar-left:hover,
.navbar-right:hover {
background-color: #f8f8f8;
}
<nav>
<a class="navbar-left" href="bio.html">About</a>
<a class="navbar-left" href="resume.html">Resume</a>
</nav>
<nav>
<a class="navbar-center" href="index.html">Sydnie Knowlton</a>
</nav>
<nav>
<a class="navbar-right" href="works.html">Portfolio</a>
<a class="navbar-right" href="contact.html">Contact</a>
</nav>
答案 0 :(得分:1)
将您的三个nav
的宽度设置为33.33%
并将它们全部浮动到左侧
不要依赖侧边填充,请使用width:50%
,以便nav
内的两个链接填充内部空间,text-align:center
将内容置于中心
* {
box-sizing: border-box;
}
nav {
width: 33.33%;
float: left;
}
.navbar-left {
float: left;
font-size: 16px;
color: black;
text-align: center;
padding: 36px 2%;
text-decoration: none;
font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
width: 50%;
}
.navbar-center {
float: left;
font-size: 30px;
color: black;
text-align: center;
padding: 27px 0;
text-decoration: none;
font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
text-align: center;
}
.navbar-right {
float: right;
font-size: 16px;
color: black;
text-align: center;
padding: 36px 2%;
text-decoration: none;
font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
width: 50%;
}
.navbar-left:hover,
.navbar-right:hover {
background-color: #f8f8f8;
}
&#13;
<nav>
<a class="navbar-left" href="bio.html">About</a>
<a class="navbar-left" href="resume.html">Resume</a>
</nav>
<nav>
<a class="navbar-center" href="index.html">Sydnie Knowlton</a>
</nav>
<nav>
<a class="navbar-right" href="works.html">Portfolio</a>
<a class="navbar-right" href="contact.html">Contact</a>
</nav>
&#13;