応答可能なカレンダー画像では、日付付きのテキストが必要です。画面のサイズを変更して画像のサイズ変更を開始すると、その画像上のテキストも同様にサイズが変更され、画像の幅と高さに合わせて変わらないようにする必要があります。画像上に絶対位置のある応答テキストサイズ
私はJavaScriptを使用して、私は唯一のCSSでそれを行うことができなかったとしてことを達成しています。私の質問は、私はCSSだけでそれをどうやって行うことができるかということです。出来ますか?
https://jsfiddle.net/bej0od7r/
HTML::
<div class="datePictureHolder">
<img class="img-responsive" alt="News Icon" src="http://shrani.si/f/u/13K/4rB6HshN/news-icon.png"/>
<div class="datePictureText">
<div class="year">2017</div>
<div class="day">25. Feb</div>
</div>
</div>
JAVASCRIPT
ResizeDateIcons();
window.onresize = function() {
ResizeDateIcons();
};
function ResizeDateIcons() {
// constants
var imageWidth = 150; // width and height must be the same
var dayTextSize = 36; // text size on maximum image width
var yearTextSize = 23; // text size on maximum image width
var yearLineHeigh = 70;
//
var allImages = document.getElementsByTagName("img");
var allDayTexts = document.getElementsByClassName("day");
var allYearTexts = document.getElementsByClassName("year");
var j = 0;
for (var i = 0; i < allImages.length; i++) {
if (allImages[i].alt === "News Icon") {
allDayTexts[j].style.fontSize = (allImages[i].width/imageWidth) * dayTextSize + "px";
allYearTexts[j].style.fontSize = (allImages[i].width/imageWidth) * yearTextSize + "px";
allYearTexts[j].style.lineHeight = (allImages[i].width/imageWidth) * yearLineHeigh + "px";
j++;
}
}
}
CSS:
.datePictureHolder {
position: relative;
display: inline-block;
}
.datePictureText {
position: absolute;
left: 0;
top: 5%;
width: 100%;
text-align: center;
color: white;
}
.datePictureText .year {
font-size: 23px;
line-height: 70px;
}
.datePictureText .day {
font-size: 36px;
font-weight: bold;
}
.img-responsive {
display: block;
max-width: 100%;
height: auto;
}
をEMを使用して結果を得ることができますCSSだけでこれを実現できると思います。 https://css-tricks.com/viewport-sized-typography/ – Luke
メディアクエリを試してみてください。 – Prabhakaran
@あなたが示唆するものは、表示ポートに基づいてフォントサイズを変更することです。画像はそのようにサイズが変更されません。 – tilenslo