2
有圖像。在這個例子中它有一個width: 320px;
和一個height: 200px;
。該覆蓋做工精細用:使覆蓋容器的大小與內部圖像相同
.overlay-content {
width: 320px;
height: 200px;
...
}
但我不能圖像的一系列的聲明,就像
img {
...
}
有沒有辦法做到這一點不知道寬度和身高.overlay-content
並且沒有對<img>
設置聲明?
這裏是一個JSFiddle,和相應的示例:
img {
/* You can't do anything here */
}
.overlay {
position: relative;
margin: 50px;
}
.overlay-content {
position: absolute;
/* This you don't know */
width: 320px;
/* This you don't know */
height: 200px;
top: 0;
background: grey;
opacity: 0;
transition: opacity .3s ease;
}
.overlay-content div {
position: absolute;
height: 100%;
width: 0%;
overflow: hidden;
right: 0;
background: orange;
transition: width .3s ease-in-out;
}
.overlay-content div ul {
display: block;
width: 100%;
height: 100%;
padding: 0;
margin: 0;
list-style-type: none;
}
.overlay-content div ul li {
position: relative;
height: 33.3333%;
width: 0%;
text-align: center;
overflow: hidden;
transition-property: width;
transition-delay: .2s;
transition-duration: .5s;
transition-timing-function: ease;
}
.overlay-content div ul li span,
.overlay-content div ul li a {
position: absolute;
display: block;
width: 100%;
top: 50%;
margin-top: -25px;
font-size: 22px;
height: 50px;
line-height: 50px;
vertical-align: middle;
color: yellow;
}
.overlay:hover > .overlay-content {
opacity: 1;
}
.overlay:hover > .overlay-content div {
width: 50%;
}
.overlay:hover > .overlay-content div ul li {
width: 100%;
}
<div class="overlay">
<img src="http://placehold.it/320x200" />
<div class="overlay-content">
<div>
<ul>
<li><a href="#">First</a>
</li>
<li><span>Second</span>
</li>
<li><span>Third</span>
</li>
</ul>
</div>
</div>
</div>
<div class="overlay">
<img src="http://placehold.it/320x200" />
<div class="overlay-content">
<div>
<ul>
<li><a href="#">First</a>
</li>
<li><span>Second</span>
</li>
<li><span>Third</span>
</li>
</ul>
</div>
</div>
</div>