gpt4 book ai didi

html - 如何在水平线上显示导航栏元素以及网站名称?

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

我是 HTML 和 CSS 编码的新手。我正在尝试创建一个导航栏,其左侧为网站名称,右侧为水平线的所有导航选项。我添加了横幅图片,但运行代码时它没有显示。我希望这个横幅图片出现在导航栏的正下方。我当前的代码在导航栏中垂直显示带有元素符号的选项。请在这方面帮助我。

 .wrapper{
width:600px;
background:#eee;
margin: 0 auto 0 auto;
}

.heading{
height:100px;
background:red;
padding:20px;
text-align: center;
}

.navigation{
height:100px;
background: lightgreen;
width: 400%;
margin-top: 10px;
margin-bottom: 10px;
font-size:16pt;
font-family:impact;
padding:10px;

}

.navigation ul{
list-style-type: none;
display: inline;
text-align: center;
}

.navigation ul li{
list-style: none;
display: inline;
margin-right:30px;
padding:6px;
}

.navigation a{
color:white;
text-decoration: none;
}

.navigation a:hover{
color:black;
}

.banner{
background: url(mtp.png);
background-size: cover;
width: 100%;
height:800px;
position: fixed;
top:100px;
}

.content{
min-height: 100px;
background:#ddd;
width: 400px;
float: left;
position: relative;
}

.sidebar{
width: 200px;
float:right;
background:lightblue;
min-height: 400px;
}

.footer{
clear:both;
background:red;
height:40px;
color:white;
text-align:center;
padding:10px;
}

我的html代码如下:

<!DOCTYPE html>
<html>
<head>
<title>HELLO</title>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<div class="wrapper">
<div class="heading">
<h1>WEBSITE NAME</h1>
</div>
<div class="navigation"
<ul>
<li><a href="#">HOME</a></li>
<li><a href="#">LOGIN</a></li>
<li><a href="#">SIGN UP</a></li>
</ul>
</div>
<div id="container">
<div id="banner">
<h1>This is my banner</h1>
</div>
</div>
<div class="content">
STAY SHOP ATTRACTIONS
</div>
<div class="sidebar">
DINE
</div>
<div class="footer"
All copyrights reserved
</div>
</div>
</body>
</html>

最佳答案

按照以下方式更新你的CSS

li{
list-style:none;
float:left;
margin-right:50px;
}

.heading{
height:100px;
background:red;
padding:20px;


}

wrapper {
width: 600px;
background: #eee;
margin: 0 auto 0 auto;
}
li {
list-style: none;
float: left;
margin-right: 50px;
}
.heading {
height: 100px;
background: red;
padding: 20px;
}
.navigation {
height: 100px;
background: lightgreen;
width: 400%;
margin-top: 10px;
margin-bottom: 10px;
font-size: 16pt;
font-family: impact;
padding: 10px;
}
.navigation ul {
list-style-type: none;
display: inline;
text-align: center;
}
.navigation ul li {
list-style: none;
display: inline;
margin-right: 30px;
padding: 6px;
}
.navigation a {
color: white;
text-decoration: none;
}
.navigation a:hover {
color: black;
}
.banner {
background: url(mtp.png);
background-size: cover;
width: 100%;
height: 800px;
position: fixed;
top: 100px;
}
.content {
min-height: 100px;
background: #ddd;
width: 400px;
float: left;
position: relative;
}
.sidebar {
width: 200px;
float: right;
background: lightblue;
min-height: 400px;
}
.footer {
clear: both;
background: red;
height: 40px;
color: white;
text-align: center;
padding: 10px;
}
<!DOCTYPE html>
<html>

<head>
<title>HELLO</title>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>

<body>
<div class="wrapper">
<div class="heading">
<h1>WEBSITE NAME</h1>
</div>
<div class="navigation" <ul>
<li><a href="#">HOME</a>
</li>
<li><a href="#">LOGIN</a>
</li>
<li><a href="#">SIGN UP</a>
</li>
</ul>
</div>
<div id="container">
<div id="banner">
<h1>This is my banner</h1>
</div>
</div>
<div class="content">
STAY SHOP ATTRACTIONS
</div>
<div class="sidebar">
DINE
</div>
<div class="footer">
All copyrights reserved
</div>
</div>
</body>

</html>

关于html - 如何在水平线上显示导航栏元素以及网站名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41605382/

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