有些问题非常相似,但我无法将其与我的具体情况联系起来。
我创建了一个响应式缩略图网格,其中包含4到3到2列的结构(百分比为25%-33,33%-50%)。
我正在使用500x330px的假占位符图像进行测试,但我希望有一个固定的缩略图占位符(css代码?),响应速度为500x330,并保持放置在中心的图像的方面无线电(垂直和水平)占位符缩略图。
在小提琴示例中,我在Photoshop中制作了一些尺寸为500x330像素并且在不同的肖像和风景尺寸中的缩略图,因此它不是真正的风景图像,但它给出了我想要实现的想法。我希望有人理解我的问题,可以帮助我或指导我。
<div class="col-4">
<a class="thumb" href="#">
<img src="img/test2.jpg">
<div class="caption">Project untitled<br> Category</div>
</a>
</div>
答案 0 :(得分:1)
我认为This是你想要实现的结果。
我在每个拇指周围添加了一个div.img-wrapper和一些css magic
<div id="container">
<div class="col-4">
<div class="img-wrapper"> <a class="thumb" href="#">
<img src="http://mintywhite.com/wp-content/uploads/2012/10/fond-ecran-wallpaper-image-arriere-plan-hd-29-HD.jpg">
<div class="caption">Project untitled<br> Category</div>
</a>
</div>
</div>
<div class="col-4">
<div class="img-wrapper"> <a class="thumb" href="#">
<img src="http://fakeimg.pl/500x330/ccc/">
<div class="caption">Project untitled<br> Category</div>
</a>
</div>
</div>
<div class="col-4">
<div class="img-wrapper"> <a class="thumb" href="#">
<img src="http://www.gettyimages.com/CMS/Pages/ImageCollection/StaticContent/image1_%20164248809.jpg">
<div class="caption">Project untitled<br> Category</div>
</a>
</div>
</div>
<div class="col-4">
<div class="img-wrapper"> <a class="thumb" href="#">
<img src="http://fakeimg.pl/500x330/ccc/">
<div class="caption">Project untitled<br> Category</div>
</a>
</div>
</div>
<div class="col-4">
<div class="img-wrapper"> <a class="thumb" href="#">
<img src="http://fakeimg.pl/500x330/ccc/">
<div class="caption">Project untitled<br> Category</div>
</a>
</div>
</div>
<div class="col-4">
<div class="img-wrapper"> <a class="thumb" href="#">
<img src="http://upload.wikimedia.org/wikipedia/commons/f/f5/Poster-sized_portrait_of_Barack_Obama.jpg">
<div class="caption">Project untitled<br> Category</div>
</a>
</div>
</div>
<div class="col-4">
<div class="img-wrapper"> <a class="thumb" href="#">
<img src="http://fakeimg.pl/500x330/ccc/">
<div class="caption">Project untitled<br> Category</div>
</a>
</div>
</div>
<div class="col-4">
<div class="img-wrapper"> <a class="thumb" href="#">
<img src="http://fakeimg.pl/500x330/ccc/">
<div class="caption">Project untitled<br> Category</div>
</a>
</div>
</div>
</div>
.col-4 {
position: relative;
float: left;
display: inline-block;
}
.col-4:after {
padding-top: 63%;
display: block;
content:'';
}
.img-wrapper {
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
/*fill parent*/
}
.img-wrapper .thumb {
height:100%;
.img-project img, .thumb img {
position:relative;
top:50%;
left:50%;
max-width:100%;
max-height:100%;
-webkit-transform:translate(-50%,-50%);
-moz-transform:translate(-50%,-50%);
-ms-transform:translate(-50%,-50%);
-o-transform:translate(-50%,-50%);
transform: translate(-50%,-50%);
}
/************************************************
Site Name:
Author:
************************************************/
html {
margin: 0;
padding: 0;
}
body {
font-family: regular, helvetica, arial, sans-serif;
font-weight: normal;
font-size: 18px;
line-height: 1.4;
text-transform: none;
letter-spacing: 0;
color: #111;
overflow-y: scroll;
}
body, input, textarea, select, button {
text-rendering: optimizeLegibility;
-webkit-font-smoothing: subpixel-antialiased;
-moz-osx-font-smoothing: grayscale;
}
:hover {
-webkit-transition: all 0.3s;
-moz-transition: all 0.3s;
-ms-transition: all 0.3s;
-o-transition: all 0.3s;
transition: all 0.3s;
}
b, strong {
font-weight: normal;
}
a, a:visited {
color: #111;
text-decoration: underline;
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
-webkit-tap-highlight-color: transparent;
}
h1, nav {
font-size: 27px;
font-weight: normal;
text-transform: uppercase;
text-decoration: none;
letter-spacing: 2px;
background-color: transparent;
}
h1 {
margin: 0 0 26px 0;
}
p {
margin: 0 0 16px 0;
background-color: transparent;
}
p a:hover, a:focus, a:active {
color: #111;
text-decoration: none;
}
h1 a, a:visited {
color: #111;
text-decoration: none;
}
h1 a:hover, a:focus, a:active {
color: #111;
text-decoration: underline;
}
/************************************************
Thumbnails - Columns - Content
************************************************/
#container {
display: block;
margin: 98px 10px 100px 10px;
overflow: hidden;
background-color: transparent;
}
.col-4 {
position: relative;
float: left;
display: inline-block;
}
.col-4 {
width: 25%;
}
.col-4:after {
padding-top: 63%;
display: block;
content:'';
}
.img-wrapper {
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
/*fill parent*/
}
.img-wrapper .thumb {
height:100%;
}
.img-project, .thumb {
display: block;
padding: 10px;
}
.img-project img, .thumb img {
position:relative;
top:50%;
left:50%;
max-width:100%;
max-height:100%;
-webkit-transform:translate(-50%,-50%);
-moz-transform:translate(-50%,-50%);
-ms-transform:translate(-50%,-50%);
-o-transform:translate(-50%,-50%);
transform: translate(-50%,-50%);
}
.thumb:hover img {
opacity: 0.2;
}
.caption {
position: absolute;
opacity: 0;
width: 80%;
padding: 0;
top: 50%;
left: 50%;
text-align: center;
background-color: transparent;
-webkit-transform: translateX(-50%) translateY(-50%);
-moz-transform: translateX(-50%) translateY(-50%);
transform: translateX(-50%) translateY(-50%);
-webkit-transition: all 0.3s;
-moz-transition: all 0.3s;
-ms-transition: all 0.3s;
-o-transition: all 0.3s;
transition: all 0.3s;
}
.col-4 a:hover .caption {
opacity: 1;
}
/************************************************
Media queries
************************************************/
@media all and (max-width: 1024px) {
h1, nav {
font-size: 22px;
}
#container {
margin: 89px 7px 100px 7px;
}
.img-project, .thumb {
padding: 7px;
}
}
@media all and (min-width: 769px) {
nav ul {
display: block !important;
}
}
@media all and (max-width: 768px) {
body {
font-size: 16px;
}
.col-4 {
width: 33.33333%;
}
}
@media all and (max-width: 479px) {
.col-4 {
width: 50%;
}
}
我可能已将长宽比计算为1:0.63有点错误。您应该使用padding-top
元素的:after
来实现所需的比率
正如您所说的添加了填充 - Fiddle
我刚从.thumb
课程中删除了它,并将其添加到.img-wrapper
课程。