2016-12-15 3 views
0

これは私の現在のコードです:2つの画像をhtmlで並べる方法は?

<figure class="half"> 
    <img style="width:400px" src="http://alexmarshall12.github.io/assets/img/colored_1693146.png"> 
    <img style="width:600px" src="http://alexmarshall12.github.io/assets/img/one-piece-1693146_colored2.png"> 
    <figcaption>Caption describing these two images.</figcaption> 
</figure> 

は、残念ながら、おそらく画像が広すぎるので、それはまだ次の行に第2の画像を置きます。私はこれを避けたいです - どんなに広いものがあっても。これどうやってするの?

+0

わずか2つの部門で2枚の画像を入れて置きます1つの主要部門の2つの部門。浮動小数点数を使用する:左に並べて配置する場合 –

+0

可能なすべての画面サイズで画像を並べて表示するには、次のような操作が可能です。https://jsfiddle.net/zvv​​38vup/1/画面の解像度を下げるためにメディアクエリを使用し、別のものの上に配置する(画面のサイズを小さくする) – sinisake

答えて

1

ちょうどあなたの場合の図では、画像の親コンテナにCSS display:flexを追加します。

<figure class="half" style="display:flex"> 
 
    <img style="width:400px" src="http://alexmarshall12.github.io/assets/img/colored_1693146.png"> 
 
    <img style="width:600px" src="http://alexmarshall12.github.io/assets/img/one-piece-1693146_colored2.png"> 
 
    <figcaption>Caption describing these two images.</figcaption> 
 
</figure>

0

ちょうど<span>タグを使用し、それらの間にスペースを入れないことをお勧めします。それらは並べて表示されます。

0

これは多くの方法で実現できます。 あなたは、あなたも、あなたのすべてのCSSを設定することができ、50%

であることを100%にグリッドシステムと設定された画像の幅、それを包むか、テーブルと各TDの設定幅を作成することができますフレキシボックス https://css-tricks.com/snippets/css/a-guide-to-flexbox/

を使用することができます画像はまったく同じサイズになります。

0

画像を表のセルに入れることができます。

<figure class="half"> 
 
    <table> 
 
    <tr> 
 
     <td> 
 
     <img style="width:400px;" src="http://alexmarshall12.github.io/assets/img/colored_1693146.png"> 
 
     </td> 
 
     <td> 
 
     <img style="width:600px;" src="http://alexmarshall12.github.io/assets/img/one-piece-1693146_colored2.png"> 
 
     </td> 
 
    </tr> 
 
    </table> 
 
    <figcaption>Caption describing these two images.</figcaption> 
 
</figure>

0

私はあなたのために少しhttps://jsfiddle.net/7kophdxq/フィドルを作成しました。

フレックスボックスの使用を強く推奨します。フレックスボックスは、これらの種類の作業を行う「新しい方法」です。もちろん、テーブルを使用することもできますが、それは表のデータではありません。一般的な構造について

<div class="columns"> 
    <div class="columns__item"></div> 
    <div class="columns__item"></div> 
</div> 

columns__item、50%の幅を有します。各columns__item内部で私は少しイメージ(と、それはそのコンテナの100%の幅を超えないことを確認しました)入れている:

<figure> 
    <img src="http://lorempixel.com/400/400/" /> 
    <figcaption>Image caption</figcaption> 
</figure> 

を、それが役に立てば幸い!

0
.half img { 
    display:inline-block; 
} 
.half figcaption { 
    display:block 
} 

か、あなたは1行にかかわらず、コンテナのサイズで画像を保存しておきたい場合は:最高のあなたに合ったものは何でも

.half { 
    white-space:nowrap; 
} 
.half img { 
    display:inline; 
} 
.half figcaption { 
    display:block 
} 

ピック;)

関連する問題