繁体   English   中英

图片未占用父div上设置的全宽

[英]Image not taking up full width set on parent div

看到这个小提琴

正如您在小提琴中看到的那样,图像左侧有一些空白区域。 我已将图像设置为100%宽度,但未占用所有空间。 您可以将鼠标悬停在它上面进行检查。

在此处输入图片说明

的HTML

<ul class="ulteamlist">
    <li class="teamlist">
        <img src="http://s21.postimg.org/jpw2o7ofr/image.png">
            <div class="overlay"></div>
        <p>Vikas Ghodke</p>
        <p class="tposition">Lead Developer</p>
    </li>
</ul>

的CSS

ul.ulteamlist {
    margin: 0;
    list-style: none;
}
li.teamlist {
    background: #fff;
    box-shadow: 0px 1px 1px -1px #ccc;
    float: left;
    padding:0;
    display: block;
    width:40%;
    margin-bottom: 3%;
    margin-right: 3%;
    transition: all 0.5s;
    position: relative;
}
li.teamlist:hover {
    background:#0dbca1;
}
li.teamlist:hover p {
    color:#fff;
}
.overlay {
    width: 100%;
    height: 210px;
    background: #fff;
    position: absolute;
    top: 0;
    opacity: 0;
    transition: all 0.5s;
}
li.teamlist:hover .overlay {
    opacity: 0.3;
}
li.teamlist:nth-child(4n+4) {
    margin-right: 0;
}
.no-js li.teamlist {
    display: block;
}
li.teamlist img {
    width: 100%;
    height: 210px;
    margin:0;
}
.teamlist p {
    padding: 10px;
    color: #5b5b5b;
    font-weight: 400;
    font-size: 14px;
    padding-left: 15px;
}
p.tposition {
    font-weight: 300;
    margin-top: -27px;
    font-size: 11px;
    margin-bottom: 0;
    color: #9d9c9c;
    text-transform: uppercase;
}

从评论扩展(包括我的和OP的):

可以说,这不是一个“差距”。 它是原始图像左侧的一个透明像素:

间隙

您可以在这个小提琴中清楚地看到它:

<img src="http://s21.postimg.org/jpw2o7ofr/image.png" />
body {
    background-color:yellow;
}
img {
    outline:1px solid black;
}

使用占位符图片,您的设置似乎不错:

占位符

http://jsfiddle.net/kDdUC/7/

只需将其添加到您的CSS中即可。

这就是你想要的仪式。

.ulteamlist
{padding:0px;}

在此处输入图片说明

通过更改图像来签出,因为图像本身的LHS有一定空间。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM