gpt4 book ai didi

html - 这个额外的空间从何而来?

转载 作者:太空宇宙 更新时间:2023-11-04 04:23:58 26 4
gpt4 key购买 nike

正如你在这里看到的http://jsfiddle.net/FqW4R/在下图中,我的菜单项与“ Logo ”和“社交”并不完全一致。菜单类别(菜单 I、菜单 2 等)和子项之间也存在巨大差距。当我查看我的代码时,我没有看到额外的填充或任何可能导致此类问题的类似内容。对此有什么想法吗?非常感谢

enter image description here

Html, body {
margin: 0;
padding: 0;
background: #fff;
font-family: 'Open Sans', sans-serif;
}

#logo {
position: absolute;
top: 35px;
left: 20px;
color: #000;
font-size: 20px;
}

/* mainmenu */

#mainmenu {
float:right;
margin-top: 35px;
padding-bottom: 10px;
overflow: hidden;
}
#mainmenu ul {
float: right;
margin: 0;
color: #000;
list-style: none;
}
#mainmenu ul li {
display: inline-block;
float: left;
width: 140px;
line-height: 20px;
}
#mainmenu>ul>li {
margin-left: 20px;
}
#mainmenu ul li a {
display: block;
text-decoration: none;
font-weight:600;
font-size: 12px;
}
#mainmenu ul li a, #mainmenu ul ul:hover li a {
color: #333;
-webkit-transition-timing-function: ease-out, ease-in, linear, ease-in-out;
-moz-transition-timing-function: ease-out, ease-in, linear, ease-in-out;
-ms-transition-timing-function: ease-out, ease-in, linear, ease-in-out;
-o-transition-timing-function: ease-out, ease-in, linear, ease-in-out;
transition-timing-function: ease-out, ease-in, linear, ease-in-out;
-webkit-transition-duration: .4s, .4s, .4s, .4s;
-moz-transition-duration: .4s, .4s, .4s, .4s;
-ms-transition-duration: .4s, .4s, .4s, .4s;
-o-transition-duration: .4s, .4s, .4s, .4s;
transition-duration: .4s, .4s, .4s, .4s;
-webkit-transition-property: all, -webkit-transform;
-moz-transition-property: all, -moz-transform;
-ms-transition-property: all, -ms-transform;
-o-transition-property: all, -o-transform;
transition-property: all, transform;
}
#mainmenu ul ul li a:hover, #mainmenu ul ul li.current-menu-item a {
color: #005EBC;
-webkit-transition-timing-function: ease-out, ease-in, linear, ease-in-out;
-moz-transition-timing-function: ease-out, ease-in, linear, ease-in-out;
-ms-transition-timing-function: ease-out, ease-in, linear, ease-in-out;
-o-transition-timing-function: ease-out, ease-in, linear, ease-in-out;
transition-timing-function: ease-out, ease-in, linear, ease-in-out;
-webkit-transition-duration: .4s, .4s, .4s, .4s;
-moz-transition-duration: .4s, .4s, .4s, .4s;
-ms-transition-duration: .4s, .4s, .4s, .4s;
-o-transition-duration: .4s, .4s, .4s, .4s;
transition-duration: .4s, .4s, .4s, .4s;
-webkit-transition-property: all, -webkit-transform;
-moz-transition-property: all, -moz-transform;
-ms-transition-property: all, -ms-transform;
-o-transition-property: all, -o-transform;
transition-property: all, transform;
}

#social {
position: absolute;
float:right;
right: 10px;
Color: blue;
margin-top: 35px;
}

HTML

  <div id="logo">Logo</div>  <!-- End DIV Logo -->
<div id="mainmenu">
<ul>
<li>
<h5>Menu I</h5>
<ul>
<li><a title="" href="">Biography</a> </li>
<li><a title="" href="">Publications</a> </li>
</ul>
<li>
<h5>Menu 2</h5>
<ul>
<li><a title="" href="">Demo</a> </li>
<li><a title="" href="">Features</a> </li>
<li><a title="" href="">Comparison</a> </li>
</ul>
</li>
<li>
<h5>Menu 3</h5>
<ul>
<li><a title="" href="">Item 1</a> </li>
<li><a title="" href="">Item 2</a> </li>
<li><a title="" href="">Item 3</a> </li>
</ul>
</li>
<li>
<h5>Menu 4</h5>
<ul>
<li><a title="" href="">ddfd</a> </li>
<li><a title="" href="">dsfd</a> </li>
</ul>
</li>
</ul>
</div> <!-- End DIV Main Menu -->
<div id="social">Social</div><!-- End DIV Social -->

最佳答案

首先,您应该使用 CSS Reset,因为如果您不重置元素,浏览器将对您的元素应用一些默认样式,这是您不想要的,是吗?你可以谷歌出来,那里会得到很多,如果你想保持简单但你想重置,你可以使用下面的代码块并将其粘贴到你的 CSS 中

* {
margin: 0;
padding: 0;
}

Demo (减少间距)

看来你应该学习定位,你正在使用 position: absolute; 元素,没有将元素包装在 position: relative; 容器中,这样,你的 position: absolute; 元素会在野外流出。另外,我认为您不想使用 absolute,在这里使用 float 比较合适。

了解定位的重要性..

What you are doing

What should you do (看到 position: relative; 了吗?)

每个菜单之间的水平间距是因为您使用显式 width

Demo

此外,如果您使用float,则不需要display: inline-block;


我建议你学习CSS PositioningFloats

关于html - 这个额外的空间从何而来?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18640774/

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