我正尝试以下列方式定位图像,从从左到右,并将其保持在屏幕中央:
但是,我不能这样做而不是最后一个图像总是出现在行的中心,如下图所示:
有没有办法能够像这样显示它,还能将它保存在屏幕的 CENTER 中?
我在 #gallery>中使用 display:inline-block 格
代码:https://jsfiddle.net/m9xuj8aa/
HTML:
<div class="container">
<header>
<div id="logo">
<img src="" alt="">
</div>
<nav class="cl-effect-21">
<ul>
<li>
<a href="index.html" class="scroll">
<span data-hover="Home">Home</span>
</a>
</li>
<li>
<a href="#about" class="scroll">
<span data-hover="About Us">About Us</span>
</a>
</li>
<li>
<a href="#services" class="scroll">
<span data-hover="Services">Services</span>
</a>
</li>
<li>
<a href="Portfolio.html" class="scroll">
<span data-hover="Portfolio">Portfolio</span>
</a>
</li>
<li>
<a href="#testimonials" class="scroll">
<span data-hover="Testimonials">Testimonials</span>
</a>
</li>
<li>
<a href="Contact.html" class="scroll active">
<span data-hover="Contact Us">Contact Us</span>
</a>
</li>
</ul>
</nav>
</header>
<div class="portfolio clearfix">
<div id="gallery">
<div id="img-wrapper">
<a href="assets/images/DesiGotTalent3/1.jpg">
<img src="assets/images/DesiGotTalent3/1.jpg" alt="">
<div id="overlay">
<h1 class="fa fa-search"></h1>
</div>
</a>
</div>
<div id="img-wrapper">
<a href="assets/images/DesiGotTalent3/2.jpg">
<img src="assets/images/DesiGotTalent3/2.jpg" alt="">
<div id="overlay">
<h1 class="fa fa-search"></h1>
</div>
</a>
</div>
<div id="img-wrapper">
<a href="assets/images/DesiGotTalent3/3.jpg">
<img src="assets/images/DesiGotTalent3/3.jpg" alt="">
<div id="overlay">
<h1 class="fa fa-search"></h1>
</div>
</a>
</div>
<div id="img-wrapper">
<a href="assets/images/DesiGotTalent3/4.jpg">
<img src="assets/images/DesiGotTalent3/4.jpg" alt="">
<div id="overlay">
<h1 class="fa fa-search"></h1>
</div>
</a>
</div>
<div id="img-wrapper">
<a href="assets/images/DesiGotTalent3/5.jpg">
<img src="assets/images/DesiGotTalent3/5.jpg" alt="">
<div id="overlay">
<h1 class="fa fa-search"></h1>
</div>
</a>
</div>
<div id="img-wrapper">
<a href="assets/images/DesiGotTalent3/6.jpg">
<img src="assets/images/DesiGotTalent3/6.jpg" alt="">
<div id="overlay">
<h1 class="fa fa-search"></h1>
</div>
</a>
</div>
<div id="img-wrapper">
<a href="assets/images/DesiGotTalent3/7.jpg">
<img src="assets/images/DesiGotTalent3/7.jpg" alt="">
<div id="overlay">
<h1 class="fa fa-search"></h1>
</div>
</a>
</div>
<div id="img-wrapper">
<a href="assets/images/DesiGotTalent3/8.jpg">
<img src="assets/images/DesiGotTalent3/8.jpg" alt="">
<div id="overlay">
<h1 class="fa fa-search"></h1>
</div>
</a>
</div>
<div id="img-wrapper" class="last">
<a href="assets/images/DesiGotTalent3/9.jpg">
<img src="assets/images/DesiGotTalent3/9.jpg" alt="">
<div id="overlay">
<h1 class="fa fa-search"></h1>
</div>
</a>
</div>
</div>
</div>
<div class="push"></div>
</div>
<footer>
<div id="social">
<span class="fa fa-facebook"></span>
<span class="fa fa-instagram"></span>
<span class="fa fa-vimeo"></span>
<span class="fa fa-youtube"></span>
</div>
<h3>© 2016 Dinesh Joshi Photography</h3>
</footer>
CSS:
/** External Stylesheet **/
* { margin: 0; }
html, body { height: 100%; }
.container {
min-height: 100%;
margin: 0 auto -60px;
}
footer, .push {
height: 20px;
padding: 20px 0px;
}
footer {
font-size: 10px;
text-align: center;
}
#social {
margin-bottom: 5px;
}
#social span {
border: 1px solid rgba(0,0,0,.2);
margin: 0px 3px;
font-size: 1.6em;
width: 1.6em;
text-align: center;
line-height: 1.6em;
background: #D4AF37;
color: white;
border-radius: 50%;
}
/** Header **/
header {
padding-top: 30px;
}
ul {
text-align: center;
}
ul li {
display: inline-block;
font-family: 'Roboto', sans-serif;
text-transform: uppercase;
font-size: 12px;
letter-spacing: 1px;
margin: 0px 8px;
}
nav a {
position: relative;
display: inline-block;
outline: none;
color: black;
text-decoration: none;
text-transform: uppercase;
letter-spacing: 1px;
font-weight: 400;
text-shadow: 0 0 1px rgba(255,255,255,0.3);
font-size: 12px;
font-family: 'Roboto', sans-serif;
}
nav a:hover,
nav a:focus {
outline: none;
}
/* Effect 21: borders slight translate */
.cl-effect-21 a {
padding: 10px;
color: black;
font-weight: 400;
text-shadow: none;
-webkit-transition: color 0.3s;
-moz-transition: color 0.3s;
transition: color 0.3s;
}
.cl-effect-21 a::before,
.cl-effect-21 a::after {
position: absolute;
left: 0;
width: 100%;
height: 1.2px;
background: #D4AF37;
content: '';
opacity: 0;
-webkit-transition: opacity 0.3s, -webkit-transform 0.3s;
-moz-transition: opacity 0.3s, -moz-transform 0.3s;
transition: opacity 0.3s, transform 0.3s;
-webkit-transform: translateY(-10px);
-moz-transform: translateY(-10px);
transform: translateY(-10px);
}
.active {
border-top: 1.2px solid #D4A347;
border-bottom: 1.2px solid #D4A347;
}
.cl-effect-21 a::before {
top: 0;
-webkit-transform: translateY(-10px);
-moz-transform: translateY(-10px);
transform: translateY(-10px);
}
.cl-effect-21 a::after {
bottom: 0;
-webkit-transform: translateY(10px);
-moz-transform: translateY(10px);
transform: translateY(10px);
}
.cl-effect-21 a:hover::before,
.cl-effect-21 a:focus::before,
.cl-effect-21 a:hover::after,
.cl-effect-21 a:focus::after {
opacity: 1;
-webkit-transform: translateY(0px);
-moz-transform: translateY(0px);
transform: translateY(0px);
}
/* End of external stylesheet */
.portfolio {
width: 100%;
margin:0 auto;
}
#gallery {
width: 100%;
margin:0 auto;
padding: 0px 10px;
display: table;
text-align: center;
}
#gallery img {
width: 100%;
height: auto;
}
#gallery > div {
width: 150px;
height: 140px;
display:inline-block;
vertical-align:top;
background-color:black;
margin: 5px;
}
#gallery a div {
position:absolute;
width: 150px;
margin:0 auto;
text-align: center;
top: 0;
right:0;
left:0;
bottom:0;
z-index: 1;
transform: translate(-110%, 0);
-webkit-transition: all .3s ease-in-out;
display:none;
}
#gallery a:hover #overlay {
background-color:rgba(212, 175, 55, .3);
transform: translate(0,0);
}
#gallery div:nth-of-type(9) {
text-align: left;
}
#gallery h1 {
font-size: 20px;
color:white;
margin:3.6em 0px;
}
.clearfix {
clear: both;
}
答案 0 :(得分:0)
你可以将整个4个图像放在一个容器中,然后在那个容器中你可以用相互间的一定像素来初始化照片,然后它应该完成!
答案 1 :(得分:0)
您可以使用flexbox更新fiddle我删除了在display flex中添加的#gallery上的显示表(默认为行)并添加了一个
#gallery {
display: flex;
flex-wrap: wrap;
width: 100%;
margin:0 auto;
padding: 0px 10px;
text-align: center;
}
修改#1 强>
我已经更新了小提琴链接,这有点肮脏,但希望它会引发一些想法。唯一需要注意的是,如果您正在寻找响应式设计,则必须在窗口调整大小时执行逻辑。这就是为什么我不认为这是一个完美的解决方案。
答案 2 :(得分:0)
我明白了。看起来图像尺寸不同,因此不能正确地从左向右浮动。
通过向图像添加显式高度来修复