我不知道這是否可行,但可變文字長度的<span>
是否可以在圖像上水平對齊?有一個與此相關的是,我希望<span>
具有背景色,背景顏色塊應與圖像重疊。CSS在圖像上水平排列文字
我試過將<span>
設置爲display:inline-block
,但它似乎並沒有水平對齊。這裏是如果你不想在小提琴看(這裏的HTML應該是一樣的,如果不惜一切-可能)
守則(https://jsfiddle.net/6c9gmvom/1/)代碼:
#wrapper {
width:100%;
}
.txt {
text-align:center;
margin:0 auto;
width:40px; /* ideally I would not want to use a fixed width here */
background-color:#ffffff;
}
img {
height:30px;
width:100%;
}
<div id="wrapper">
<img src="http://seedmagazine.com/slideshow/the_long_shot/img/8_the_long_shot_ss.jpg">
<div id="modulewrapper">
<span class="txt">hey</span>
<div id="module"></div>
</div>
</div>
謝謝你,但我試圖讓「哎」重疊的圖像,如「嘿」將坐在在圖像 – Zac
@Zac答案更新......除非有某種原因背景圖像是不可接受的。 – Scott
非常感謝,這是@ xxxmatko的答案,我正在尋找的影響。我實際上一直在複製你的snippit顯示的內容(我不希望背景橫跨整個圖像) – Zac