gpt4 book ai didi

html - CSS float 属性创建幻像边距

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

you can view the problem here

所以我亲切地建立了我不起眼的小网站,我有一个包含内容的 div,紧贴在我的内容 div 中的是两个段落和一个标题。我决定在我的内容 div 中向右浮动一个图像,希望段落环绕它,它按预期发生但它在我的标题横幅和我的内容 div 之间创建了一个幻影边距,我搜索并搜索并搜索并搜索违规代码,直到我无法忍受为止!并决定将我的 SOS 放入瓶子中并将其发送到 stackoverflow,请帮助我,否则我可能会在 24-48 小时内结束自杀监视。

这是html和代码,请不要笑我是菜鸟,才学了大约三个星期的css和html:

<!DOCTYPE HTML>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<link href="style.css" rel="stylesheet" type="text/css" media="only screen and (min-width: 769px)"/>
<link href="style.css" rel="stylesheet" type="text/css" media="only screen and (min-width: 480px) and (max-width: 768px)"/>
<link href="media.css" rel="stylesheet" type="text/css" media="only screen and (min-width: 200px) and (max-width: 479px)"/>
<title>MSK Chess</title>
</head>

<body>
<div id="banner">
<h1>MSK Chess</h1>
</div>
<div id="container">
<div id="container2">
<div id="navigation">
<ul>
<li><a href="#">Nav item 1</a></li>
<li><a href="#">Nav item 2</a></li>
<li><a href="#">Nav item 3</a></li>
</ul>
</div>
<div id="more"> <!--right column-->
<h3>Chess goodies</h3>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet. </p>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet. </p>
<a href="#"><img src="chessjam.jpg"></a>
</div>
<div id="content"><!--left column-->
<div class="right"><img src="image.gif" alt="" width="100" height="100"><br>Chess blah</div><p>
<h2>Chess is Awesome</h2>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. </p>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. </p>

</div>
<div id="cleardiv"></div>
</div>
</div>
<div id="footer">
<ul>
<li><a href="#">Footer item 1</a></li>
<li><a href="#">Footer item 2</a></li>
<li><a href="#">Footer item 3</a></li>
<li><a href="#">Copyright &copy; mirsultankhan.com</a></li>
<li><a href="#"><img src="vcss.gif"></a></li>
</ul>
</div>

</body>

body
{
margin: 0;
padding: 0;
font-size: 95%;
font-family: georgia, times, "times new roman", serif;
color: #000;
background-color: #fff;
}

div#banner
{
color: #fff;
background-color: #333;
border-bottom: 1px solid #000;
}

div.right{
float:right;
margin: 0 0 5px 5px;
border: 1px solid #666;
padding: 10px;
width:102px;
background-color: #ddd;
border-top: 1px solid #999;
border-right: 2px solid #555;
border-bottom: 2px solid #555;
border-left: 1px solid #999;
}

div.right img{
border-top: 2px solid #555;
border-right: 1px solid #999;
border-bottom: 1px solid #999;
border-left: 2px solid #555;
}



div#banner h1
{
margin: 0;
padding: .3em 0 .3em .5em;
font-size: 2.2em;
font-weight: normal;
}



div#container
{margin:0;
background-image: url(nav_col_base.jpg);
background-repeat: repeat-y;
}

div#container2
{margin:0;
background-image: url(more_col_base.jpg);
background-repeat: repeat-y;
background-position: right;
}

div#navigation
{
float: left;
width: 150px;
padding-top: 2em;
}

div#navigation ul
{
list-style-type: none;
padding: 0;
margin: 0;
}

div#navigation ul li { margin-top: 4px; }

#navigation ul li a
{
display: block;
width: 135px;
padding: 3px 5px 3px 10px;
text-decoration: none;
color: #000;
background-image: url(nav_base.jpg);
background-repeat: repeat-y;
}

#navigation ul li a:hover
{
color: #fff;
background-color: #ccc;
background-image: url(nav_base2.jpg);
background-repeat: repeat-y;
}

div#more
{
float: right;
width: 160px;
margin: 0;
padding: 2em 10px 0 0;
color: #fff;
}

div#more h3
{
margin-top: 0;
color: #fff;
padding: .2em;
background-image: url(more_base.jpg);
background-position: right;
background-repeat: repeat-y;
}

div#content
{
margin-left: 190px;
margin-right: 200px;
}

div#content h2
{
font-size: 2em;
color: #036;
margin: 0;
font-weight: normal;
}

div#content { line-height: 150%; }

#cleardiv
{
clear: both;
height: 1em;
}

div#footer
{
clear: both;
padding: .5em 1em;
border-top: 1px solid #999;
text-align: center;
background-color:#E0E0E0;
height: 80px;
}

div#footer ul
{
padding: 0;
margin-top: 10px;
list-style-type: none;
}

div#footer li
{
display: inline;
margin-right: 1em;
background-size: cover;
padding:3px 5px 3px 5px;
}

div#footer a{
padding: 3px;
text-decoration: none;
color: #036;
}

div#footer ul li a:hover
{
color: #000;
background-color: #ccc;
}

非常感谢您花时间 - 亲切的问候罗比

最佳答案

你有一个空的 <p>在您的 <h2>Chess is Awesome</h2> 之前标记标签。该段落有一个默认的上边距,它折叠到其父级的零边距中,<div id="content">元素,有效地将边距应用于 <div id="content">本身,将其从横幅上移开。

我假设空段落是为了抵消 <h2>从顶部 <div id="content"> .您可以用 <br> 替换空段落出于相同目的的标记,或者您可以提供 <div id="content">一个padding: 1px样式以便将其边距与 <p> 分开 margin ,避免它们崩溃。

关于html - CSS float 属性创建幻像边距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23041654/

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