在多个包装中一致地删除填充/边距

时间:2017-01-04 22:32:53

标签: html css

我正试图让浅绿色消失(没有消失但是在深绿色之下)。

这与我之前的帖子(Remove padding/margin between elements in shrink-to-fit container)完全相同,但唯一不同的是换行是在另一个换行中,没有零边距/填充,显示内联块或溢出都有效。

#footer-left{
	float:left;
	width:700px;
	height:200px;
	background:#CC3;
}
#footer-services-contents-wrap{
	background:#030;
	width:auto;
	height:auto;
	display:inline-block;
}
#footer-services-title-wrap{
	background:#0F0;
	width:auto;
	height:auto;
	display:inline-block;
}
.footer-wrap-left{
	width:auto;
	height:auto;
	display: inline-block;
	border-left:1px solid #ccc;
	padding-left:50px;
	padding:0;
	border:none;
	float:left;
}
ul.footer {
    list-style-type:none;
    padding: 0px;
	color:#666;
	font-weight:100;
	font-family:verdana,arial,"Times New Roman", Times, serif,georgia,serif,helvetica;
	font-size:20px;
	margin: 10px 0 0 0;
}

.footer-wrap-right{
	width:auto;
	height:auto;
	display: inline-block;
	border-left:1px solid #ccc;
	padding-left:50px;
	padding:0 0 0 50px;
	border:none;
	float:left;
}
<div id="footer-left">

<div id="footer-services-title-wrap">
<div id="footer-services-contents-wrap">

<div class="footer-wrap-left">
<f1>text goes here</f1>
<ul class="footer">
  <li>text text</li>
  <li>text text</li>
  <li>text text</li>
</ul>
</div>

<div class="footer-wrap-right">
<f1>more text goes here</f1>
<ul class="footer">
  <li>text text</li>
  <li>text text</li>
  <li>text text</li>
</ul>
</div>

</div>
</div>

</div>

2 个答案:

答案 0 :(得分:1)

float:left添加到#footer-services-contents-wrap

可以解决您的问题

发生这种情况的原因:

  

块格式化上下文对于定位非常重要(请参阅   漂浮物)和清除浮体(见清楚)。定位规则   并且清除浮动仅适用于同一块内的事物   格式化上下文浮点数不会影响其他事物的布局   阻止格式化上下文,并清除只清除过去的浮动   相同的块格式化上下文。

https://www.w3.org/TR/CSS2/visuren.html#block-formatting

&#13;
&#13;
#footer-left{
	float:left;
	width:700px;
	height:200px;
	background:#CC3;
}
#footer-services-contents-wrap{
	background:#030;
	width:auto;
	height:auto;
	display:inline-block;
        float: left;
}
#footer-services-title-wrap{
	background:#0F0;
	width:auto;
	height:auto;
	display:inline-block;
}
.footer-wrap-left{
	width:auto;
	height:auto;
	display: inline-block;
	border-left:1px solid #ccc;
	padding-left:50px;
	padding:0;
	border:none;
	float:left;
}
ul.footer {
    list-style-type:none;
    padding: 0px;
	color:#666;
	font-weight:100;
	font-family:verdana,arial,"Times New Roman", Times, serif,georgia,serif,helvetica;
	font-size:20px;
	margin: 10px 0 0 0;
}

.footer-wrap-right{
	width:auto;
	height:auto;
	display: inline-block;
	border-left:1px solid #ccc;
	padding-left:50px;
	padding:0 0 0 50px;
	border:none;
	float:left;
}
&#13;
<div id="footer-left">

<div id="footer-services-title-wrap">
<div id="footer-services-contents-wrap">

<div class="footer-wrap-left">
<f1>text goes here</f1>
<ul class="footer">
  <li>text text</li>
  <li>text text</li>
  <li>text text</li>
</ul>
</div>

<div class="footer-wrap-right">
<f1>more text goes here</f1>
<ul class="footer">
  <li>text text</li>
  <li>text text</li>
  <li>text text</li>
</ul>
</div>

</div>
</div>

</div>
&#13;
&#13;
&#13;

答案 1 :(得分:1)

float:leftinline-block课程中使用footer-wrap-right时,您不需要footer-wrap-left

#footer-left{
	float:left;
	width:700px;
	height:200px;
	background:#CC3;
}
#footer-services-contents-wrap{
	background:#030;
	width:auto;
	height:auto;
	display:inline-block;
}
#footer-services-title-wrap{
	background:#0F0;
	width:auto;
	height:auto;
	display:inline-block;
}
.footer-wrap-left{
	width:auto;
	height:auto;
	display: inline-block;
	border-left:1px solid #ccc;
	padding-left:50px;
	padding:0;
	border:none;
}
ul.footer {
    list-style-type:none;
    padding: 0px;
	color:#666;
	font-weight:100;
	font-family:verdana,arial,"Times New Roman", Times, serif,georgia,serif,helvetica;
	font-size:20px;
	margin: 10px 0 0 0;
}

.footer-wrap-right{
	width:auto;
	height:auto;
	display: inline-block;
	border-left:1px solid #ccc;
	padding-left:50px;
	padding:0 0 0 50px;
	border:none;
}
<div id="footer-left">

<div id="footer-services-title-wrap">
<div id="footer-services-contents-wrap">

<div class="footer-wrap-left">
<f1>text goes here</f1>
<ul class="footer">
  <li>text text</li>
  <li>text text</li>
  <li>text text</li>
</ul>
</div>

<div class="footer-wrap-right">
<f1>more text goes here</f1>
<ul class="footer">
  <li>text text</li>
  <li>text text</li>
  <li>text text</li>
</ul>
</div>

</div>
</div>

</div>