2016-05-18 6 views
0

私のdivに問題があります。私は右にイメージを浮かべています、そして、私はそれの横にテキストを持っています。 linear-gradient divを作成しようとしていますが、divはページ全体を埋めています。Divコンテンツにフィッティングしない

私はどのようにして自分のコンテンツに合ったdivを作成しますか?

私はinline-block方法を試しました。それは画像の下に自分のテキストをクリアするだけです。

問題:

enter image description here


コード:

.Popcorn { 
 
    float: right; 
 
    position: relative; 
 
    top: -45px; 
 
} 
 
.Software { 
 
    padding: 4px; 
 
    min-width: 100%; 
 
    padding-top: 20px; 
 
    background: rgba(0, 0, 0, 0) linear-gradient(to bottom, #277FD8 0%, #ffffff 30%, #ffffff 100%) repeat scroll 0 0; 
 
}
<img src="/img/popcorn_edited.png" class="Popcorn" /> 
 
<div class="Software"> 
 
    <h3>The Software You Want!</h3> 
 
    <br> 
 
    <p>Android is the World's leading mobile and tablet operating system. This means no learning curves for Android users. The media box is powered by Android which allows you to download applications and share it with all your Android devices or vice versa. 
 
    You can download from millions of apps, games, books, movies and more on the Google Play store.</p> 
 
</div>

+0

からmin-width:100%を削除することができます。 divは実際にあなたが好きなように動作します、それはコンテンツのサイズを持っています。 https://jsfiddle.net/c8k5t4mg/ –

+0

jsfiddleはうまくいきますが、私のコードでは画像に収まるはずがありません。それはそれの周りにラップされていません。 –

+0

さて、わかりました。混乱させて申し訳ありません。 –

答えて

3

ます場合は、calc()機能で勾配であなたのdivに幅を設定することができます知っている

.Software { 
    padding: 4px; 
    width: calc(100% - 350px); 
    padding-top: 20px; 
    background: rgba(0, 0, 0, 0) linear-gradient(to bottom, #277FD8 0%, #ffffff 30%, #ffffff 100%) repeat scroll 0 0; 
} 

Fiddle here

+0

OPがHTML構造を変更できない場合は、良い解決策です。 –

+0

ありがとうございました! :) –

1

1.)にDIV

2)も浮上画像を覆うように容器にoverflow: auto;の割り当てを画像入れ:ポップコーン画像は、固定幅を有しています。

<div class="Software"> 
    <img src="/img/popcorn_edited.png" class="Popcorn"/> 
    <h3>The Software You Want!</h3> 
    <p>Android is the World's leading mobile and tablet operating system. This means no learning curves for Android users. The media box is powered by Android which allows you to download applications and share it with all your Android devices or vice versa. You can download from millions of apps, games, books, movies and more on the Google Play store.</p> 
</div> 

.Popcorn { 
    float: right; 
    position: relative; 
    top: -45px; 
} 
.Software { 
    overflow: auto; 
    padding: 4px; 
    min-width: 100%; 
    padding-top: 20px; 
    background: rgba(0, 0, 0, 0) linear-gradient(to bottom, #277FD8 0%, #ffffff 30%, #ffffff 100%) repeat scroll 0 0; 
} 
+0

あなたの最初のポイントは基本的です!私のupvote。 –

1

あなたは簡単に、私はあなたの質問を理解していないflexboxでこれを解決するため、プラス.Software

body { 
 
    margin: 0 
 
} 
 
.wrap { 
 
    display: flex 
 
} 
 
.Software { 
 
    padding: 4px; 
 
    padding-top: 20px; 
 
    background: rgba(0, 0, 0, 0) linear-gradient(to bottom, #277FD8 0%, #ffffff 30%, #ffffff 100%) repeat scroll 0 0; 
 
} 
 
img { 
 
    width: 100px; 
 
    height: 100px; 
 
}
<div class="wrap"> 
 
    <div class="Software"> 
 
    <h3>The Software You Want!</h3> 
 
    <br> 
 
    <p>Android is the World's leading mobile and tablet operating system. This means no learning curves for Android users. The media box is powered by Android which allows you to download applications and share it with all your Android devices or vice versa. 
 
     You can download from millions of apps, games, books, movies and more on the Google Play store.</p> 
 
    </div> 
 
    <img src="//lorempixel.com/100/100" class="Popcorn" /> 
 
</div>

+0

Mmmm、今、すべてのレイアウトをflexboxに変換するファッションがあります。私はflexboxが大好きですが、これは誇張されているようです。しかし、それは、私のupvote動作します。 –

+0

コードを単純化する方法です(私はできるだけコードを単純化しようと努力しています)。そして、それはフレックスボックスについてもっと勉強し続ける方法です。私の間違いなどを見てください。あなたのアップフォートに感謝しますが、まだ見ませんでした;) – dippas

+1

Ooooh!あなたは正しい、私のせいだ。私はこの回答をアップフォートしていると思っていた。はい、どうぞ :) –

関連する問題