gpt4 book ai didi

css - 尝试创建网页。导航栏上的文本居中问题

转载 作者:太空宇宙 更新时间:2023-11-04 01:51:03 25 4
gpt4 key购买 nike

我正在使用 Pixel Perfect 来尝试复制网页以用于学习目的。我真的很难尝试创建它。对于初学者,我的文本不会停留在导航栏的中心。我认为这可能是我的标题的问题。我可能不小心组合了标题和导航。我不确定如何解决它。

The page I am trying to copy

我的 html:

  <body>
<div id="wrapper">
<header>
<div id="bluebox"><h1>Main Title Here</h1></div>
<div id="outerbox"></div>
<div id="navbox"></div>
</header>
<div class="navigation-bar">
<nav>
<ul>
<li><a href="home.html">Home</a></li>
<li><a href="about.html">About</a></li>
<li><a href="portfolio.html">Portfolio</a></li>
<li><a href="contact.html">Contact</a></li>
</ul>
</nav>
</div>

我的CSS:

/* general */
*{margin: 0; padding: 0;}
body {font-size: 100%; line-height: 1.5em; font-family: 'arial'; }
article, aside, figure, footer, header, main, menu, nav, section, video {display: block;}

/* wrapper */
#wrapper {width: 1024px; margin: 0 auto; }

/* header */
#wrapper header {height: 50px; padding-top: 128px; padding-right: 0px;
padding-bottom: 0px; padding-left: 0px;}
#wrapper h1 {font-family: "arial"; color: #FFF; top: 70px; position: absolute; padding-left: 195px; font-size: 2.75em;}
#bluebox{
background-color: #23b6eb;
width: 1020px;
height: 140px;
position: absolute;
top: 30px;
}
#outerbox{
background-color: #5d5a5a;
width: 1020px;
height: 30px;
position: absolute;
top: 0px;
}

/* navigation */

#navbox{
background-color: #BBB;
width: 1020px;
height: 40px;
position: absolute;
top: 170px;
}

.navigation-bar {display: inline-block; font-weight: bold; font-size: 1.2em; vertical-align: center; text-align: center;}
nav ul li span, nav ul li a {text-decoration: none; color: #000; }

最佳答案

同样的正确方法。我更改了以下内容:

  1. 完全摆脱position: absolute
  2. line-height替换所有的height
  3. 去除不必要的标签,如 outer-box
  4. 尽可能使用语义标签。

/* general */

* {
margin: 0;
padding: 0;
}

body {
font-size: 100%;
line-height: 1.5em;
font-family: 'arial';
}

article, aside, figure, footer, header, main, menu, nav, section, video {
display: block;
}

/* wrapper */
#wrapper {
width: 1024px;
margin: 0 auto;
padding: 20px 0;
background-color: #5d5a5a;
}

/* header */
#wrapper header {
background-color: #23b6eb;
}

#wrapper header h1 {
font-family: "arial";
color: #fff;
font-size: 2.75em;
text-align: center;
line-height: 2.5;
}


/* navigation */
nav ul {
text-align: center;
background-color: #ccc;
}

nav ul li {
display: inline-block;
padding: 0 25px;
}

nav ul li a {
text-decoration: none;
color: #000;
}
<div id="wrapper">
<header>
<h1>Main Title Here</h1>
</header>
<nav>
<ul>
<li><a href="home.html">Home</a></li>
<li><a href="about.html">About</a></li>
<li><a href="portfolio.html">Portfolio</a></li>
<li><a href="contact.html">Contact</a></li>
</ul>
</nav>
</div>

预览

preview

关于css - 尝试创建网页。导航栏上的文本居中问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43478997/

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