gpt4 book ai didi

html - CSS 导航栏的问题

转载 作者:行者123 更新时间:2023-11-28 15:56:48 25 4
gpt4 key购买 nike

我正在尝试使用 HTML 和 CSS 创建导航栏。但是,导航栏并没有像我希望的那样延伸到页面末尾。我试过使用 padding-left-: 0pxpadding-right: 0px; 但这不起作用。

这是我目前的工作:

$banner-height: 50px;
@import 'https://fonts.googleapis.com/css?family=Work+Sans:400,500,900';

nav {
height: $banner-height * 2;
position: fixed;
width: 100%;
top: 0;
transition: top 0.2s ease-out;
}

.banner {
text-align: center;
line-height: $banner-height;
top: 0;
width: 100%;
background: #FEFFB7;
box-shadow: inset 0px -1px 0px 0px rgba(0,0,0,0.13);
}

.nav-bar {
top: $banner-height;
/* Rectangle 1: */
background: #FFFFFF;
box-shadow: 0px 2px 2px 0px rgba(0,0,0,0.11), 0px 4px 6px 0px rgba(0,0,0,0.11);
width: 100%;
line-height: $banner-height;
text-align: center;
}

.nav-up {
top: -$banner-height;
}

//-------------------------------------------------------
/*Strip the ul of padding and list styling*/
ul {
list-style-type:none;
margin:0;

position: absolute;
}
/*Create a horizontal list with spacing*/
li {
display:inline-block;
float: center;
margin-right: 1px;
}
/*Style for menu links*/
li a {
display:block;
min-width:140px;
height: 50px;
text-align: center;
line-height: 50px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
color: #fff;
background: #2f3036;
text-decoration: none;
}
/*Hover state for top level links*/
li:hover a {
background: #19c589;
}
/*Style for dropdown links*/
li:hover ul a {
background: #f3f3f3;
color: #2f3036;
height: 40px;
line-height: 40px;
}
/*Hover state for dropdown links*/
li:hover ul a:hover {
background: #19c589;
color: #fff;
}
/*Hide dropdown links until they are needed*/
li ul {
display: none;
}
/*Make dropdown links vertical*/
li ul li {
display: block;
float: none;
}
/*Prevent text wrapping*/
li ul li a {
width: auto;
min-width: 100px;
padding-left: 0px;
padding-right: 0px;
}
/*Display the dropdown on hover*/
ul li a:hover + .hidden, .hidden:hover {
display: block;
}
/*Style 'show menu' label button and hide it by default*/
.show-menu {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
text-decoration: none;
color: #fff;
background: #19c589;
text-align: center;
padding-left: 0px;
padding-right: 0px;
display: none;
}
/*Hide checkbox*/
input[type=checkbox]{
display: none;
}
/*Show menu when invisible checkbox is checked*/
input[type=checkbox]:checked ~ #menu{
display: block;
}
/*Responsive Styles*/
@media screen and (max-width : 760px){
/*Make dropdown links appear inline*/
ul {
position: static;
display: none;

}
/*Create vertical spacing*/
li {
margin-bottom: 1px;
}
/*Make all menu links full width*/
ul li, li a {
width: 100%;
}
/*Display 'show menu' link*/
.show-menu {
display:block;
}
}
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Untitled Document</title>

</head>

<body>

<nav class="nav-down">
<div class="banner animated">I'm a banner</div>
<div class="nav-bar"> <label for="show-menu" class="show-menu">Show Menu</label>
<input type="checkbox" id="show-menu" role="button">
<ul id="menu" >
<li><a href="#">Home</a></li>
<li>
<a href="#">About</a>
</li>
<li>
<a href="#">Portfolio</a>
</li>
<li><a href="#">News</a></li>
<li><a href="#">Contact</a></li>
</ul></div>
</nav>
</body>
</html>

问题:

enter image description here

enter image description here

(全屏查看以查看完整问题)。

最佳答案

已更新:代码段、flexbox 和 padding 中的解决方案留给 UL 设置为 0。

看到一些与嵌入代码段不一致的行为,所以这里是一个 fiddle :

https://jsfiddle.net/2u1kzy3c/

$banner-height: 50px;
@import 'https://fonts.googleapis.com/css?family=Work+Sans:400,500,900';

nav {
height: $banner-height * 2;
position: fixed;
width: 100%;
top: 0;
transition: top 0.2s ease-out;
}

.banner {
text-align: center;
line-height: $banner-height;
top: 0;
width: 100%;
background: #FEFFB7;
box-shadow: inset 0px -1px 0px 0px rgba(0,0,0,0.13);
}

nav ul#menu {
padding-left: 0;
display: flex;
}

nav ul li {
flex-grow: 1;
}

.nav-bar {
top: $banner-height;
/* Rectangle 1: */
background: #FFFFFF;
box-shadow: 0px 2px 2px 0px rgba(0,0,0,0.11), 0px 4px 6px 0px rgba(0,0,0,0.11);
width: 100%;
line-height: $banner-height;
text-align: center;
}

.nav-up {
top: -$banner-height;
}

//-------------------------------------------------------
/*Strip the ul of padding and list styling*/
ul {
list-style-type:none;
margin:0;

position: absolute;
}
/*Create a horizontal list with spacing*/
li {
display:inline-block;
float: center;
margin-right: 1px;
}
/*Style for menu links*/
li a {
display:block;
min-width:140px;
height: 50px;
text-align: center;
line-height: 50px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
color: #fff;
background: #2f3036;
text-decoration: none;
}
/*Hover state for top level links*/
li:hover a {
background: #19c589;
}
/*Style for dropdown links*/
li:hover ul a {
background: #f3f3f3;
color: #2f3036;
height: 40px;
line-height: 40px;
}
/*Hover state for dropdown links*/
li:hover ul a:hover {
background: #19c589;
color: #fff;
}
/*Hide dropdown links until they are needed*/
li ul {
display: none;
}
/*Make dropdown links vertical*/
li ul li {
display: block;
float: none;
}
/*Prevent text wrapping*/
li ul li a {
width: auto;
min-width: 100px;
padding-left: 0px;
padding-right: 0px;
}
/*Display the dropdown on hover*/
ul li a:hover + .hidden, .hidden:hover {
display: block;
}
/*Style 'show menu' label button and hide it by default*/
.show-menu {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
text-decoration: none;
color: #fff;
background: #19c589;
text-align: center;
padding-left: 0px;
padding-right: 0px;
display: none;
}
/*Hide checkbox*/
input[type=checkbox]{
display: none;
}
/*Show menu when invisible checkbox is checked*/
input[type=checkbox]:checked ~ #menu{
display: block;
}
/*Responsive Styles*/
@media screen and (max-width : 760px){
/*Make dropdown links appear inline*/
nav ul#menu {
position: static;
display: none;

}
/*Create vertical spacing*/
li {
margin-bottom: 1px;
}
/*Make all menu links full width*/
ul li, li a {
width: 100%;
}
/*Display 'show menu' link*/
.show-menu {
display:block;
}
}
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Untitled Document</title>

</head>

<body>

<nav class="nav-down">
<div class="banner animated">I'm a banner</div>
<div class="nav-bar"> <label for="show-menu" class="show-menu">Show Menu</label>
<input type="checkbox" id="show-menu" role="button">
<ul id="menu" >
<li><a href="#">Home</a></li>
<li>
<a href="#">About</a>
</li>
<li>
<a href="#">Portfolio</a>
</li>
<li><a href="#">News</a></li>
<li><a href="#">Contact</a></li>
</ul></div>
</nav>
</body>
</html>

关于html - CSS 导航栏的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50645870/

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