【发布时间】:2018-08-06 08:26:53
【问题描述】:
我一直被这个问题困扰着,我正在制作一个投资组合网站,我想展示我已经完成的项目。我正在搞乱位置和居中,但我似乎无法正确处理。
我想要的是让图像和文本垂直和水平居中,文本与图像重叠。
我在这里做了一个JSFidlle:https://jsfiddle.net/vw7ftzy8/1/
我最终想要的是:https://jsfiddle.net/vw7ftzy8/4/(但反应灵敏)
.projectTest {
color: white;
padding: 10px 40px;
background-color: rgba(0, 0, 0, 0.4);
font-weight: 600;
font-style: italic;
font-size: 56px;
position: absolute;
z-index: 999;
}
.projectsImage1 {
height: 200px;
width: auto;
position: absolute;
}
.projectsImage1Ghost {
visibility: hidden;
position: relative;
}
.text-center {
position: relative;
text-align: center;
background-color:yellow;
}
<div class="text-center">
<span class="projectTest">A test project</span>
<img class="projectsImage1" src="http://www.stickpng.com/assets/images/580b57fcd9996e24bc43c545.png">
<div class="projectsImage1 projectsImage1Ghost"></div>
</div>
【问题讨论】:
标签: html css image alignment center