浮动元素下的额外余量

时间:2016-07-01 13:31:32

标签: html css css3 css-float margin

我的容器构造方式存在问题。我有两行,每行有两列。想想4个象限(见下图)。左下象限向上进入右上象限。

我正在使用浮点数来切换不同视口的位置,因此浮点数是必须的。我一直坚持这个问题一段时间,似乎无法弄明白。

我收录了一下它正在做什么的快照。除了进入右上角的左下象限外,行之间还有间隙。

我也包括一个小提琴。有谁看到发生了什么?

enter image description here

enter image description here

.section-blocks {
	width: 50%;
	height: auto;
	display: inline-block;
	vertical-align: top;
}
.section-block-img {
	height: 100%;
	width: 100%;
}
.left {
	float: left;
}
.right {
	float: right;
}

#company-information {
	width: 100%;
	height: auto;
}
.company-information-block-title, .company-information-block-title2, .company-information-block-general-title, .company-information-block-description {
	color: #313743;
	line-height: 1.4em;
}
.company-information-block-title {
	font-size: 1.6em;
	margin-bottom: 20px;
}
.company-information-block-title2 {
	font-size: 3.2em;
	margin-bottom: 40px;
	font-weight: bold;
	color: #0085A1;
}
.company-information-block-general-title {
	font-size: 2.2em;
	margin-bottom: 40px;
	font-weight: bold;
}
.company-information-block-description {
	font-size: 1.2em;
	margin-bottom: 40px;
}


#company-information-block2 {
	height: auto;
}

#company-slider-section {
  width: 100%;
  height: auto;
  position: relative;
}

div#slider {
  width: 100%;
  overflow: hidden;
  position: relative;
}

#responsive-section {
	width: 100%;
	height: auto;
}
#responsive-block1 {
	float: left;
	height: 100%;
	width: 40%;
	position: relative;
}
#responsive-block2 {
	float: right;
	height: auto;
	width: 60%;
	overflow: hidden;
}
#responsive-block2 img {
	width: 100%;
	height: auto;
}
<div class="section-blocks right">
			<div class="company-container">
				<div class="company-information-block-general-title">COMPANY STORY</div>
				<div class="company-information-block-description">
					<p>fdhsia  fid afdan fndsanfdn   fnfd fksanfanfd nfdanfan nfanafn dfnejwaoN F[gnf nr rnreogn aonrkngrnrnasng r narnrnoangrfkdkgraarmng aa arngrnga;aggkrioa   anrnr argnkrg gagnrgng g grkrn g g rgn e gan ggn as</p><br><br>
					<p>Ohtgfd htgdh thtrh trh rt sdfhh htsh shfh tsh sshh hs thhth shgsndfsank kfdnsak fndnkfdsa nkf f ndaiof nfasoanovn ndan fna gn an gnalnasgng agngna na nngfen grana akn gngaananogn</p>
					
				</div>
			</div>
		</div><div id="company-slider-section">
			<div class="section-blocks left">
			<div id="slider" class="slider">
			  <figure class="figure figure2">
				<div class="slide-wrapper">
				  <div class="slide"><img src="http://optimumwebdesigns.com/images/work/projects/eslich/es-test1.jpg" alt class="slide-image"></div>
				</div>
			  </figure>
			</div>
		</div>
	</div>
	<div id="responsive-section">
		<div id="responsive-block1">
			<div class="company-container">
				<div class="company-information-block-general-title">INDUSTRY SPECIFIC</div>
				<div class="company-information-block-description"></div>
			</div>
		</div>
		<div id="responsive-block2">
			<img src="http://optimumwebdesigns.com/images/work/projects/eslich/es-test3.jpg" alt>
		</div>
	</div>

2 个答案:

答案 0 :(得分:1)

我能看到的最简单的解决方案是使用.clearfix解决方案将各自的象限包装成行:

.clearfix:after {
    content: "";
    display: table;
    clear: both;
}

答案 1 :(得分:0)

您不需要同时使用float: left;float: right,只需向左浮动即可。这将使代码更容易阅读。 您可以将“块”放入“行”以确保它们不会相互干扰。通过设置块overflow,您可以确保它与子项一起“增长”。

.row {
  position: relative;
  overflow: hidden;
}
.section-blocks {
	float: left;
	width: 50%;
	height: auto;
	display: inline-block;
	vertical-align: top;
}
.section-block-img {
	height: 100%;
	width: 100%;
}
.left {
	float: left;
}
.right {
	float: right;
}

#company-information {
	width: 100%;
	height: auto;
}
.company-information-block-title, .company-information-block-title2, .company-information-block-general-title, .company-information-block-description {
	color: #313743;
	line-height: 1.4em;
}
.company-information-block-title {
	font-size: 1.6em;
	margin-bottom: 20px;
}
.company-information-block-title2 {
	font-size: 3.2em;
	margin-bottom: 40px;
	font-weight: bold;
	color: #0085A1;
}
.company-information-block-general-title {
	font-size: 2.2em;
	margin-bottom: 40px;
	font-weight: bold;
}
.company-information-block-description {
	font-size: 1.2em;
	margin-bottom: 40px;
}


#company-information-block2 {
	height: auto;
}

#company-slider-section {
  width: 100%;
  height: auto;
  position: relative;
}

div#slider {
  width: 100%;
  overflow: hidden;
  position: relative;
}

#responsive-section {
	width: 100%;
	height: auto;
}
#responsive-block1 {
	float: left;
	height: 100%;
	width: 40%;
	position: relative;
}
#responsive-block2 {
	float: right;
	height: auto;
	width: 60%;
	overflow: hidden;
}
#responsive-block2 img {
	width: 100%;
	height: auto;
}
<div class="row">
  <div class="section-blocks">
    <div id="slider" class="slider">
      <figure class="figure figure2">
        <div class="slide-wrapper">
          <div class="slide"><img src="http://optimumwebdesigns.com/images/work/projects/eslich/es-test1.jpg" alt class="slide-image"></div>
        </div>
      </figure>
    </div>
  </div>

<div class="section-blocks">
  <div class="company-container">
    <div class="company-information-block-general-title">COMPANY STORY</div>
    <div class="company-information-block-description">
      <p>fdhsia  fid afdan fndsanfdn   fnfd fksanfanfd nfdanfan nfanafn dfnejwaoN F[gnf nr rnreogn aonrkngrnrnasng r narnrnoangrfkdkgraarmng aa arngrnga;aggkrioa   anrnr argnkrg gagnrgng g grkrn g g rgn e gan ggn as</p><br><br>
      <p>Ohtgfd htgdh thtrh trh rt sdfhh htsh shfh tsh sshh hs thhth shgsndfsank kfdnsak fndnkfdsa nkf f ndaiof nfasoanovn ndan fna gn an gnalnasgng agngna na nngfen grana akn gngaananogn</p>			
    </div>
  </div>
</div>
</div>
<div class="row">
<div id="responsive-section">
  <div id="responsive-block1">
    <div class="company-container">
      <div class="company-information-block-general-title">INDUSTRY SPECIFIC</div>
      <div class="company-information-block-description"></div>
    </div>
  </div>
  <div id="responsive-block2">
    <img src="http://optimumwebdesigns.com/images/work/projects/eslich/es-test3.jpg" alt>
  </div>
</div>
  </div>