我已經看到其他人問過同一個問題,但該解決方案不適用於此問題。該解決方案應該最好適用於不同的設備,例如iPhone,iPad等等,所以通用解決方案更可取 - 而不是隻適用於一臺設備。 我試圖設置text-align:center
,並試圖設置margin-left:auto
和margin-right:auto
,但它不起作用。如何將圖像連成一排
HTML(僅相關的代碼包括):
<div class="container">
<div class="buttonyear"> <a href="en131.html"><img class="buttonyear" src="./navi/yearen.png" /><span>2014</span></a></div>
<div class="buttonyear"> <a href="en131.html"><img class="buttonyear" src="./navi/yearen.png" /><span>2013</span></a></div>
<div class="buttonyear clearfix"> <a href="en131.html"><img class="buttonyear" src="./navi/yearen.png" /><span>2012</span></a></div>
<br/>
<br/>
</div> <!-- end of navi -->
的CSS:
.container {
max-width: 48rem;
width: 90%;
display: table-cell;
text-align: center;
vertical-align: middle;
}
body{
background-image: url(../images/gradient.jpg);
}
// todo improve css..ask on stackoverflow..
.navi {
width:100%;
text-align:center;
text-align: center;
margin-left: 42%;
margin-right: 42%;
}
.buttonyear
{
float: left;
}
.buttonyear a
{
text-decoration: none;
}
.logocontainer {
text-align:center;
}
.logo {
width:180px;
height:60px;
}
*, *:before, *:after {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
/* Small screens (default) */
html { font-size: 100%; }
/* Medium screens (640px) */
@media (min-width: 40rem) {
html { font-size: 112%; }
}
/* Large screens (1024px) */
@media (min-width: 64rem) {
html { font-size: 120%; }
}
ul {
list-style-type:none;
}
.buttonyear {
position: relative;
width: 42px;
height: 20px;
}
.buttonyear span {
left: 0;
position:absolute;
width: 100%;
color: white;
font: 12px Gill Sans;
font-weight:600;
text-decoration:none;
text-align:center;
width:42px;
height:20px;
padding-top:2px;
position:absolute;
}
.clearfix:after {
content: ".";
display: block;
clear: both;
visibility: hidden;
line-height: 0;
height: 0;
}
.clearfix {
display: inline-block;
}
html[xmlns] .clearfix {
display: block;
}
* html .clearfix {
height: 1%;
}
小提琴:http://jsfiddle.net/wzhwtvmt/
可以添加一個小提琴請 – 2014-10-03 16:55:52
http://jsfiddle.net/wzhwtvmt/ – 2014-10-03 16:57:42
您使用的是你的CSS .navi類,但在HTML中是不存在的。你想要集中.container嗎? – dippas 2014-10-03 16:59:43