私は画面サイズに関係なく、画面上の同じ場所にオブジェクト(テキストと呼ぶ)を保持するために、Position:relativeを使用する方法を理解しようとしています。位置を使用して画像領域内のテキストを含む:相対;
私はPosition:relativeを使用し、 "left"を30%に設定すると...画面の30%です。私は画像の上にテキストを置き、画像内にテキストが30%残るように設定する方法を見つけようとしています。私は画面のサイズに関係なく動作するためにこれが必要です。これまで私はできなかった。
このような状況で、相対的なポジションと絶対的なポジションがどのように機能するのか誰かが私に説明できますか?または、これがどのように処理されるのが最善でしょうか?
ありがとうございます!
はここに私のJsFiddleだし、ここでのスニペットに
.center {
display: table;
margin: 0 auto;
}
body {
background-color: #27ae60;
}
.image {
position: relative;
width: 100%;
/* for IE 6 */
}
.element {
position: absolute;
top: 100px;
left: 30%;
width: 100%;
font-size: 45px;
font-family: 'Just Me Again Down Here', cursive;
}
.input {
/*color: blue;*/
outline: none;
border: none;
background-color: transparent;
position: absolute;
top: 220px;
left: 18%;
width: 480px;
height: 475px;
overflow: hidden;
font-size: 30px;
font-family: 'Just Me Again Down Here', cursive;
}
<img id='image' class='center' src='https://s13.postimg.org/li2l28a0n/White_Board.gif'>
<h1 class='element'>This is a header </h1>
<textarea id='text1' class='input' placeholder="Write your answer here."></textarea>
これは素晴らしいです。なぜこれがうまくいくのか説明するためにあなたの答えを少し編集できますか? – AndrewLeonardi
@AndrewLeonardi私は最高を説明しようとしました、私の編集を参照してください:) –
ファンタスティックな答え。ありがとうございました!! :) – AndrewLeonardi