gpt4 book ai didi

html - 减少填充,初学者 CSS

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

我希望我正在处理的页面顶部的导航按钮(请参阅帖子末尾的链接)更像下图,即它们应该显示为选项卡。我已经尝试更改页面上几个元素的填充和边距,但我还没有成功。如何消除“主要”div 和导航栏之间的空间? enter image description here

这是我用来生成页面的 html 和 css,底部有一个 JFiddle 链接:

body {
background-color: #090986;
}

#main {
background-color: white;
padding-left: .5em;
}

h1 {
text-align: center;
background-color: white;
}

#menu {
text-align: center;
}

#menu li{
display: inline;
padding:4px 30px 0px 1px;
}

#menu a {
color:#228;
background:#bbb;
padding:.1em .2em .2em .2em;
}

#menu li.current a{
background: white;
}

abbr {
border-bottom: 1px dotted #000;
text-decoration: none;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Sample Menu Page</title>
<link rel="stylesheet" title="Q1" href="style1.css" />
</head>
<body>
<h1>Sample Menu Page</h1>

<ul id="menu">
<li><a href="one.html">Page One</a></li>
<li class="current"><a href="two.html">Page Two</a></li>
<li><a href="three.html">Page Three</a></li>
<li><a href="four.html">Page Four</a></li>
<li><a href="five.html">Page Five</a></li>
</ul>

<div id="main">
<h2 id="first">First Section</h2>
<p>This is the first part of the real content of the page.</p>
<p>This exercise is mostly about:</p>
<ul>
<li><abbr title="Cascading StyleSheets">CSS</abbr></li>
<li>geese</li>
</ul>
<p>Actually, there isn't so much about geese. I just wanted to use a <code>&lt;ul&gt;</code> there.</p>

<h2 id="next">Next Section</h2>
<p>I'm really running out of stuff to say here. Oh well, fall back to old standards, I guess&hellip;</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>

</div>

</body>
</html>

最佳答案

额外填充的主要原因是 #first <h1>顶部有自动填充(h1 的默认样式),还有 <ul>下面有填充。删除这两个作品。

body {
background-color: #090986;
}

#main {
background-color: white;
padding-left: .5em;
}

h1 {
text-align: center;
background-color: white;
}

#main #first {
margin-top:0
}

#menu {
text-align: center;
margin-bottom:0;
}

#menu li{
display: inline;
padding:4px 30px 0px 1px;
}

#menu a {
color:#228;
background:#bbb;
padding:.1em .28em .05em .1em;
}

#menu li.current a{
background: white;
}

abbr {
border-bottom: 1px dotted #000;
text-decoration: none;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Sample Menu Page</title>
<link rel="stylesheet" title="Q1" href="style1.css" />
</head>
<body>
<h1>Sample Menu Page</h1>

<ul id="menu">
<li><a href="one.html">Page One</a></li>
<li class="current"><a href="two.html">Page Two</a></li>
<li><a href="three.html">Page Three</a></li>
<li><a href="four.html">Page Four</a></li>
<li><a href="five.html">Page Five</a></li>
</ul>

<div id="main">
<h2 id="first">First Section</h2>
<p>This is the first part of the real content of the page.</p>
<p>This exercise is mostly about:</p>
<ul>
<li><abbr title="Cascading StyleSheets">CSS</abbr></li>
<li>geese</li>
</ul>
<p>Actually, there isn't so much about geese. I just wanted to use a <code>&lt;ul&gt;</code> there.</p>

<h2 id="next">Next Section</h2>
<p>I'm really running out of stuff to say here. Oh well, fall back to old standards, I guess&hellip;</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>

</div>

</body>
</html>

关于html - 减少填充,初学者 CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34935248/

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