2016-11-06 7 views
0

中小両方のディスプレイにdiv要素を揃えますか?内側のdivが同じ行にあることを望みます。私の現在のコードはそうしています。だから私は、div内のすべてのページを一列に整列させたい。センターは、私は、次の内容を持っている

+0

の可能性の重複を役に立てば幸いhttp://stackoverflow.com/questions/40443049/show-div-in - 現在のビューポイント中心のモバイルデバイス) – Mukund

答えて

0

含まれているラッパーにtext-align:centerルールを置きます。 は次のようになります。

<div style="text-align:center"> 
    <div style="display:inline-block;vertical-align:top;"> 
     <a href="http://sunlightfoundation.com/" target="_blank"><img src="images/logo.png" style="display: inline"></a> 
    </div> 
    <div style="display:inline-block;"> 
     <h4><b>Congress API</b></h4> 
    </div> 
</div> 
1

あなたはtext-align: centerを使用して中央にメインの親のdiv(すなわち、.holder)を揃えることによってそれを行うことができます。 vertical-align: middleを使用して中央に

および垂直整列子供<div>の両方(すなわち、.content-holder.title-holder)。

/* Parent Element */ 
 
.holder { 
 
    text-align: center; 
 
} 
 

 
/* Child Elements */ 
 
.content-holder, 
 
.title-holder { 
 
    display: inline-block; 
 
    vertical-align: middle; 
 
}
<div class="holder"> 
 
    <div class="content-holder"> 
 
    <a href="http://sunlightfoundation.com/" target="_blank"> 
 
     <img src="http://placehold.it/50x50" style="display: inline"> 
 
    </a> 
 
    </div> 
 
    <div class="title-holder"> 
 
    <h4><b>Congress API</b></h4> 
 
    </div> 
 
</div>

・ホープ、このことができます:

は、以下のコードを見てください!

0

div { 
 
    text-align:center; 
 
} 
 
a img { 
 
    height:50px; 
 
}
<div> 
 
    <div style="display:inline-block;vertical-align:top;"> 
 
     <a href="http://sunlightfoundation.com/" target="_blank"><img src="http://www.freeiconspng.com/uploads/camera-icon--long-shadow-ios7-iconset--pelfusion-30.png" style="display: inline"></a> 
 
    </div> 
 
    <div style="display:inline-block;"> 
 
     <h4><b>Congress API</b></h4> 
 
    </div> 
 
</div>

Live view

あなたはこのCSSスタイルを使用する必要があります。

div { 
    text-align:center; 
} 
0

あなたは、ディスプレイを使用して検討するかもしれない:

チェックにこのスニペットを曲げる

.container{ 
 
    display:flex; 
 
    justify-content:center; 
 
} 
 
.imageClass{ 
 
    display:flex; 
 
    align-items:center; 
 
}
<div class="container"> 
 
    <div class="imageClass"> 
 
    <a href="http://sunlightfoundation.com/" target="_blank"> 
 
     <img src="http://www.freedigitalphotos.net/images/img/homepage/87357.jpg" class="image" height="26px" width=26px> 
 
    </a> 
 
    </div> 
 
    <div> 
 
    <h4><b>Congress API</b></h4> 
 
    </div> 
 
</div>
が(それは[モバイルデバイス上の現在のビューポートの中心でshow DIV]

関連する問題