gpt4 book ai didi

css - 如何使填充响应

转载 作者:行者123 更新时间:2023-11-28 11:58:00 28 4
gpt4 key购买 nike

我刚开始学习 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>

最佳答案

将三个 nav 的宽度设置为 33.33% 并将它们全部 float 到左侧

不要依赖侧边距,使用 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;
}
<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>

关于css - 如何使填充响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50093093/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com