【发布时间】:2018-11-05 18:04:12
【问题描述】:
我尝试使用边距/填充(顶部 80% / 底部 20%)将文本放置在 div 底部上方约 20% 的位置。然而,它看起来不像这种方式工作,边距/填充只是开箱即用,而不是根据需要定位文本。
我可以使用 margin: 20% 将它定位在图像的中心,但我想将它定位在底线上方 20% 的位置,否则当我更改分辨率时文本会继续移动,有时它会由于溢出而完全隐藏.
关于如何在 div 底部稍上方对齐的任何建议?最好不使用 position: absolute 因为这个设置对我来说搞砸了其他一切。
.featured_title {
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
margin: auto;
margin-top: 80%; /* this needs to be removed in order for text to become visible as currently it's hidden due to overflow:hidden */
margin-bottom: 20%;
font-size: 4vw;
color: #000;
width: 65%;
text-align: center;
}
.browser {
width: 1366px;
height: 768px;
}
.featured_box {
max-height: 500px;
overflow: hidden;
}
.banner {
max-height: inherit;
}
.banner {
margin:auto;
width: 80%;
display: block;
max-height: 500px;
overflow: hidden;
}
.featured_image {
overflow: hidden;
position: relative;
background-size: cover;
background-repeat: no-repeat;
background-position: center;
height: 500px;
width: 100%
}
<div class=browser>
<div class="featured_box">
<div class="banner" onclick="location.href=">
<div class="featured_image" style="background-image:
url(https://upload.wikimedia.org/wikipedia/commons/thumb/d/d1/Mount_Everest_as_seen_from_Drukair2_PLW_edit.jpg/1024px-Mount_Everest_as_seen_from_Drukair2_PLW_edit.jpg)">
<p class="featured_title">Text goes here</p>
</div>
</div>
</div>
<div class=browser>
【问题讨论】:
-
我想每个人都无法理解你到底想要什么。您说“将文本定位在 div 底部上方约 20%”,现在您总共有 5 个 div。你需要指定哪个div?是“浏览器”、“精选框”吗?比基于此查看“将文本定位在底部上方约 20% 的位置”
-
抱歉,“featured_image”div 底线的 20%。当我说 20% 时,我猜我们说的是图像/div 总高度的 20%。
-
感谢 Ilimkan Omurzakova,问题已得到解决。只是对似乎是问题的快速更新。使用 margin-top: 20% 而不是像素似乎会导致问题和文本根据分辨率上下浮动。