【发布时间】:2014-07-24 13:48:12
【问题描述】:
我正在做一场噩梦,试图让一小段文字放在图像上,以我的页面为中心。我管理的最接近的是文本框现在稍微偏右了。
我正在尝试通过使用以图像为背景的 Div 类以及 div 类“TEST”内的段落内的文本来完成此操作。我这样做是因为我稍后想在悬停时对其进行动画处理,但目前我只是想让文本位于图像顶部!
我认为 margin: auto 0;会有所帮助,但它会导致更多问题,所以我将其删除并尝试 display: inline; 代替它让我更接近。现在我完全没有想法了......
这是 p CSS:
p {
background: rgba(0,0,0,1);
background: -webkit-linear-gradient(bottom, rgba(0,0,0,1), rgba(0,0,0,.4));
background: -moz-linear-gradient(bottom, rgba(0,0,0,1), rgba(0,0,0,.4));
background: linear-gradient(bottom, rgba(0,0,0,1), rgba(0,0,0,.4));
padding: 2px;
line-height: 28px;
text-align: center;
position: absolute;
bottom: 0;
margin: 0;
display: inline;
}
这是 Div CSS 及其类:
div {
height: 200px;
margin: 40px 0 0 0;
position: relative;
}
.TESTimage {
background-image: url("https://eccentric.productions/assets/roundlogo");
background-size: 100px;
background-repeat: no-repeat;
background-position: center;
height: 100px;
}
最后是 HTML 的相关部分:
<body>
<div class="TEST">
<p>
Writing
</p>
</div>
</body>
非常感谢任何可以帮助我的人,我已经使用 Stack Overflow 多年,但这是我第一次需要发布问题。你们做的很棒!
【问题讨论】:
-
你会做一个小提琴吗? :)
-
所以这以“写作”为中心:codepen.io/anon/pen/ublzF。你想要背景上方的文字吗?