嗨,我正在尝试创建一个网站,除了导航栏不会移动到屏幕的中心之外,其他一切都进行得很好,当我让导航栏占据整个页面时,它确实转到了中心,但是我只想要导航酒吧要尽可能大,但现在我无法将其放到页面的中央。
这是我的代码如下:
body {
display: block;
margin: 0;
padding: 0px;
}
#header {
background-color: #b9fee2;
width: 1920px;
height: 200px;
display: inline-block;
}
h1 {
font-family: Optima, Segoe, 'Segoe UI', Candara, Calibri, Arial, sans-serif;
font-size: 75px;
font-weight: 500;
text-align: center;
margin: 0px;
color: #000000;
text-decoration: none;
}
h1 a{
text-decoration: none;
}
h1 a:visited {
color: #000000;
text-decoration: none;
}
#nav {
display: inline-block;
-webkit-padding-start: 0px;
text-align: center;
margin: auto;
width: 35%;
}
#nav li {
display: inline-block;
vertical-align: top;
}
#nav a {
-webkit-transition: background-color 0.2s linear;
}
#nav a:link {
display: block;
text-align: center;
color: #000000;
text-decoration: none;
font-family: Georgia, Times, 'Times New Roman', serif;
font-size: 30px;
padding-top: 10px;
padding-bottom: 10px;
padding-left: 50px;
padding-right: 50px;
}
#nav a:visited {
color: #000000;
}
#nav a:hover {
display: block;
text-align: center;
color: #000000;
background-color: #FFFFFF;
text-decoration: none;
padding-left: 50px;
padding-right: 50px;
font-size: 30px;
}
#circle {
padding-top: 25px;
}
#webInfo {
padding-top: 10px;
text-align: center;
font-family: Georgia, Times, 'Times New Roman', serif;
font-size: 25px;
}
#webInfo p{
padding: 0px;
margin:
}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>My Portfolio - Home</title>
<link rel="stylesheet" type="text/css" href="css/style.css" />
</head>
<body>
<div id="header">
<h1><a href="index.html">Alex Trotter</a></h1>
<ul id="nav">
<li><a href="index.html">Home</a></li>
<img id="circle" src="images/circle.png"/>
<li><a href="about.html">About Me</a></li>
<img id="circle" src="images/circle.png"/>
<li><a href="contact.html">Contact</a></li>
</ul>
</div>
<div id="content">
<div id="webInfo">
<p>Hi, my name is Alex Trotter and this is my portfolio website</p>
<p>below you will find some of work that I have created.</p>
<p>Above you can navigate to different pages to learn more about me.</p>
</div>
<div id="exampleWork1"></div>
<div id="exampleWork2"></div>
<div id="exampleWork3"></div>
</div>
</body>
片段:
body {
display: block;
margin: 0;
padding: 0px;
}
#header {
background-color: #b9fee2;
width: 1920px;
height: 200px;
display: inline-block;
}
h1 {
font-family: Optima, Segoe, 'Segoe UI', Candara, Calibri, Arial, sans-serif;
font-size: 75px;
font-weight: 500;
text-align: center;
margin: 0px;
color: #000000;
text-decoration: none;
}
h1 a {
text-decoration: none;
}
h1 a:visited {
color: #000000;
text-decoration: none;
}
#nav {
display: inline-block;
-webkit-padding-start: 0px;
text-align: center;
margin: auto;
width: 35%;
}
#nav li {
display: inline-block;
vertical-align: top;
}
#nav a {
-webkit-transition: background-color 0.2s linear;
}
#nav a:link {
display: block;
text-align: center;
color: #000000;
text-decoration: none;
font-family: Georgia, Times, 'Times New Roman', serif;
font-size: 30px;
padding-top: 10px;
padding-bottom: 10px;
padding-left: 50px;
padding-right: 50px;
}
#nav a:visited {
color: #000000;
}
#nav a:hover {
display: block;
text-align: center;
color: #000000;
background-color: #FFFFFF;
text-decoration: none;
padding-left: 50px;
padding-right: 50px;
font-size: 30px;
}
#circle {
padding-top: 25px;
}
#webInfo {
padding-top: 10px;
text-align: center;
font-family: Georgia, Times, 'Times New Roman', serif;
font-size: 25px;
}
#webInfo p {
padding: 0px;
margin:
}
<div id="header">
<h1><a href="index.html">Alex Trotter</a></h1>
<ul id="nav">
<li><a href="index.html">Home</a>
</li>
<img id="circle" src="images/circle.png" />
<li><a href="about.html">About Me</a>
</li>
<img id="circle" src="images/circle.png" />
<li><a href="contact.html">Contact</a>
</li>
</ul>
</div>
<div id="content">
<div id="webInfo">
<p>Hi, my name is Alex Trotter and this is my portfolio website</p>
<p>below you will find some of work that I have created.</p>
<p>Above you can navigate to different pages to learn more about me.</p>
</div>
<div id="exampleWork1"></div>
<div id="exampleWork2"></div>
<div id="exampleWork3"></div>
</div>
提前致谢!:)
您可以设置width: 100%
为#nav
。但是您的html无效:
ul:允许的内容零个或多个li元素,最终与和元素混合。
我在中移动img
元素li
。还id
必须是唯一使用类,而不是(我改变的元素id
#circle
来.circle
也更新您的CSS)和img
元素必须有标题和alt属性。正确的版本:
body {
display: block;
margin: 0;
padding: 0px;
}
#header {
background-color: #b9fee2;
width: 1920px;
height: 200px;
display: inline-block;
}
h1 {
font-family: Optima, Segoe, 'Segoe UI', Candara, Calibri, Arial, sans-serif;
font-size: 75px;
font-weight: 500;
text-align: center;
margin: 0px;
color: #000000;
text-decoration: none;
}
h1 a {
text-decoration: none;
}
h1 a:visited {
color: #000000;
text-decoration: none;
}
#nav {
display: inline-block;
-webkit-padding-start: 0px;
text-align: center;
margin: auto;
width: 100%;
}
#nav li {
display: inline-block;
vertical-align: top;
}
#nav a {
-webkit-transition: background-color 0.2s linear;
}
#nav a:link {
display: block;
text-align: center;
color: #000000;
text-decoration: none;
font-family: Georgia, Times, 'Times New Roman', serif;
font-size: 30px;
padding-top: 10px;
padding-bottom: 10px;
padding-left: 50px;
padding-right: 50px;
}
#nav a:visited {
color: #000000;
}
#nav a:hover {
display: block;
text-align: center;
color: #000000;
background-color: #FFFFFF;
text-decoration: none;
padding-left: 50px;
padding-right: 50px;
font-size: 30px;
}
.circle {
padding-top: 25px;
}
#webInfo {
padding-top: 10px;
text-align: center;
font-family: Georgia, Times, 'Times New Roman', serif;
font-size: 25px;
}
#webInfo p {
padding: 0px;
margin:
}
<div id="header">
<h1><a href="index.html">Alex Trotter</a></h1>
<ul id="nav">
<li><a href="index.html">Home</a>
<img class="circle" title="circle" alt="circle" src="images/circle.png" />
</li>
<li><a href="about.html">About Me</a>
<img class="circle" title="circle" alt="circle" src="images/circle.png" />
</li>
<li><a href="contact.html">Contact</a>
</li>
</ul>
</div>
<div id="content">
<div id="webInfo">
<p>Hi, my name is Alex Trotter and this is my portfolio website</p>
<p>below you will find some of work that I have created.</p>
<p>Above you can navigate to different pages to learn more about me.</p>
</div>
<div id="exampleWork1"></div>
<div id="exampleWork2"></div>
<div id="exampleWork3"></div>
</div>
使用OP代码的解决方案:
body {
display: block;
margin: 0;
padding: 0px;
}
#header {
background-color: #b9fee2;
width: 1920px;
height: 200px;
display: inline-block;
}
h1 {
font-family: Optima, Segoe, 'Segoe UI', Candara, Calibri, Arial, sans-serif;
font-size: 75px;
font-weight: 500;
text-align: center;
margin: 0px;
color: #000000;
text-decoration: none;
}
h1 a {
text-decoration: none;
}
h1 a:visited {
color: #000000;
text-decoration: none;
}
#nav {
display: inline-block;
-webkit-padding-start: 0px;
text-align: center;
margin: auto;
width: 100%;
}
#nav li {
display: inline-block;
vertical-align: top;
}
#nav a {
-webkit-transition: background-color 0.2s linear;
}
#nav a:link {
display: block;
text-align: center;
color: #000000;
text-decoration: none;
font-family: Georgia, Times, 'Times New Roman', serif;
font-size: 30px;
padding-top: 10px;
padding-bottom: 10px;
padding-left: 50px;
padding-right: 50px;
}
#nav a:visited {
color: #000000;
}
#nav a:hover {
display: block;
text-align: center;
color: #000000;
background-color: #FFFFFF;
text-decoration: none;
padding-left: 50px;
padding-right: 50px;
font-size: 30px;
}
#circle {
padding-top: 25px;
}
#webInfo {
padding-top: 10px;
text-align: center;
font-family: Georgia, Times, 'Times New Roman', serif;
font-size: 25px;
}
#webInfo p {
padding: 0px;
margin:
}
<div id="header">
<h1><a href="index.html">Alex Trotter</a></h1>
<ul id="nav">
<li><a href="index.html">Home</a>
</li>
<img id="circle" src="images/circle.png" />
<li><a href="about.html">About Me</a>
</li>
<img id="circle" src="images/circle.png" />
<li><a href="contact.html">Contact</a>
</li>
</ul>
</div>
<div id="content">
<div id="webInfo">
<p>Hi, my name is Alex Trotter and this is my portfolio website</p>
<p>below you will find some of work that I have created.</p>
<p>Above you can navigate to different pages to learn more about me.</p>
</div>
<div id="exampleWork1"></div>
<div id="exampleWork2"></div>
<div id="exampleWork3"></div>
</div>
参考
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句