2016-06-14 3 views
0

私はちょうどこのように私のイメージの内側に私のh2のテキストと小さな段落を追加したい。イメージ内のテキスト

enter image description here

私はH1とテキストを追加すると、画像の下に位置しています。

enter image description here

は、これは悪いCSSのポジショニングのために起こったのですか?

これは、これを行うのが一般的で、CSS position:relative;<div>ですべてをラップして、画像の上にそれらをもたらすために、テキスト要素にCSS position:absolute;を与えることであろう私のコード

<div className="committeeBackground"> 
        <img src="/images/conference.jpg" alt=""/> 
        <h1>Who</h1> 
        <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. 
        Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, 
        </p> 
       </div> 

.committeeBackground{ 
img{ 
    width: 100%; 
} 
} 
+0

を使用して、このようにセンターを実行します。あなたはそれらを上または上にしたいですか? – LGSon

+0

最初の写真と似ています。画像の中央。 –

+1

CSSはそのようにネストできません。また、どの要素の配置に関連するコードにも何もありません。 – Shaggy

答えて

0

それはflexを使用して、トップにposition: absolute

.wrapper { 
 
    position: relative; 
 
    display: inline-block; 
 
} 
 
.ontop { 
 
    position: absolute; 
 
    left: 0; 
 
    top: 0; 
 
    right: 0; 
 
    bottom: 0; 
 
    display: flex; 
 
    flex-direction: column; 
 
    align-items: center; 
 
    justify-content: center; 
 
} 
 
.ontop > div { 
 
    text-align: center; 
 
    color: white; 
 
    font-size: 24px; 
 
}
<div class="wrapper"> 
 
    <img src="http://lorempixel.com/400/300/animals/6" alt=""> 
 
    <div class="ontop"> 
 
    <div> 
 
     <h2>Test Text</h2> 
 
     <p><i>Dummy Text Under H2</i></p> 
 
    </div> 
 
    </div> 
 
</div>

+0

素晴らしい作業!ありがとう –

0

です。次に、top:0;top:30%;などのさまざまな属性を使用してテキストを削除することができます。すべてのテキストをまとめて保存したい場合は、<div>に異なるテキストエレメントをすべてラップして、position:absolute;のスタイルposition:absolute;<div>に付けて、すべてのテキストを一緒に移動できるようにすることもできます。

それは意味がありますか?

私はdiv要素の背景となる画像を設定します。

0

これは、私はあなたが探しているものを行う方法です。そして、私は内部の要素について心配しています。

.backgroundImage { 
 
    background: url('http://placehold.it/300?text=%20'); 
 
    width: 300px; 
 
    height: 300px; 
 
    display: flex; 
 
    align-items: center; 
 
    justify-content: center; 
 
} 
 

 
.block { 
 
    display:block; 
 
    text-align: center; 
 
}
<div class="backgroundImage"> 
 
    <div class="block"> 
 
    <h2>Test Text</h2> 
 
    <p><i>Dummy Text Under H2</i></p> 
 
    </div> 
 
</div>

+0

これは素晴らしいことです!しかし、私は背景イメージを使用することはできません。私は反応を使用しているので、画像を変更する必要があります –

0

あなたは背景画像

<div className="committeeBackground"> 
       <img src="/images/conference.jpg" alt=""/> 
       <h1>Who</h1> 
       <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. 
       Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, 
       </p> 
      </div> 
.committeeBackground{ 
    background-image: url("/images/conference.jpg"); 
} 

やCSS>位置を使用する時に、あなたのイメージを置くことができます:絶対;あなたの子供に、および位置:あなたのコンテナのdivに対する "committeeBackground"

<div className="committeeBackground"> 
       <img src="/images/conference.jpg" alt=""/> 
       <h1>Who</h1> 
       <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. 
       Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, 
       </p> 
      </div> 
.committeeBackground{ 
    position: relative; 
} 
.committeeBackground > * { 
    position: absolute; 
    left: 50%; 
    top: 50% 
} 
関連する問題