ブラウザウィンドウのサイズを変更するときにこれを取得したい:
そして私はこのHTMLを持っています:
<a class="article-link-block" href="#">
<img src="http://c69282.r82.cf3.rackcdn.com/361.jpg">
<div class="article-info">
Article Info need to be 20% of the height and always at the bottom
</div>
</a>
記事情報の高さの20%ではなく、すべてを取得できます。
たとえば、高さ50ピクセル、次にマージントップ:-50ピクセルしか作成できません。最大幅であれば、問題ありません。しかし、ブラウザの幅を減らし始めると、高さは変更されず、幅だけが変更されます。これは100%です。
高さのサイズを動的に変更し、常に下部にとどまるにはどうすればよいですか?
マージントップを使用する場合:-20%; 高さ:20%; .article-infoの場合
それはそのようなものを作成します:
もちろん、これは間違っています。
ところで。CSSは
.article-link-block {
display: block;
float: left;
width: 100%;
position: relative;
height: auto;
}
.article-link-block img {
margin: 0px;
padding: 0px;
display: block;
float: left;
}
.article-info {
background: black;
width: 100%;
height: auto;
float: left;
position: relative;
display: block;
margin-top: -20%;
height: 20%;
}
編集 編集 編集
<body>
<div id="header">
<!-- header is 100% width of body width-->
</div>
<div id="content">
<!-- container is 100% of body width -->
<div id="articles">
<!-- articles are 70% of container width-->
<a class="article-link-block article-1" href="#">
<img src="http://c69282.r82.cf3.rackcdn.com/361.jpg">
<div class="article-info">
Article Info need to be 20% of the height and always at the bottom
</div>
</a>
<a class="article-link-block article-2" href="#">
<img src="http://c69282.r82.cf3.rackcdn.com/361.jpg">
<div class="article-info">
Article Info need to be 20% of the height and always at the bottom
</div>
</a>
<a class="article-link-block article-3" href="#">
<img src="http://c69282.r82.cf3.rackcdn.com/361.jpg">
<div class="article-info">
Article Info need to be 20% of the height and always at the bottom
</div>
</a>
<a class="article-link-block article-4" href="#">
<img src="http://c69282.r82.cf3.rackcdn.com/361.jpg">
<div class="article-info">
Article Info need to be 20% of the height and always at the bottom
</div>
</a>
</div>
<div id="sidebar">
<!-- sidebar is 30% of container width -->
</div>
</div>
<div id="footer">
<!-- footer is 100% of body width -->
</div>
</body>