我正在尝试使行之间的间距等于列间距 但我真的不知道是什么属性在行之间造成了这种差距。我试图摆弄网格间隙,但没有成功。
当屏幕尺寸减小时,右边距也会消失。
努力使该图库快速响应。
.container {
margin: auto;
padding: 0 1rem;
max-width: 90rem;
width: 100%;
}
.grid {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
-ms-flex-flow: row wrap;
flex-flow: row wrap;
}
.grid>[class*="column-"] {
display: block;
}
.first {
-webkit-box-ordinal-group: 0;
-ms-flex-order: -1;
order: -1;
}
.last {
-webkit-box-ordinal-group: 13;
-ms-flex-order: 12;
order: 12;
}
.align-top {
-webkit-box-align: start;
-ms-flex-align: start;
align-items: start;
}
.align-center {
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
}
.align-bottom {
-webkit-box-align: end;
-ms-flex-align: end;
align-items: end;
}
.column-xs-1 {
-ms-flex-preferred-size: 8.3333333333%;
flex-basis: 8.3333333333%;
max-width: 8.3333333333%;
}
.column-xs-2 {
-ms-flex-preferred-size: 16.6666666667%;
flex-basis: 16.6666666667%;
max-width: 16.6666666667%;
}
.column-xs-3 {
-ms-flex-preferred-size: 25%;
flex-basis: 25%;
max-width: 25%;
}
.column-xs-4 {
-ms-flex-preferred-size: 33.3333333333%;
flex-basis: 33.3333333333%;
max-width: 33.3333333333%;
}
.column-xs-5 {
-ms-flex-preferred-size: 41.6666666667%;
flex-basis: 41.6666666667%;
max-width: 41.6666666667%;
}
.column-xs-6 {
-ms-flex-preferred-size: 50%;
flex-basis: 50%;
max-width: 50%;
}
.column-xs-7 {
-ms-flex-preferred-size: 58.3333333333%;
flex-basis: 58.3333333333%;
max-width: 58.3333333333%;
}
.column-xs-8 {
-ms-flex-preferred-size: 66.6666666667%;
flex-basis: 66.6666666667%;
max-width: 66.6666666667%;
}
.column-xs-9 {
-ms-flex-preferred-size: 75%;
flex-basis: 75%;
max-width: 75%;
}
.column-xs-10 {
-ms-flex-preferred-size: 83.3333333333%;
flex-basis: 83.3333333333%;
max-width: 83.3333333333%;
}
.column-xs-11 {
-ms-flex-preferred-size: 91.6666666667%;
flex-basis: 91.6666666667%;
max-width: 91.6666666667%;
}
.column-xs-12 {
-ms-flex-preferred-size: 100%;
flex-basis: 100%;
max-width: 100%;
}
@media (min-width: 48rem) {
.column-sm-1 {
-ms-flex-preferred-size: 8.3333333333%;
flex-basis: 8.3333333333%;
max-width: 8.3333333333%;
}
.column-sm-2 {
-ms-flex-preferred-size: 16.6666666667%;
flex-basis: 16.6666666667%;
max-width: 16.6666666667%;
}
.column-sm-3 {
-ms-flex-preferred-size: 25%;
flex-basis: 25%;
max-width: 25%;
}
.column-sm-4 {
-ms-flex-preferred-size: 33.3333333333%;
flex-basis: 33.3333333333%;
max-width: 33.3333333333%;
}
.column-sm-5 {
-ms-flex-preferred-size: 41.6666666667%;
flex-basis: 41.6666666667%;
max-width: 41.6666666667%;
}
.column-sm-6 {
-ms-flex-preferred-size: 50%;
flex-basis: 50%;
max-width: 50%;
}
.column-sm-7 {
-ms-flex-preferred-size: 58.3333333333%;
flex-basis: 58.3333333333%;
max-width: 58.3333333333%;
}
.column-sm-8 {
-ms-flex-preferred-size: 66.6666666667%;
flex-basis: 66.6666666667%;
max-width: 66.6666666667%;
}
.column-sm-9 {
-ms-flex-preferred-size: 75%;
flex-basis: 75%;
max-width: 75%;
}
.column-sm-10 {
-ms-flex-preferred-size: 83.3333333333%;
flex-basis: 83.3333333333%;
max-width: 83.3333333333%;
}
.column-sm-11 {
-ms-flex-preferred-size: 91.6666666667%;
flex-basis: 91.6666666667%;
max-width: 91.6666666667%;
}
.column-sm-12 {
-ms-flex-preferred-size: 100%;
flex-basis: 100%;
max-width: 100%;
}
}
@media (min-width: 62rem) {
.column-md-1 {
-ms-flex-preferred-size: 8.3333333333%;
flex-basis: 8.3333333333%;
max-width: 8.3333333333%;
}
.column-md-2 {
-ms-flex-preferred-size: 16.6666666667%;
flex-basis: 16.6666666667%;
max-width: 16.6666666667%;
}
.column-md-3 {
-ms-flex-preferred-size: 25%;
flex-basis: 25%;
max-width: 25%;
}
.column-md-4 {
-ms-flex-preferred-size: 33.3333333333%;
flex-basis: 33.3333333333%;
max-width: 33.3333333333%;
}
.column-md-5 {
-ms-flex-preferred-size: 41.6666666667%;
flex-basis: 41.6666666667%;
max-width: 41.6666666667%;
}
.column-md-6 {
-ms-flex-preferred-size: 50%;
flex-basis: 50%;
max-width: 50%;
}
.column-md-7 {
-ms-flex-preferred-size: 58.3333333333%;
flex-basis: 58.3333333333%;
max-width: 58.3333333333%;
}
.column-md-8 {
-ms-flex-preferred-size: 66.6666666667%;
flex-basis: 66.6666666667%;
max-width: 66.6666666667%;
}
.column-md-9 {
-ms-flex-preferred-size: 75%;
flex-basis: 75%;
max-width: 75%;
}
.column-md-10 {
-ms-flex-preferred-size: 83.3333333333%;
flex-basis: 83.3333333333%;
max-width: 83.3333333333%;
}
.column-md-11 {
-ms-flex-preferred-size: 91.6666666667%;
flex-basis: 91.6666666667%;
max-width: 91.6666666667%;
}
.column-md-12 {
-ms-flex-preferred-size: 100%;
flex-basis: 100%;
max-width: 100%;
}
}
@media (min-width: 75rem) {
.column-lg-1 {
-ms-flex-preferred-size: 8.3333333333%;
flex-basis: 8.3333333333%;
max-width: 8.3333333333%;
}
.column-lg-2 {
-ms-flex-preferred-size: 16.6666666667%;
flex-basis: 16.6666666667%;
max-width: 16.6666666667%;
}
.column-lg-3 {
-ms-flex-preferred-size: 25%;
flex-basis: 25%;
max-width: 25%;
}
.column-lg-4 {
-ms-flex-preferred-size: 33.3333333333%;
flex-basis: 33.3333333333%;
max-width: 33.3333333333%;
}
.column-lg-5 {
-ms-flex-preferred-size: 41.6666666667%;
flex-basis: 41.6666666667%;
max-width: 41.6666666667%;
}
.column-lg-6 {
-ms-flex-preferred-size: 50%;
flex-basis: 50%;
max-width: 50%;
}
.column-lg-7 {
-ms-flex-preferred-size: 58.3333333333%;
flex-basis: 58.3333333333%;
max-width: 58.3333333333%;
}
.column-lg-8 {
-ms-flex-preferred-size: 66.6666666667%;
flex-basis: 66.6666666667%;
max-width: 66.6666666667%;
}
.column-lg-9 {
-ms-flex-preferred-size: 75%;
flex-basis: 75%;
max-width: 75%;
}
.column-lg-10 {
-ms-flex-preferred-size: 83.3333333333%;
flex-basis: 83.3333333333%;
max-width: 83.3333333333%;
}
.column-lg-11 {
-ms-flex-preferred-size: 91.6666666667%;
flex-basis: 91.6666666667%;
max-width: 91.6666666667%;
}
.column-lg-12 {
-ms-flex-preferred-size: 100%;
flex-basis: 100%;
max-width: 100%;
}
}
@supports (display: grid) {
.grid {
display: grid;
grid-template-columns: repeat(12, 1fr);
grid-template-rows: auto;
}
.grid>[class*="column-"] {
margin: 0;
max-width: 100%;
}
.column-xs-1 {
grid-column-start: span 1;
grid-column-end: span 1;
}
.column-xs-2 {
grid-column-start: span 2;
grid-column-end: span 2;
}
.column-xs-3 {
grid-column-start: span 3;
grid-column-end: span 3;
}
.column-xs-4 {
grid-column-start: span 4;
grid-column-end: span 4;
}
.column-xs-5 {
grid-column-start: span 5;
grid-column-end: span 5;
}
.column-xs-6 {
grid-column-start: span 6;
grid-column-end: span 6;
}
.column-xs-7 {
grid-column-start: span 7;
grid-column-end: span 7;
}
.column-xs-8 {
grid-column-start: span 8;
grid-column-end: span 8;
}
.column-xs-9 {
grid-column-start: span 9;
grid-column-end: span 9;
}
.column-xs-10 {
grid-column-start: span 10;
grid-column-end: span 10;
}
.column-xs-11 {
grid-column-start: span 11;
grid-column-end: span 11;
}
.column-xs-12 {
grid-column-start: span 12;
grid-column-end: span 12;
}
@media (min-width: 48rem) {
.column-sm-1 {
grid-column-start: span 1;
grid-column-end: span 1;
}
.column-sm-2 {
grid-column-start: span 2;
grid-column-end: span 2;
}
.column-sm-3 {
grid-column-start: span 3;
grid-column-end: span 3;
}
.column-sm-4 {
grid-column-start: span 4;
grid-column-end: span 4;
}
.column-sm-5 {
grid-column-start: span 5;
grid-column-end: span 5;
}
.column-sm-6 {
grid-column-start: span 6;
grid-column-end: span 6;
}
.column-sm-7 {
grid-column-start: span 7;
grid-column-end: span 7;
}
.column-sm-8 {
grid-column-start: span 8;
grid-column-end: span 8;
}
.column-sm-9 {
grid-column-start: span 9;
grid-column-end: span 9;
}
.column-sm-10 {
grid-column-start: span 10;
grid-column-end: span 10;
}
.column-sm-11 {
grid-column-start: span 11;
grid-column-end: span 11;
}
.column-sm-12 {
grid-column-start: span 12;
grid-column-end: span 12;
}
}
@media (min-width: 62rem) {
.column-md-1 {
grid-column-start: span 1;
grid-column-end: span 1;
}
.column-md-2 {
grid-column-start: span 2;
grid-column-end: span 2;
}
.column-md-3 {
grid-column-start: span 3;
grid-column-end: span 3;
}
.column-md-4 {
grid-column-start: span 4;
grid-column-end: span 4;
}
.column-md-5 {
grid-column-start: span 5;
grid-column-end: span 5;
}
.column-md-6 {
grid-column-start: span 6;
grid-column-end: span 6;
}
.column-md-7 {
grid-column-start: span 7;
grid-column-end: span 7;
}
.column-md-8 {
grid-column-start: span 8;
grid-column-end: span 8;
}
.column-md-9 {
grid-column-start: span 9;
grid-column-end: span 9;
}
.column-md-10 {
grid-column-start: span 10;
grid-column-end: span 10;
}
.column-md-11 {
grid-column-start: span 11;
grid-column-end: span 11;
}
.column-md-12 {
grid-column-start: span 12;
grid-column-end: span 12;
}
}
@media (min-width: 75rem) {
.column-lg-1 {
grid-column-start: span 1;
grid-column-end: span 1;
}
.column-lg-2 {
grid-column-start: span 2;
grid-column-end: span 2;
}
.column-lg-3 {
grid-column-start: span 3;
grid-column-end: span 3;
}
.column-lg-4 {
grid-column-start: span 4;
grid-column-end: span 4;
}
.column-lg-5 {
grid-column-start: span 5;
grid-column-end: span 5;
}
.column-lg-6 {
grid-column-start: span 6;
grid-column-end: span 6;
}
.column-lg-7 {
grid-column-start: span 7;
grid-column-end: span 7;
}
.column-lg-8 {
grid-column-start: span 8;
grid-column-end: span 8;
}
.column-lg-9 {
grid-column-start: span 9;
grid-column-end: span 9;
}
.column-lg-10 {
grid-column-start: span 10;
grid-column-end: span 10;
}
.column-lg-11 {
grid-column-start: span 11;
grid-column-end: span 11;
}
.column-lg-12 {
grid-column-start: span 12;
grid-column-end: span 12;
}
}
}
* {
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
*::before,
*::after {
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
body {
font-family: 'Barlow', sans-serif;
font-size: 1.125rem;
line-height: 1.5;
color: #787878;
background: #fff;
text-rendering: optimizeLegibility;
}
ul li {
margin: 0 1.5rem 0 0;
}
a {
color: #787878;
text-decoration: none;
-webkit-transition: all 0.2s ease;
-o-transition: all 0.2s ease;
transition: all 0.2s ease;
}
a:hover {
color: #2e2e2e;
}
a.active {
color: #2e2e2e;
}
nav {
padding: 2.5rem 0 2.5rem 0;
}
nav ul {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: left;
-ms-flex-pack: left;
justify-content: left;
}
nav li {
font-size: 1.25rem;
}
nav li:nth-child(2) {
margin: 0;
}
#highlight {
color: #ea8478;
font-size: 1.25rem;
}
.gallery {
padding: 0 0 4rem 0;
}
.img-container {
width: 100%;
height: 500px;
cursor: pointer;
overflow: hidden;
}
.img-container:hover .img-content-hover {
display: block;
}
.moto {
width: 100%;
height: 500px;
-o-object-fit: cover;
object-fit: cover;
-webkit-transform: scale(1);
-ms-transform: scale(1);
transform: scale(1);
-webkit-transition: all 0.3s ease-in-out;
-o-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
}
.moto:hover {
-webkit-transform: scale(1.05);
-ms-transform: scale(1.05);
transform: scale(1.05);
}
.img-content-hover {
position: absolute;
z-index: 1;
white-space: nowrap;
display: none;
padding: 1rem;
background: #fff;
font-weight: 400;
margin-top: 1.25rem;
margin-left: -2rem;
}
.title {
color: #2e2e2e;
font-size: 1.5rem;
font-weight: 700;
}
.category {
font-size: 1rem;
color: #787878;
}
.img-content {
display: none;
}
.social,
.copyright {
margin: 1rem;
}
.social li {
display: inline-block;
}
footer {
padding: 1rem 0;
background: #23272A;
text-align: center;
}
@supports (display: grid) {
.gallery .grid {
grid-gap: 1rem;
}
}
@media (min-width: 62rem) {
nav ul {
-webkit-box-pack: right;
-ms-flex-pack: right;
justify-content: right;
}
}
@media screen and (max-width: 1024px) {
img:hover {
-webkit-transform: none;
-ms-transform: none;
transform: none;
}
.img-container {
height: 100%;
}
.img-container:hover .img-content-hover {
display: none;
}
.img-content {
display: block;
padding: 1rem 0;
}
}
<section class="gallery">
<div class="container">
<div class="grid">
<div class="column-xs-12 column-md-4">
<figure class="img-container">
<img class="moto" src="https://source.unsplash.com/8b1cWDyvT7Y" />
<figcaption class="img-content">
<h2 class="title">Smart Watch</h2>
<h3 class="category">Showcase</h3>
</figcaption>
<span class="img-content-hover">
<h2 class="title">Smart Watch</h2>
<h3 class="category">Showcase</h3>
</span>
</figure>
</div>
<div class="column-xs-12 column-md-4">
<figure class="img-container">
<img class="moto" src="https://source.unsplash.com/5VXH4RG88gc" />
<figcaption class="img-content">
<h2 class="title">Camera Film</h2>
<h3 class="category">Showcase</h3>
</figcaption>
<span class="img-content-hover">
<h2 class="title">Camera Film</h2>
<h3 class="category">Showcase</h3>
</span>
</figure>
</div>
<div class="column-xs-12 column-md-4">
<figure class="img-container">
<img class="moto" src="https://source.unsplash.com/XtUd5SiX464">
<figcaption class="img-content">
<h2 class="title">Coffee</h2>
<h3 class="category">Showcase</h3>
</figcaption>
<span class="img-content-hover">
<h2 class="title">Coffee</h2>
<h3 class="category">Showcase</h3>
</span>
</figure>
</div>
<div class="column-xs-12 column-md-6">
<figure class="img-container">
<img class="moto" src="https://source.unsplash.com/JYGnB9gTCls" />
<figcaption class="img-content">
<h2 class="title">Phone</h2>
<h3 class="category">Showcase</h3>
</figcaption>
<span class="img-content-hover">
<h2 class="title">Phone</h2>
<h3 class="category">Showcase</h3>
</span>
</figure>
</div>
<div class="column-xs-12 column-md-6">
<figure class="img-container">
<img class="moto" src="https://source.unsplash.com/-RBuQ2PK_L8" />
<figcaption class="img-content">
<h2 class="title">Keyboard</h2>
<h3 class="category">Showcase</h3>
</figcaption>
<span class="img-content-hover">
<h2 class="title">Keyboard</h2>
<h3 class="category">Showcase</h3>
</span>
</figure>
</div>
<div class="column-xs-12 column-md-4">
<figure class="img-container">
<img class="moto" src="https://source.unsplash.com/8b1cWDyvT7Y" />
<figcaption class="img-content">
<h2 class="title">Smart Watch</h2>
<h3 class="category">Showcase</h3>
</figcaption>
<span class="img-content-hover">
<h2 class="title">Smart Watch</h2>
<h3 class="category">Showcase</h3>
</span>
</figure>
</div>
<div class="column-xs-12 column-md-4">
<figure class="img-container">
<img class="moto" src="https://source.unsplash.com/5VXH4RG88gc" />
<figcaption class="img-content">
<h2 class="title">Camera Film</h2>
<h3 class="category">Showcase</h3>
</figcaption>
<span class="img-content-hover">
<h2 class="title">Camera Film</h2>
<h3 class="category">Showcase</h3>
</span>
</figure>
</div>
<div class="column-xs-12 column-md-4">
<figure class="img-container">
<img class="moto" src="https://source.unsplash.com/XtUd5SiX464">
<figcaption class="img-content">
<h2 class="title">Coffee</h2>
<h3 class="category">Showcase</h3>
</figcaption>
<span class="img-content-hover">
<h2 class="title">Coffee</h2>
<h3 class="category">Showcase</h3>
</span>
</figure>
</div>
<div class="column-xs-12 column-md-6">
<figure class="img-container">
<img class="moto" src="https://source.unsplash.com/JYGnB9gTCls" />
<figcaption class="img-content">
<h2 class="title">Phone</h2>
<h3 class="category">Showcase</h3>
</figcaption>
<span class="img-content-hover">
<h2 class="title">Phone</h2>
<h3 class="category">Showcase</h3>
</span>
</figure>
</div>
<div class="column-xs-12 column-md-6">
<figure class="img-container">
<img class="moto" src="https://source.unsplash.com/-RBuQ2PK_L8" />
<figcaption class="img-content">
<h2 class="title">Keyboard</h2>
<h3 class="category">Showcase</h3>
</figcaption>
<span class="img-content-hover">
<h2 class="title">Keyboard</h2>
<h3 class="category">Showcase</h3>
</span>
</figure>
</div>
</div>
</div>
</section>
答案 0 :(得分:1)
该问题与grip-gap
属性无关。
实际上,grid-column-gap
和grid-row-gap
的渲染长度均与您指定的相同:
.gallery .grid {
grid-gap: 1rem;
}
是的,差距似乎有所不同。
但是如果突出显示网格,您会发现差距是相同的:
(使用Chrome开发者工具概述。)
此问题是由于网格项目的内容未填充每个项目的整个高度而引起的。
这是由figure
元素上的默认边距引起的:
(了解margin-block-*
和margin-inline-*
属性。)
因此解决方案是覆盖这些边距。将此添加到您的代码中:
figure.img-container {
margin: 0;
}
figure.img-container {
margin: 0;
}
.container {
margin: auto;
padding: 0 1rem;
max-width: 90rem;
width: 100%;
}
.grid {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
-ms-flex-flow: row wrap;
flex-flow: row wrap;
}
.grid>[class*="column-"] {
display: block;
}
.first {
-webkit-box-ordinal-group: 0;
-ms-flex-order: -1;
order: -1;
}
.last {
-webkit-box-ordinal-group: 13;
-ms-flex-order: 12;
order: 12;
}
.align-top {
-webkit-box-align: start;
-ms-flex-align: start;
align-items: start;
}
.align-center {
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
}
.align-bottom {
-webkit-box-align: end;
-ms-flex-align: end;
align-items: end;
}
.column-xs-1 {
-ms-flex-preferred-size: 8.3333333333%;
flex-basis: 8.3333333333%;
max-width: 8.3333333333%;
}
.column-xs-2 {
-ms-flex-preferred-size: 16.6666666667%;
flex-basis: 16.6666666667%;
max-width: 16.6666666667%;
}
.column-xs-3 {
-ms-flex-preferred-size: 25%;
flex-basis: 25%;
max-width: 25%;
}
.column-xs-4 {
-ms-flex-preferred-size: 33.3333333333%;
flex-basis: 33.3333333333%;
max-width: 33.3333333333%;
}
.column-xs-5 {
-ms-flex-preferred-size: 41.6666666667%;
flex-basis: 41.6666666667%;
max-width: 41.6666666667%;
}
.column-xs-6 {
-ms-flex-preferred-size: 50%;
flex-basis: 50%;
max-width: 50%;
}
.column-xs-7 {
-ms-flex-preferred-size: 58.3333333333%;
flex-basis: 58.3333333333%;
max-width: 58.3333333333%;
}
.column-xs-8 {
-ms-flex-preferred-size: 66.6666666667%;
flex-basis: 66.6666666667%;
max-width: 66.6666666667%;
}
.column-xs-9 {
-ms-flex-preferred-size: 75%;
flex-basis: 75%;
max-width: 75%;
}
.column-xs-10 {
-ms-flex-preferred-size: 83.3333333333%;
flex-basis: 83.3333333333%;
max-width: 83.3333333333%;
}
.column-xs-11 {
-ms-flex-preferred-size: 91.6666666667%;
flex-basis: 91.6666666667%;
max-width: 91.6666666667%;
}
.column-xs-12 {
-ms-flex-preferred-size: 100%;
flex-basis: 100%;
max-width: 100%;
}
@media (min-width: 48rem) {
.column-sm-1 {
-ms-flex-preferred-size: 8.3333333333%;
flex-basis: 8.3333333333%;
max-width: 8.3333333333%;
}
.column-sm-2 {
-ms-flex-preferred-size: 16.6666666667%;
flex-basis: 16.6666666667%;
max-width: 16.6666666667%;
}
.column-sm-3 {
-ms-flex-preferred-size: 25%;
flex-basis: 25%;
max-width: 25%;
}
.column-sm-4 {
-ms-flex-preferred-size: 33.3333333333%;
flex-basis: 33.3333333333%;
max-width: 33.3333333333%;
}
.column-sm-5 {
-ms-flex-preferred-size: 41.6666666667%;
flex-basis: 41.6666666667%;
max-width: 41.6666666667%;
}
.column-sm-6 {
-ms-flex-preferred-size: 50%;
flex-basis: 50%;
max-width: 50%;
}
.column-sm-7 {
-ms-flex-preferred-size: 58.3333333333%;
flex-basis: 58.3333333333%;
max-width: 58.3333333333%;
}
.column-sm-8 {
-ms-flex-preferred-size: 66.6666666667%;
flex-basis: 66.6666666667%;
max-width: 66.6666666667%;
}
.column-sm-9 {
-ms-flex-preferred-size: 75%;
flex-basis: 75%;
max-width: 75%;
}
.column-sm-10 {
-ms-flex-preferred-size: 83.3333333333%;
flex-basis: 83.3333333333%;
max-width: 83.3333333333%;
}
.column-sm-11 {
-ms-flex-preferred-size: 91.6666666667%;
flex-basis: 91.6666666667%;
max-width: 91.6666666667%;
}
.column-sm-12 {
-ms-flex-preferred-size: 100%;
flex-basis: 100%;
max-width: 100%;
}
}
@media (min-width: 62rem) {
.column-md-1 {
-ms-flex-preferred-size: 8.3333333333%;
flex-basis: 8.3333333333%;
max-width: 8.3333333333%;
}
.column-md-2 {
-ms-flex-preferred-size: 16.6666666667%;
flex-basis: 16.6666666667%;
max-width: 16.6666666667%;
}
.column-md-3 {
-ms-flex-preferred-size: 25%;
flex-basis: 25%;
max-width: 25%;
}
.column-md-4 {
-ms-flex-preferred-size: 33.3333333333%;
flex-basis: 33.3333333333%;
max-width: 33.3333333333%;
}
.column-md-5 {
-ms-flex-preferred-size: 41.6666666667%;
flex-basis: 41.6666666667%;
max-width: 41.6666666667%;
}
.column-md-6 {
-ms-flex-preferred-size: 50%;
flex-basis: 50%;
max-width: 50%;
}
.column-md-7 {
-ms-flex-preferred-size: 58.3333333333%;
flex-basis: 58.3333333333%;
max-width: 58.3333333333%;
}
.column-md-8 {
-ms-flex-preferred-size: 66.6666666667%;
flex-basis: 66.6666666667%;
max-width: 66.6666666667%;
}
.column-md-9 {
-ms-flex-preferred-size: 75%;
flex-basis: 75%;
max-width: 75%;
}
.column-md-10 {
-ms-flex-preferred-size: 83.3333333333%;
flex-basis: 83.3333333333%;
max-width: 83.3333333333%;
}
.column-md-11 {
-ms-flex-preferred-size: 91.6666666667%;
flex-basis: 91.6666666667%;
max-width: 91.6666666667%;
}
.column-md-12 {
-ms-flex-preferred-size: 100%;
flex-basis: 100%;
max-width: 100%;
}
}
@media (min-width: 75rem) {
.column-lg-1 {
-ms-flex-preferred-size: 8.3333333333%;
flex-basis: 8.3333333333%;
max-width: 8.3333333333%;
}
.column-lg-2 {
-ms-flex-preferred-size: 16.6666666667%;
flex-basis: 16.6666666667%;
max-width: 16.6666666667%;
}
.column-lg-3 {
-ms-flex-preferred-size: 25%;
flex-basis: 25%;
max-width: 25%;
}
.column-lg-4 {
-ms-flex-preferred-size: 33.3333333333%;
flex-basis: 33.3333333333%;
max-width: 33.3333333333%;
}
.column-lg-5 {
-ms-flex-preferred-size: 41.6666666667%;
flex-basis: 41.6666666667%;
max-width: 41.6666666667%;
}
.column-lg-6 {
-ms-flex-preferred-size: 50%;
flex-basis: 50%;
max-width: 50%;
}
.column-lg-7 {
-ms-flex-preferred-size: 58.3333333333%;
flex-basis: 58.3333333333%;
max-width: 58.3333333333%;
}
.column-lg-8 {
-ms-flex-preferred-size: 66.6666666667%;
flex-basis: 66.6666666667%;
max-width: 66.6666666667%;
}
.column-lg-9 {
-ms-flex-preferred-size: 75%;
flex-basis: 75%;
max-width: 75%;
}
.column-lg-10 {
-ms-flex-preferred-size: 83.3333333333%;
flex-basis: 83.3333333333%;
max-width: 83.3333333333%;
}
.column-lg-11 {
-ms-flex-preferred-size: 91.6666666667%;
flex-basis: 91.6666666667%;
max-width: 91.6666666667%;
}
.column-lg-12 {
-ms-flex-preferred-size: 100%;
flex-basis: 100%;
max-width: 100%;
}
}
@supports (display: grid) {
.grid {
display: grid;
grid-template-columns: repeat(12, 1fr);
grid-template-rows: auto;
}
.grid>[class*="column-"] {
margin: 0;
max-width: 100%;
}
.column-xs-1 {
grid-column-start: span 1;
grid-column-end: span 1;
}
.column-xs-2 {
grid-column-start: span 2;
grid-column-end: span 2;
}
.column-xs-3 {
grid-column-start: span 3;
grid-column-end: span 3;
}
.column-xs-4 {
grid-column-start: span 4;
grid-column-end: span 4;
}
.column-xs-5 {
grid-column-start: span 5;
grid-column-end: span 5;
}
.column-xs-6 {
grid-column-start: span 6;
grid-column-end: span 6;
}
.column-xs-7 {
grid-column-start: span 7;
grid-column-end: span 7;
}
.column-xs-8 {
grid-column-start: span 8;
grid-column-end: span 8;
}
.column-xs-9 {
grid-column-start: span 9;
grid-column-end: span 9;
}
.column-xs-10 {
grid-column-start: span 10;
grid-column-end: span 10;
}
.column-xs-11 {
grid-column-start: span 11;
grid-column-end: span 11;
}
.column-xs-12 {
grid-column-start: span 12;
grid-column-end: span 12;
}
@media (min-width: 48rem) {
.column-sm-1 {
grid-column-start: span 1;
grid-column-end: span 1;
}
.column-sm-2 {
grid-column-start: span 2;
grid-column-end: span 2;
}
.column-sm-3 {
grid-column-start: span 3;
grid-column-end: span 3;
}
.column-sm-4 {
grid-column-start: span 4;
grid-column-end: span 4;
}
.column-sm-5 {
grid-column-start: span 5;
grid-column-end: span 5;
}
.column-sm-6 {
grid-column-start: span 6;
grid-column-end: span 6;
}
.column-sm-7 {
grid-column-start: span 7;
grid-column-end: span 7;
}
.column-sm-8 {
grid-column-start: span 8;
grid-column-end: span 8;
}
.column-sm-9 {
grid-column-start: span 9;
grid-column-end: span 9;
}
.column-sm-10 {
grid-column-start: span 10;
grid-column-end: span 10;
}
.column-sm-11 {
grid-column-start: span 11;
grid-column-end: span 11;
}
.column-sm-12 {
grid-column-start: span 12;
grid-column-end: span 12;
}
}
@media (min-width: 62rem) {
.column-md-1 {
grid-column-start: span 1;
grid-column-end: span 1;
}
.column-md-2 {
grid-column-start: span 2;
grid-column-end: span 2;
}
.column-md-3 {
grid-column-start: span 3;
grid-column-end: span 3;
}
.column-md-4 {
grid-column-start: span 4;
grid-column-end: span 4;
}
.column-md-5 {
grid-column-start: span 5;
grid-column-end: span 5;
}
.column-md-6 {
grid-column-start: span 6;
grid-column-end: span 6;
}
.column-md-7 {
grid-column-start: span 7;
grid-column-end: span 7;
}
.column-md-8 {
grid-column-start: span 8;
grid-column-end: span 8;
}
.column-md-9 {
grid-column-start: span 9;
grid-column-end: span 9;
}
.column-md-10 {
grid-column-start: span 10;
grid-column-end: span 10;
}
.column-md-11 {
grid-column-start: span 11;
grid-column-end: span 11;
}
.column-md-12 {
grid-column-start: span 12;
grid-column-end: span 12;
}
}
@media (min-width: 75rem) {
.column-lg-1 {
grid-column-start: span 1;
grid-column-end: span 1;
}
.column-lg-2 {
grid-column-start: span 2;
grid-column-end: span 2;
}
.column-lg-3 {
grid-column-start: span 3;
grid-column-end: span 3;
}
.column-lg-4 {
grid-column-start: span 4;
grid-column-end: span 4;
}
.column-lg-5 {
grid-column-start: span 5;
grid-column-end: span 5;
}
.column-lg-6 {
grid-column-start: span 6;
grid-column-end: span 6;
}
.column-lg-7 {
grid-column-start: span 7;
grid-column-end: span 7;
}
.column-lg-8 {
grid-column-start: span 8;
grid-column-end: span 8;
}
.column-lg-9 {
grid-column-start: span 9;
grid-column-end: span 9;
}
.column-lg-10 {
grid-column-start: span 10;
grid-column-end: span 10;
}
.column-lg-11 {
grid-column-start: span 11;
grid-column-end: span 11;
}
.column-lg-12 {
grid-column-start: span 12;
grid-column-end: span 12;
}
}
}
* {
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
*::before,
*::after {
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
body {
font-family: 'Barlow', sans-serif;
font-size: 1.125rem;
line-height: 1.5;
color: #787878;
background: #fff;
text-rendering: optimizeLegibility;
}
ul li {
margin: 0 1.5rem 0 0;
}
a {
color: #787878;
text-decoration: none;
-webkit-transition: all 0.2s ease;
-o-transition: all 0.2s ease;
transition: all 0.2s ease;
}
a:hover {
color: #2e2e2e;
}
a.active {
color: #2e2e2e;
}
nav {
padding: 2.5rem 0 2.5rem 0;
}
nav ul {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: left;
-ms-flex-pack: left;
justify-content: left;
}
nav li {
font-size: 1.25rem;
}
nav li:nth-child(2) {
margin: 0;
}
#highlight {
color: #ea8478;
font-size: 1.25rem;
}
.gallery {
padding: 0 0 4rem 0;
}
.img-container {
width: 100%;
height: 500px;
cursor: pointer;
overflow: hidden;
}
.img-container:hover .img-content-hover {
display: block;
}
.moto {
width: 100%;
height: 500px;
-o-object-fit: cover;
object-fit: cover;
-webkit-transform: scale(1);
-ms-transform: scale(1);
transform: scale(1);
-webkit-transition: all 0.3s ease-in-out;
-o-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
}
.moto:hover {
-webkit-transform: scale(1.05);
-ms-transform: scale(1.05);
transform: scale(1.05);
}
.img-content-hover {
position: absolute;
z-index: 1;
white-space: nowrap;
display: none;
padding: 1rem;
background: #fff;
font-weight: 400;
margin-top: 1.25rem;
margin-left: -2rem;
}
.title {
color: #2e2e2e;
font-size: 1.5rem;
font-weight: 700;
}
.category {
font-size: 1rem;
color: #787878;
}
.img-content {
display: none;
}
.social,
.copyright {
margin: 1rem;
}
.social li {
display: inline-block;
}
footer {
padding: 1rem 0;
background: #23272A;
text-align: center;
}
@supports (display: grid) {
.gallery .grid {
grid-gap: 1rem;
}
}
@media (min-width: 62rem) {
nav ul {
-webkit-box-pack: right;
-ms-flex-pack: right;
justify-content: right;
}
}
@media screen and (max-width: 1024px) {
img:hover {
-webkit-transform: none;
-ms-transform: none;
transform: none;
}
.img-container {
height: 100%;
}
.img-container:hover .img-content-hover {
display: none;
}
.img-content {
display: block;
padding: 1rem 0;
}
}
<section class="gallery">
<div class="container">
<div class="grid">
<div class="column-xs-12 column-md-4">
<figure class="img-container">
<img class="moto" src="https://source.unsplash.com/8b1cWDyvT7Y" />
<figcaption class="img-content">
<h2 class="title">Smart Watch</h2>
<h3 class="category">Showcase</h3>
</figcaption>
<span class="img-content-hover">
<h2 class="title">Smart Watch</h2>
<h3 class="category">Showcase</h3>
</span>
</figure>
</div>
<div class="column-xs-12 column-md-4">
<figure class="img-container">
<img class="moto" src="https://source.unsplash.com/5VXH4RG88gc" />
<figcaption class="img-content">
<h2 class="title">Camera Film</h2>
<h3 class="category">Showcase</h3>
</figcaption>
<span class="img-content-hover">
<h2 class="title">Camera Film</h2>
<h3 class="category">Showcase</h3>
</span>
</figure>
</div>
<div class="column-xs-12 column-md-4">
<figure class="img-container">
<img class="moto" src="https://source.unsplash.com/XtUd5SiX464">
<figcaption class="img-content">
<h2 class="title">Coffee</h2>
<h3 class="category">Showcase</h3>
</figcaption>
<span class="img-content-hover">
<h2 class="title">Coffee</h2>
<h3 class="category">Showcase</h3>
</span>
</figure>
</div>
<div class="column-xs-12 column-md-6">
<figure class="img-container">
<img class="moto" src="https://source.unsplash.com/JYGnB9gTCls" />
<figcaption class="img-content">
<h2 class="title">Phone</h2>
<h3 class="category">Showcase</h3>
</figcaption>
<span class="img-content-hover">
<h2 class="title">Phone</h2>
<h3 class="category">Showcase</h3>
</span>
</figure>
</div>
<div class="column-xs-12 column-md-6">
<figure class="img-container">
<img class="moto" src="https://source.unsplash.com/-RBuQ2PK_L8" />
<figcaption class="img-content">
<h2 class="title">Keyboard</h2>
<h3 class="category">Showcase</h3>
</figcaption>
<span class="img-content-hover">
<h2 class="title">Keyboard</h2>
<h3 class="category">Showcase</h3>
</span>
</figure>
</div>
<div class="column-xs-12 column-md-4">
<figure class="img-container">
<img class="moto" src="https://source.unsplash.com/8b1cWDyvT7Y" />
<figcaption class="img-content">
<h2 class="title">Smart Watch</h2>
<h3 class="category">Showcase</h3>
</figcaption>
<span class="img-content-hover">
<h2 class="title">Smart Watch</h2>
<h3 class="category">Showcase</h3>
</span>
</figure>
</div>
<div class="column-xs-12 column-md-4">
<figure class="img-container">
<img class="moto" src="https://source.unsplash.com/5VXH4RG88gc" />
<figcaption class="img-content">
<h2 class="title">Camera Film</h2>
<h3 class="category">Showcase</h3>
</figcaption>
<span class="img-content-hover">
<h2 class="title">Camera Film</h2>
<h3 class="category">Showcase</h3>
</span>
</figure>
</div>
<div class="column-xs-12 column-md-4">
<figure class="img-container">
<img class="moto" src="https://source.unsplash.com/XtUd5SiX464">
<figcaption class="img-content">
<h2 class="title">Coffee</h2>
<h3 class="category">Showcase</h3>
</figcaption>
<span class="img-content-hover">
<h2 class="title">Coffee</h2>
<h3 class="category">Showcase</h3>
</span>
</figure>
</div>
<div class="column-xs-12 column-md-6">
<figure class="img-container">
<img class="moto" src="https://source.unsplash.com/JYGnB9gTCls" />
<figcaption class="img-content">
<h2 class="title">Phone</h2>
<h3 class="category">Showcase</h3>
</figcaption>
<span class="img-content-hover">
<h2 class="title">Phone</h2>
<h3 class="category">Showcase</h3>
</span>
</figure>
</div>
<div class="column-xs-12 column-md-6">
<figure class="img-container">
<img class="moto" src="https://source.unsplash.com/-RBuQ2PK_L8" />
<figcaption class="img-content">
<h2 class="title">Keyboard</h2>
<h3 class="category">Showcase</h3>
</figcaption>
<span class="img-content-hover">
<h2 class="title">Keyboard</h2>
<h3 class="category">Showcase</h3>
</span>
</figure>
</div>
</div>
</div>
</section>
答案 1 :(得分:0)
似乎已经添加了一些默认边距,这使整个网格脱离了重击,现已找到并解决。非常感谢!