我有四個圖像並排排列。除第三張圖像低於第二張圖像外。兩者都對齊到第一張圖片的右側。第四個圖像與第二個和第三個圖像(堆疊在彼此的頂部)右側對齊。如何在CSS中實現圖庫
見圖片: http://www.gliffy.com/go/publish/9802269
如何在CSS中實現這一點?
我有以下代碼:
<div class="examples">
<div class="example"><img src="examples/1.jpg" /></div>
<div class="example"><img src="examples/2.jpg" /></div>
<div class="example"><img src="examples/3.jpg" /></div>
<div class="example"><img src="examples/4.jpg" /></div>
</div>
我要自動執行此操作。沒有使用HTML的黑客。
我把它們並排排列,但我不知道如何對齊第二個和第三個圖像,以便第二個圖像位於第三個圖像的頂部。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
.examples {
position: relative;
display: block;
box-sizing: border-box;
height: 100vh;
width: 100%;
margin: 0;
padding: 0;
}
.example {
position: absolute;
background-size: cover;
background-repeat: no-repeat;
width: 33.33%;
cursor: pointer;
margin: 0;
padding: 0;
box-sizing: border-box;
background-position: 50% 50%;
}
.example:nth-child(1) {
top: 0;
left: 0;
height: 100%;
background-image: url(examples/1.jpg);
}
.example:nth-child(2) {
top: 0;
left: 33.33%;
height: 50%;
background-image: url('examples/2.jpg');
}
.example:nth-child(3) {
top: 50%;
left: 33.33%;
height: 50%;
background-image: url('examples/3.jpg');
}
.example:nth-child(4) {
top: 0;
left: 66.66%;
height: 100%;
background-image: url('examples/4.jpg');
}
</style>
</head>
<body>
<div class="examples">
<div class="example"></div>
<div class="example"></div>
<div class="example"></div>
<div class="example"></div>
</div>
</body>
</html>
會不會有永遠是4張圖片? –
是總是會有4張圖片 –