css 纯CSS砌体布局 - https://medium.com/@_jh3y/how-to-pure-css-masonry-layouts-a8ede07ba31a#.fomk5pu69
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了css 纯CSS砌体布局 - https://medium.com/@_jh3y/how-to-pure-css-masonry-layouts-a8ede07ba31a#.fomk5pu69相关的知识,希望对你有一定的参考价值。
<html lang="en-us"></html>
<body>
<div class="masonry-layout">
<div class="masonry-layout__panel masonry-layout__panel--flipper-container masonry-layout__panel--medium">
<div class="masonry-layout__panel-content--flipper"><img src="img/photo-1.jpg" class="masonry-layout__panel-content--img masonry-layout__panel-content--front"/>
<div class="masonry-layout__panel-content--back bg--green">
<p>Here is a flipped image...</p>
</div>
</div>
</div>
<div class="masonry-layout__panel">
<div class="masonry-layout__panel-content tx--white bg--green">
<h1>Here is a masonry layout.</h1>
</div>
</div>
<div class="masonry-layout__panel masonry-layout__panel--cluster masonry-layout__panel--horizontal masonry-layout__panel--medium">
<div class="masonry-layout__panel masonry-layout__panel--segment masonry-layout__panel--full-size"><img src="img/photo-2.jpg" class="masonry-layout__panel-content masonry-layout__panel-content--img"/></div>
<div class="masonry-layout__panel masonry-layout__panel--segment masonry-layout__panel--quarter-size"><img src="img/photo-1.jpg" class="masonry-layout__panel-content masonry-layout__panel-content--img"/></div>
<div class="masonry-layout__panel masonry-layout__panel--segment">
<div class="masonry-layout__panel-content bg--red tx--white">
<p>Some cool pics.</p>
</div>
</div>
</div>
<div class="masonry-layout__panel">
<div class="masonry-layout__panel-content tx--white bg--purple">
<h3>That's pretty cool, thanks for showing me.</h3>
</div>
</div>
<div class="masonry-layout__panel masonry-layout__panel--cluster masonry-layout__panel--vertical masonry-layout__panel--large">
<div class="masonry-layout__panel masonry-layout__panel--segment masonry-layout__panel--full-size"><img src="img/photo-2.jpg" class="masonry-layout__panel-content masonry-layout__panel-content--img"/></div>
<div class="masonry-layout__panel masonry-layout__panel--segment masonry-layout__panel--quarter-size">
<div class="masonry-layout__panel-content bg--blue tx--white">
<p>This is an image, it's quite nice.</p>
</div>
</div>
<div class="masonry-layout__panel masonry-layout__panel--segment">
<div class="masonry-layout__panel-content bg--blue tx--white"><a>Click here to find out more.</a></div>
</div>
</div>
<div class="masonry-layout__panel">
<div class="masonry-layout__panel-content tx--white bg--red">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis eu justo ex. Praesent mollis augue sagittis eros pharetra feugiat. Phasellus dignissim est lacus. Sed nec imperdiet dolor, sit amet mattis ex. Sed sed augue eu neque tristique commodo. Mauris aliquet tortor sollicitudin nibh molestie, id egestas nisl sollicitudin. Aliquam erat volutpat. Donec quis ultrices ligula. Cras sed purus risus. Curabitur quis eros eu tortor semper eleifend. Pellentesque lorem elit, dignissim interdum massa id, malesuada rutrum ligula. Suspendisse tempor quis mauris eu facilisis. Phasellus non volutpat diam, non dapibus ligula. Ut non molestie ex, nec sagittis mi. Curabitur suscipit tellus id dolor pretium blandit. Cras tristique tristique pharetra.</p>
</div>
</div>
<div class="masonry-layout__panel">
<div class="masonry-layout__panel-content tx--white bg--green">
<h2>Some post about something</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis eu justo ex. Praesent mollis augue sagittis eros pharetra feugiat. Phasellus dignissim est lacus. Sed nec imperdiet dolor, sit amet mattis ex. Sed sed augue eu neque tristique commodo. Mauris aliquet tortor sollicitudin nibh molestie, id egestas nisl sollicitudin. Aliquam erat volutpat. Donec quis ultrices ligula. Cras sed purus risus. Curabitur quis eros eu tortor semper eleifend.</p>
</div>
</div>
<div class="masonry-layout__panel"><img src="img/photo-1.jpg" class="masonry-layout__panel-content masonry-layout__panel-content--img"/></div>
</div>
</body>
.masonry-layout {
box-sizing: border-box;
-webkit-column-count: 1;
-moz-column-count: 1;
column-count: 1;
-webkit-column-gap: 0;
-moz-column-gap: 0;
column-gap: 0;
}
.masonry-layout * {
box-sizing: border-box;
}
@media (min-width: 768px) {
.masonry-layout {
-webkit-column-count: 2;
-moz-column-count: 2;
column-count: 2;
}
}
@media (min-width: 1200px) {
.masonry-layout {
-webkit-column-count: 3;
-moz-column-count: 3;
column-count: 3;
}
}
.masonry-layout__panel-content {
padding: 10px;
border-radius: 10px;
overflow: hidden;
width: 100%;
}
.masonry-layout__panel-content--img {
max-width: 100%;
padding: 0;
}
.masonry-layout__panel-content--flipper {
position: relative;
overflow: visible;
height: 100%;
-webkit-transform-style: preserve-3d;
transform-style: preserve-3d;
-webkit-transition: 0.25s;
transition: 0.25s;
}
.masonry-layout__panel-content--front,
.masonry-layout__panel-content--back {
position: absolute;
top: 0;
left: 0;
overflow: hidden;
width: 100%;
height: 100%;
border-radius: 10px;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
}
.masonry-layout__panel-content--front {
z-index: 2;
-webkit-transform: rotateY(0deg);
transform: rotateY(0deg);
}
.masonry-layout__panel-content--back {
-webkit-transform: rotateY(180deg);
transform: rotateY(180deg);
}
.masonry-layout__panel {
padding: 5px;
}
@media (min-width: 768px) {
.masonry-layout__panel {
-webkit-column-break-inside: avoid;
page-break-inside: avoid;
break-inside: avoid;
}
}
.masonry-layout__panel--flipper-container {
-webkit-perspective: 1000;
perspective: 1000;
}
.masonry-layout__panel--flipper-container:hover .masonry-layout__panel-content--flipper {
-webkit-transform: rotateY(180deg);
transform: rotateY(180deg);
}
.masonry-layout__panel--small {
height: 200px;
}
.masonry-layout__panel--medium {
height: 300px;
}
.masonry-layout__panel--large {
height: 400px;
}
@media (max-width: 768px) {
.masonry-layout__panel--small,
.masonry-layout__panel--medium,
.masonry-layout__panel--large {
overflow: hidden;
height: auto;
}
}
.masonry-layout__panel--cluster {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
padding: 0;
-webkit-flex-wrap: wrap;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
-webkit-box-orient: horizontal;
-webkit-box-direction: normal;
-webkit-flex-direction: row;
-ms-flex-direction: row;
flex-direction: row;
}
.masonry-layout__panel--segment {
display: block;
width: 100%;
height: auto;
}
@media (min-width: 768px) {
.masonry-layout__panel--segment {
-webkit-box-flex: 1;
-webkit-flex: 1;
-ms-flex: 1;
flex: 1;
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
}
}
@media (min-width: 768px) {
.masonry-layout__panel--full-size {
-webkit-box-flex: 0;
-webkit-flex: 0 0 100%;
-ms-flex: 0 0 100%;
flex: 0 0 100%;
width: 100%;
height: 100%;
}
.masonry-layout__panel--half-size {
-webkit-box-flex: 0;
-webkit-flex: 0 0 50%;
-ms-flex: 0 0 50%;
flex: 0 0 50%;
width: 50%;
height: 50%;
}
.masonry-layout__panel--quarter-size {
-webkit-box-flex: 0;
-webkit-flex: 0 0 25%;
-ms-flex: 0 0 25%;
flex: 0 0 25%;
width: 25%;
height: 25%;
}
}
@media (min-width: 768px) {
.masonry-layout__panel--vertical {
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
}
.masonry-layout__panel--vertical .masonry-layout__panel--segment {
width: 50%;
}
.masonry-layout__panel--horizontal .masonry-layout__panel--segment {
height: 50%;
}
}
/**
* Theming
*/
img {
background-color: #Fb9f3b;
}
.tx--white {
color: #fff;
}
.bg--red {
background-color: #e74c3c;
}
.bg--green {
background-color: #26a65b;
}
.bg--purple {
background-color: #8e44ad;
}
.bg--blue {
background-color: #1e8bc3;
}
以上是关于css 纯CSS砌体布局 - https://medium.com/@_jh3y/how-to-pure-css-masonry-layouts-a8ede07ba31a#.fomk5pu69的主要内容,如果未能解决你的问题,请参考以下文章
css 纯CSS砌体布局 - https://medium.com/@_jh3y/how-to-pure-css-masonry-layouts-a8ede07ba31a#.fomk5pu69