2017-02-06 15 views
1

私は別のdivの中にdivを持っていて、私が達成したいと思っていた効果は、隣にあるクラシックな3つの製品のアイコンです。Div div絶対位置と負のマージンの内容が重複

テキストdivのコンテンツは、次のコンテンツをプッシュダウンして重複することはありません。私は多くの異なるソリューションを試しましたが、私はこの場合に動作するものは見つかりませんでした。

私は内部のdivの絶対的な位置と負のマージンがそれをより困難にするのではないかと恐れています。

私はどんな提案もありがとう。ありがとう!

HTML

<div class="icon-group"> 
     <div class="icon"> 
      <i class="fa fa-book fa-4x" aria-hidden="true"></i> 
      <div class="icon-caption">Astonishment tendrils of gossamer clouds the carbon in our apple pies made in the interiors of collapsing stars.</div> 
     </div> 
     <div class="icon"> 
      <i class="fa fa-plane fa-4x" aria-hidden="true"></i> 
      <div class="icon-caption">Astonishment tendrils of gossamer clouds the carbon in our apple pies made in the interiors of collapsing stars.</div> 
     </div> 
     <div class="icon"> 
      <i class="fa fa-quote-right fa-4x" aria-hidden="true"></i> 
      <div class="icon-caption">Astonishment tendrils of gossamer clouds the carbon in our apple pies made in the interiors of collapsing stars.</div> 
     </div> 
     </div> 
    <div class="clear"></div> 
    <h3 class="after-icons">What people say about me</h3> 

CSS

.icon-group, icon-caption-group { 
    height: 100px; display: table; width:100%; table-layout: fixed} 
.icon, .icon-caption { 
    display: table-cell; 
    text-align: center; 
    vertical-align: middle; 
    position: relative;} 

.icon-caption { 
    border-bottom: 3px solid #E8EAF6; 
    vertical-align: middle; 
    position: absolute; 
    top: 50%; 
    left: 50%; 
    width: 50%; 
    margin: -15% 0 0 -25%; 
    margin-top: 20%; 
} 

.after-icons { 
    margin-top: 30px 
} 

答えて

1

あなたは以下スニペット

.icon-group, icon-caption-group {height: 100px; display: table; width:100%; table-layout: fixed} 
 
.icon, .icon-caption { 
 
display: table-cell; 
 
text-align: center; 
 
vertical-align: middle; 
 
position: relative;} 
 

 
.icon-caption { 
 
border-bottom: 3px solid #E8EAF6; 
 
vertical-align: middle; 
 
display: block; 
 
margin: 0 auto; 
 
width: 50%; 
 
} 
 

 
.after-icons { 
 
margin-top: 30px 
 
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" /> 
 
<div class="icon-group"> 
 
     <div class="icon"> 
 
      <i class="fa fa-book fa-4x" aria-hidden="true"></i> 
 
      <div class="icon-caption">Astonishment tendrils of gossamer clouds the carbon in our apple pies made in the interiors of collapsing stars.</div> 
 
     </div> 
 
     <div class="icon"> 
 
      <i class="fa fa-plane fa-4x" aria-hidden="true"></i> 
 
      <div class="icon-caption">Astonishment tendrils of gossamer clouds the carbon in our apple pies made in the interiors of collapsing stars.</div> 
 
     </div> 
 
     <div class="icon"> 
 
      <i class="fa fa-quote-right fa-4x" aria-hidden="true"></i> 
 
      <div class="icon-caption">Astonishment tendrils of gossamer clouds the carbon in our apple pies made in the interiors of collapsing stars.</div> 
 
     </div> 
 
     </div> 
 
    <div class="clear"></div> 
 
    <h3 class="after-icons">What people say about me</h3>
に確認してください、あなたは、単にこの方法のように行うことができ、コンテンツを配置する必要はありません。

0

アフターアイコンクラスの上余白を大きくするのはどうですか?私は130にそれを増加し、これはdivの下にテキストをプッシュします。

0

あなたのCSSが良く回避される絶対的な位置付け子

Make absolute positioned div expand parent div heightは、あなたが同じとあなたを消去MARKUP HTML保つのサイズに基づいて、親(アイコンクラス)を展開しようとしているのが非常に困難な状況につながります明確なdiv要素や、あなたのCSSは

あなたがする必要があるのは、アイコンスペースにアイコンクラスにパディングやマージンを適用している非常に簡単になる

.icon { 
 
    float: left; 
 
    width: 33%; 
 
} 
 
.clearfix:after { 
 
    content: ""; 
 
    display: table; 
 
    clear: both; 
 
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" /> 
 

 
<div class="icon-group"> 
 
     <div class="icon clearfix"> 
 
      <i class="fa fa-book fa-4x" aria-hidden="true"></i> 
 
      <div class="icon-caption">Astonishment tendrils of gossamer clouds the carbon in our apple pies made in the interiors of collapsing stars.</div> 
 
     </div> 
 
     <div class="icon clearfix"> 
 
      <i class="fa fa-plane fa-4x" aria-hidden="true"></i> 
 
      <div class="icon-caption">Astonishment tendrils of gossamer clouds the carbon in our apple pies made in the interiors of collapsing stars.</div> 
 
     </div> 
 
     <div class="icon clearfix"> 
 
      <i class="fa fa-quote-right fa-4x" aria-hidden="true"></i> 
 
      <div class="icon-caption">Astonishment tendrils of gossamer clouds the carbon in our apple pies made in the interiors of collapsing stars.</div> 
 
     </div> 
 
     </div> 
 
    <h3 class="after-icons">What people say about me</h3>

注:clearfixは通常、古いブラウザのために必要と私はそれの最も単純な実装を選択しましたが、あなたは非常に古いブラウザをサポートしたい場合はここでclearfix

の検索がhttps://jsfiddle.net/GiorgosK/x3evnxpn/

作業jsfiddleあるんさ
関連する問題