2017-07-01 13 views
0

3列からなる単純な要素を作成しようとしています.3列はicon-imageです。 要素を反応的にしたいが、icon-imageは常に同じサイズ(たとえば40x40ピクセル)にする必要があります。 したがって、1.と2.の列は%値を持ち、3.の列の幅は40pxです。小さな画面でicon-imageのサイズを変更したくないアイコンの幅は常に40ピクセルです。固定サイズの3列目の応答3列レイアウト

.container { 
 
    width: 80%; 
 
} 
 

 
.text1 { 
 
    float: left; 
 
    width: 30%; 
 
} 
 

 
.text2 { 
 
    float: left; 
 
    width: 50%; 
 
} 
 

 
.image { 
 
    float: right; 
 
    width: 120px; 
 
}
<div class="container"> 
 

 
    <p class="text1">Some Titel</p> 
 

 
    <h3 class="text2">Some Text and some more text...</h3> 
 

 
    <img src="image1.jpeg" alt="" class="image" /> 
 

 
</div>

https://jsfiddle.net/mkrizanek/usfmk6r7

敬具、 ミラノ

答えて

1

CSSでちょっと微調整しました。しかし、私はあなたが論理を得ることを願っています。私はのcontainerflexに変更しました。要件に応じて、コンテナ内の要素のwithを変更することができます。

.container { 
 
    background-color: #DDDDDD; 
 
    width: 80%; 
 
    display: flex; 
 
} 
 

 
.text { 
 
    background-color: #BBBBBB; 
 
    width: 50%; 
 
} 
 

 
.heading { 
 
    background-color: #999999; 
 
    width: 50%; 
 
} 
 

 
img { 
 
    max-width: 120px; 
 
    max-height: 120px; 
 
}
<div class="container"> 
 
    <p class="text">Some Text</p> 
 
    <h3 class="heading">Heading</h3> 
 
    <img src="https://www.w3.org/html/logo/downloads/HTML5_Logo_512.png" class="image" /> 
 
</div>

1

あなたの最良のオプションは、フレックス使用することが考えられます。

コンテナdivに「display:flex; justify-content:space-between」と「flex:1;」を設定します。応答可能にする各セクションで

2番目のdivのテキストを画像に押し込む場合は、「text-align:right;」を追加することもできます。それに。ここで

.container { 
 
    display: flex; 
 
    justify-content: space-between; 
 
} 
 

 
.text1 { 
 
    flex: 1; 
 
} 
 

 
.text2 { 
 
    flex: 1; 
 
} 
 

 
.image { 
 
    width: 40px; 
 
    height: 40px; 
 
    background: #088; 
 
}
<div class="container"> 
 

 
    <p class="text1">Some Title</p> 
 

 
    <h3 class="text2">Some Text and some more text...</h3> 
 

 
    <img alt="" class="image" /> 
 

 
</div>

フレキシボックスのための優れたリソースです:https://css-tricks.com/snippets/css/a-guide-to-flexbox/

+0

興味深い、ありがとうございました。 text1とtext2の幅にも%値を使用できますか?私は試して、それは動作していないようです...私はまた、余白/ text2の余白を制御することができる必要があります... – user838531

+0

あなたは、各セクションに割り当てられている割合をflex値で変更することができます:3 "/" flex:1 "の.text1/.text2は75%/ 25%の幅を与えます)。余白とパディングはいつものように動作するはずです。私は良いフレックスボックスガイドへのリンクを追加しました。 – user7363719

関連する問題