0
我正在嘗試製作一個博客設計,並且我想在verticaly和horizontaly居中的圖像上顯示文本。我的CSS類.featured文章有相對位置。這是HTML和CSS:圖像上的Horizontaly和Verticaly中心文本框
<div class="featured-article">
<img src="images/Image.png" alt="Image"> <!-- This Works Perfect, I don't need to touch it anymore -->
<div class="article">
<img src="uploads/4.png" alt="Image"> <!-- Image where I need to add TextBox -->
<div class="title"> <!-- TextBox that I need to center on image -->
<span><strong>TEXT</strong> TEXT</span>
</div>
.......... Other Eelements
.......... Other Eelements
.......... Other Elements
CSS:
.featured-article { /* Container of Post */
position: relative;
margin-top: 60px;
}
.featured-article > img { /* Background Image, This Works Perfect */
position: absolute;
top: -150px;
left: 20px;
z-index: -1;
}
.featured-article > .article > img { /* Image where I need to add TextBox */
width: 100%;
}
.featured-article > .article > .title > span { /* TextBox that I need to center on image */
background-color: #9ED7D8;
padding: 25px 35px 25px 35px;
text-transform: uppercase;
max-width: 800px;
font-size: 30px;
font-weight: 300;
color: #FFF;
}
這應該是這樣的:Example。
圖像是可變的,必須是鏈接,圖像取決於張貼的圖像。 –
這與您使用時的效果完全相同。你只需要在CSS中設置鏈接。另外,你可以使用內聯'樣式',如:'如果你想在html內部做''div style =「background-image:url(...)」>'。 是你的意思嗎? – GHB