我想知道如何让每张照片都集中在页面中间,并且每排在4行之下。任何帮助都将受到赞赏。谢谢你的时间。
我的编码可以在下面看到:
@import url(http://fonts.googleapis.com/css?family=Open+Sans:400,300);
body {
color: #333;
font-family: 'Open Sans', sans-serif;
font-weight: 300;
}
h1,
h1+p {
margin: 30px 15px 0;
font-weight: 300;
}
h1+p a {
color: #333;
}
h1+p a:hover {
text-decoration: none;
}
h2 {
margin: 60px 15px 0;
padding: 0;
font-weight: 300;
}
h2 span {
margin-left: 1em;
color: #aaa;
font-size: 85%;
}
.column {
margin: 15px 15px 0;
padding: 0;
}
.column:last-child {
padding-bottom: 60px;
}
.column::after {
content: '';
clear: both;
display: block;
}
.column div {
position: relative;
float: left;
width: 300px;
height: 200px;
margin: 0 0 0 25px;
padding: 0;
}
.column div:first-child {
margin-left: 0;
}
.column div span {
position: absolute;
bottom: -20px;
left: 0;
z-index: -1;
display: block;
width: 300px;
margin: 0;
padding: 0;
color: #444;
font-size: 18px;
text-decoration: none;
text-align: center;
-webkit-transition: .3s ease-in-out;
transition: .3s ease-in-out;
opacity: 0;
}
figure {
width: 300px;
height: 200px;
margin: 0;
padding: 0;
background: #fff;
overflow: hidden;
}
figure:hover+span {
bottom: -36px;
opacity: 1;
}
/* Opacity #1 */
.hover11 figure img {
opacity: 1;
-webkit-transition: .3s ease-in-out;
transition: .3s ease-in-out;
}
.hover11 figure:hover img {
opacity: .5;
}
<div class="container">
</br>
<span class="textformat1"><center><b>Gallery</b></span></center>
<center>
<div class="hover11 column">
<div>
<figure><a class="fancybox" href="images/img1fullsize.jpg"><img src="images/10647762_1068348719862622_2085603419_n.png" alt="10647762_1068348719862622_2085603419_n" width="300" height="200"></a></figure>
<span>Hover</span>
</div>
<div>
<figure><a class="fancybox" href="images/img2fullsize.jpg"><img src="images/12325991_1059629627401198_1870410396_o.jpg" alt="12325991_1059629627401198_1870410396_o" width="300" height="200"></a></figure>
</div>
<div>
<figure><a class="fancybox" href="images/img3fullsize.jpg"><img src="images/12381186_1068348869862607_2103570970_o.jpg" alt="12381186_1068348869862607_2103570970_o" width="300" height="200"></a></figure>
</div>
<div>
<figure><a class="fancybox" href="images/img4fullsize.jpg"><img src="images/1932078_1068348593195968_1861115484_n.jpg" alt="1932078_1068348593195968_1861115484_n" width="300" height="200"></a></figure>
</div>
<div>
<figure><a class="fancybox" href="images/img5fullsize.jpg"><img src="images/img5thumbnail.jpg" alt="img5thumbnail" width="300" height="200"></a></figure>
</div>
<div>
<figure><a class="fancybox" href="images/img6fullsize.jpg"><img src="images/12404434_1068348596529301_270753597_n.jpg" alt="12404434_1068348596529301_270753597_n" width="300" height="200"></a></figure>
</div>
<div>
<figure><a class="fancybox" href="images/img7fullsize.jpg"><img src="images/12404946_1068348673195960_1063608705_o.jpg" alt="12404946_1068348673195960_1063608705_o" width="300" height="200"></a></figure>
</div>
<div>
<figure><a class="fancybox" href="images/img8fullsize.jpg"><img src="images/12405008_1068348669862627_440250682_o.jpg" alt="12405008_1068348669862627_440250682_o" width="300" height="200"></a></figure>
</div>
<div>
<figure><a class="fancybox" href="images/img9fullsize.jpg"><img src="images/12413879_10683487763195950_1758712787_o.jpg" alt="12413879_10683487763195950_1758712787_o" width="300" height="200"></a></figure>
</div>
<div>
<figure><a class="fancybox" href="images/img10fullsize.jpg"><img src="images/12358479235.jpg" alt="12358479235" width="300" height="200"></a></figure>
</div>
<div>
<figure><a class="fancybox" href="images/img11fullsize.jpg"><img src="images/124522465_1068348823195945_750893117_o.jpg" alt="124522465_1068348823195945_750893117_o" width="300" height="200"></a></figure>
</div>
</div>
</center>
<br/>
答案 0 :(得分:0)
首先,删除<center></center>
标记,因为这些标记很快就会从HTML中删除/折旧。现在有一种现代的CSS方式,你应该使用它来集中内容。 <b>
标签也一样!如今,任何格式化都应该使用CSS完成,而不是使用&#34;旧样式&#34; font=""
或<center>
或<b>
或width=""
或height=""
等内容。你也不应该使用figure
。基本上......我猜你是从一本非常古老的书或者真正的旧教程中学习HTML的?这就是HTML在2001年左右的工作方式,但现在,它不再是它的编码方式了,而且它仍然有点&#34;工作的唯一原因&#34;是因为浏览器试图做兼容性&#34;当他们看到旧式HTML时的事情。由于折旧,它将来会停止工作。你能告诉我你想通过数字实现什么吗?我会为你重写CSS,而不使用这个数字。但无论如何......在你的情况下,为了使图像居中(并解决其他问题)我已经将你的代码重写为:
<强> HTML 强>
<div class="container">
<br>
<div class="textformat1 text_center">Gallery</div>
<div class="hover11 column">
<a class="fancybox" href="images/img1fullsize.jpg">
<img class="image_center figure" src="images/10647762_1068348719862622_2085603419_n.png" alt="10647762_1068348719862622_2085603419_n" ></a>
<span>Hover</span>
</div>
<div>
<a class="fancybox" href="images/img2fullsize.jpg">
<img class="image_center figure" src="images/12325991_1059629627401198_1870410396_o.jpg" alt="12325991_1059629627401198_1870410396_o">
</a>
</div>
<div>
<a class="fancybox" href="images/img3fullsize.jpg">
<img class="image_center figure" src="images/12381186_1068348869862607_2103570970_o.jpg" alt="12381186_1068348869862607_2103570970_o">
</a>
</div>
<div>
<a class="fancybox" href="images/img4fullsize.jpg">
<img class="image_center figure" src="images/1932078_1068348593195968_1861115484_n.jpg" alt="1932078_1068348593195968_1861115484_n">
</a>
</div>
<div>
<a class="fancybox" href="images/img5fullsize.jpg">
<img class="image_center figure" src="images/img5thumbnail.jpg" alt="img5thumbnail">
</a>
</div>
<div>
<a class="fancybox" href="images/img6fullsize.jpg">
<img class="image_center figure" src="images/12404434_1068348596529301_270753597_n.jpg" alt="12404434_1068348596529301_270753597_n">
</a>
</div>
<div>
<a class="fancybox" href="images/img7fullsize.jpg">
<img class="image_center figure" src="images/12404946_1068348673195960_1063608705_o.jpg" alt="12404946_1068348673195960_1063608705_o">
</a>
</div>
<div>
<a class="fancybox" href="images/img8fullsize.jpg">
<img class="image_center figure" src="images/12405008_1068348669862627_440250682_o.jpg" alt="12405008_1068348669862627_440250682_o">
</a>
</div>
<div>
<a class="fancybox" href="images/img9fullsize.jpg">
<img class="image_center figure" src="images/12413879_10683487763195950_1758712787_o.jpg" alt="12413879_10683487763195950_1758712787_o">
</a>
</div>
<div>
<a class="fancybox" href="images/img10fullsize.jpg">
<img class="image_center figure" src="images/12358479235.jpg" alt="12358479235">
</a>
</div>
<div>
<a class="fancybox" href="images/img11fullsize.jpg">
<img class="image_center figure" src="images/124522465_1068348823195945_750893117_o.jpg" alt="124522465_1068348823195945_750893117_o">
</a>
</div>
</div><!--//end container-->
<br>
<强> CSS 强>
.image_center {
display: block;
margin-left: auto;
margin-right: auto
}
.text_center {
text-align: center; }
.figure {
width: 300px;
height: 200px; }
.figure:hover+span {
bottom: -36px;
opacity: 1; }
/* Opacity #1 */
.hover11 figure img {
opacity: 1;
-webkit-transition: .3s ease-in-out;
transition: .3s ease-in-out;
}
.hover11 figure:hover img {
opacity: .5;
body {
color: #333;
font-family: 'Open Sans', sans-serif;
font-weight: 300;
}
h1,
h1+p {
margin: 30px 15px 0;
font-weight: 300;
}
h1+p a {
color: #333;
}
h1+p a:hover {
text-decoration: none;
}
h2 {
margin: 60px 15px 0;
padding: 0;
font-weight: 300;
}
h2 span {
margin-left: 1em;
color: #aaa;
font-size: 85%;
}
.column {
margin: 15px 15px 0;
padding: 0;
}
.column:last-child {
padding-bottom: 60px;
}
.column::after {
content: '';
clear: both;
display: block;
}
.column div {
position: relative;
float: left;
width: 300px;
height: 200px;
margin: 0 0 0 25px;
padding: 0;
}
.column div:first-child {
margin-left: 0;
}
.column div span {
position: absolute;
bottom: -20px;
left: 0;
z-index: -1;
display: block;
width: 300px;
margin: 0;
padding: 0;
color: #444;
font-size: 18px;
text-decoration: none;
text-align: center;
-webkit-transition: .3s ease-in-out;
transition: .3s ease-in-out;
opacity: 0;
}