我試圖做一個網站,一些div持有的圖像/文本,佈局看起來是這樣的:HTML和CSS DIV佈局
(我不能發佈超過2個鏈接,因此文字的例子。的div居中)
-
- -
- -
- -
當我使瀏覽器小的div應根據相互排隊,這樣的:
但我的代碼將是這樣的:
我已經試過各種事情,但他們沒有導致第一個div被在這兩種情況下完美的神韻:。
HTML源代碼:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<title>Sinterklaas website</title>
</head>
<body style="background-color:black">
<center><div class = "secondary"></div></center>
<center>
<div class="main">
<table border="0" cellpadding="0" cellspacing="0" width="100%" height="100%">
<tr>
<td colspan="2" height="180px">
<a href="http://www.google.nl">
<img style="display:block;" width="100%" height="100%" src="arduino.jpg" />
</a>
</td>
</tr>
<tr>
<td colspan="1" bgcolor="blue" width="220px"></td>
<td bgcolor="green"></td>
</tr>
</table>
</div>
<div class="main" id="second">
<table border="0" cellpadding="0" cellspacing="0" width="100%" height="100%">
<tr>
<td colspan="2" height="180px">
<a href="http://www.google.nl">
<img style="display:block;" width="100%" height="100%" src="arduino.jpg" />
</a>
</td>
</tr>
<tr>
<td colspan="1" bgcolor="blue" width="220px"></td>
<td bgcolor="green"></td>
</tr>
</table>
</div>
</center>
<center>
<div class="main"></div>
<div class="main"></div>
</center>
<center>
<div class="main"></div>
<div class="main"></div>
</center>
</body>
CSS來源:
body {
background-image: url("background.jpg");
background-repeat: no-repeat;
background-attachment: fixed;
background-position: center;
}
.main {
background-color: red;
display: inline-block;
position: relative;
width: 300px;
height: 225px;
margin: 15px;
}
.secondary {
background-color: red;
position: relative;
display: inline-block;
left: -165px;
width: 300px;
height: 70px;
margin: 0 auto;
}
.test {
background-color: red;
display: inline-block;
position: relative;
width: 300px;
height: 260px;
margin: 30px;
}
.empty {
position: relative;
display: inline-block;
background-color: red;
width: 300px;
height: 0px;
}
#first {
}
#second {
background-image: url("arduino.jpg");
background-size: 100% 100%;
}
#third {
}
#fourth {
}
#fifth {
}
#sixth {
}
任何幫助將真正理解!
'
[在div中水平居中div的可能副本](http://stackoverflow.com/ question/114543/horizontal-center-a-div-in-a-div) – TylerH
您的@media查詢在哪裏? –