【发布时间】:2017-01-06 15:51:43
【问题描述】:
我有以下 HTML 和 CSS:
#page {
background-color: #000;
color: #fff;
height: 360px;
width: 360px;
min-height: 100%;
}
#viewport {
font-size: 20pt;
text-align: center;
}
.taskTitle {
height: 13%;
font-weight: bold;
font-size: 30pt;
white-space: nowrap;
display: inline-block;
}
.taskNote {
color: gray;
white-space: nowrap;
}
<div id="page">
<div id="viewport">
<div id="task-view">
<div style="width: 100%; background-color: aqua; position: relative;">
<img style="background-color: blue; position: absolute; left :0%; top: 50%; transform: translate(-0%, -50%);" src="./image/tw_btn_radio_holo_dark.png"></img>
<div style="width: 100%; background-color: red;">
<div class="taskTitle" id="taskTitle1" style="background-color: green; width: 100%">Long text overlays picture :(</div>
<div class="taskNote" id="taskNote1">My Note 1</div>
</div>
</div>
<div style="width: 100%; background-color: orange; position: relative;">
<img style="background-color: blue; position: absolute; left :0%; top: 50%; transform: translate(-0%, -50%);" src="./image/tw_btn_radio_holo_dark.png"></img>
<div style="width: 100%; background-color: red;">
<div style="background-color: green;" class="taskTitle" id="taskTitle2">Short</div>
<div class="taskNote" id="taskNote2">Short text should always centerd in page!</div>
</div>
</div>
</div>
</div>
</div>
我会得到以下内容:
- 始终在屏幕左侧显示图片
- 始终在父 div 的垂直中心显示图片
- 居中文本(标题和注释)始终位于屏幕的中心
- 文字不应覆盖图片
我该怎么做?
【问题讨论】: