Html 用标题定位绝对div

Html 用标题定位绝对div,html,css,position,height,absolute,Html,Css,Position,Height,Absolute,我正在编写一些html代码,但遇到了一个问题。这就是我们正在努力做到的: 我们将在一行(列表)中有多个图像,宽度将为fullwidth,因此它们将根据浏览器宽度更改高度。这工作正常,但我们在设置标题时遇到问题。我们要在这个图像中间设置字幕,以便垂直地在中间和中心。它还需要拍摄完整的图像高度 以下是我们拥有的和我们想要的: 代码: body { background: #fafafa; } .wrapper { position: relative; display:

我正在编写一些html代码,但遇到了一个问题。这就是我们正在努力做到的:

我们将在一行(列表)中有多个图像,宽度将为fullwidth,因此它们将根据浏览器宽度更改高度。这工作正常,但我们在设置标题时遇到问题。我们要在这个图像中间设置字幕,以便垂直地在中间和中心。它还需要拍摄完整的图像高度

以下是我们拥有的和我们想要的:

代码:

body {
    background: #fafafa;
}

.wrapper {
    position: relative;
    display: block;
    float: left;
}

ul {
    list-style: none;
    display: block;
    width: 100%;
    margin: 0;
    padding: 0;
}

ul li {
    width: 20%;
    height: auto;
    float: left;
    position: relative;
}

img {
    max-width: 100%; 
    height: auto;
    float: left;
}

.title-wrapper {
    position: absolute;
    text-align: center;
    width: 100%;
    height: 100%;
    top: 0;
    vertical-align: middle;
    text-align: center;
    background: rgba(0,0,0,0.4);
}
.title-wrapper a {
    color: #000;
    background: #fff;
    padding: 0 30px;
    text-decoration: none;
}

.wanted-result {
    width: 100%; 
    margin-top: 30px; 
    margin-bottom: 30px; 
    float: left;
}

.get-result {
    width: 100%; 
    margin-bottom: 30px; 
    float: left;
}

<div class="get-result">
    This is what get:
</div>
<div class="wrapper">
    <div class="list-wrapper">
        <ul>
            <li><img src="http://s5.favim.com/orig/52/winter-nature-small-canon-eos-7d-Favim.com-474348.jpg" /></li>
            <li><img src="http://s5.favim.com/orig/52/winter-nature-small-canon-eos-7d-Favim.com-474348.jpg" /></li>
            <li><img src="http://s5.favim.com/orig/52/winter-nature-small-canon-eos-7d-Favim.com-474348.jpg" /></li>
            <li><img src="http://s5.favim.com/orig/52/winter-nature-small-canon-eos-7d-Favim.com-474348.jpg" /></li>
            <li><img src="http://s5.favim.com/orig/52/winter-nature-small-canon-eos-7d-Favim.com-474348.jpg" /></li>  

        </ul>
    </div>
    <div class="title-wrapper">
        <a href="#">Title</a>
    </div>
</div>
<div class="wanted-result">
    This is what we want to get:
</div>
<img src="http://s12.postimg.org/ibhy38epp/birds.jpg" />
正文{
背景:#fafafa;
}
.包装纸{
位置:相对位置;
显示:块;
浮动:左;
}
保险商实验室{
列表样式:无;
显示:块;
宽度:100%;
保证金:0;
填充:0;
}
ulli{
宽度:20%;
高度:自动;
浮动:左;
位置:相对位置;
}
img{
最大宽度:100%;
高度:自动;
浮动:左;
}
.标题包装{
位置:绝对位置;
文本对齐:居中;
宽度:100%;
身高:100%;
排名:0;
垂直对齐:中间对齐;
文本对齐:居中;
背景:rgba(0,0,0,0.4);
}
.标题a{
颜色:#000;
背景:#fff;
填充:0 30px;
文字装饰:无;
}
.想要的结果{
宽度:100%;
边缘顶部:30px;
边缘底部:30px;
浮动:左;
}
.得到结果{
宽度:100%;
边缘底部:30px;
浮动:左;
}
这就是我们得到的:
这就是我们想要得到的:

谢谢

您可以将
a
标记放置在
li
中,并将文本包装到
span
中:

        <li><img src="http://s5.favim.com/orig/52/winter-nature-small-canon-eos-7d-Favim.com-474348.jpg" />
            <a href=""><span>Title</span></a>
        </li>

您可以在

中看到实现,这很棘手,因为如果没有某种重叠,几乎不可能覆盖动态大小的图像。使用相对于文本的位置,并根据文本的大小从顶部45-50%进行调整,然后您可以使用vw来尽量掩盖图像

.title-wrapper a {
    position: relative;
    top: 46%;
    color: #000;
    background: #fff;
    padding: 6.8vw 9vw;
    text-decoration: none;
}

试试这个,它会有用的,你会得到你想要的。
如果您想使用高度和宽度,请操纵
高度
宽度
属性。

如果CSS中的
.title wrapper
类具有
宽度:20%,您希望如何操作该属性;左:40%和行高等于图像高度,在本例中为~130px。您可以相应地使其动态化。谢谢您的回答。但我不想替换中间列表项目,例如,我可能有10个,我只想把标题放在上面,这是在列表的中间,它考虑到文本的宽度。例如,它可能会超过1.5个列表项。谢谢您的回答。但我不想替换中间列表项目,例如,我可能有10个,我只想把标题放在上面,这是在列表的中间,它考虑到文本的宽度。例如,它可能超过1.5个列表项。
.title-wrapper a {
    position: relative;
    top: 46%;
    color: #000;
    background: #fff;
    padding: 6.8vw 9vw;
    text-decoration: none;
}