<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style type="text/css">
div {
width: 60%;
margin: 50px 20%;
}
* {
font-family: "Courier New", Courier, monospace;
}
div * {
width: 100%;
}
h1 {
text-align: center;
font-size: 48px;
padding: 0px;
margin: 0px;
}
p.grey {
color: grey;
text-align: center;
font-size: 24px;
padding: 0px;
margin: 0px;
}
p#ending {
text-align: center;
}
ul {
border-top: 3px solid black;
border-bottom: 2px solid grey;
margin-top: 20px;
padding-top: 10px;
padding-bottom: 10px;
}
li {
color: black;
font-size: 18px;
display: inline;
margin-left: 50px;
}
div#images {
border: 1px solid black;
}
div#images>img {
width: 30%;
-webkit-filter: grayscale(100%);
-moz-filter: grayscale(100%);
-ms-filter: grayscale(100%);
-o-filter: grayscale(100%);
filter: grayscale(100%);
filter: gray;
}
li:hover, li:active {
color: red;
}
</style>
</head>
<body>
<div>
<p class="grey">THE</p>
<h1>ANALOG</h1>
<p class="grey">SPECIALISTS</p>
<ul>
<li>HOME</li>
<li>FOR SALE</li>
<li>REPAIRES</li>
<li>ABOUT</li>
<li>CONTACT</li>
</ul>
<div id="images">
<img src="http://www.99-taobao.com/uploads/151109/1- 151109142014X3.jpg" alt="pic1">
<img src="http://www.99-taobao.com/uploads/151109/1-151109142014X3.jpg" alt="pic2">
<img src="http://www.99-taobao.com/uploads/151109/1-151109142014X3.jpg" alt="pic3">
</div>
<p id="ending">We specialise in the sales and repair of classic keyboards, in particular
the Fender Rhodes, Wurlitzer EP200, and Hohner Clavinet.</p>
</div>
</body>
</html>
我想這是一個愚蠢的問題,但我寫了這段html和css代碼,我想中心div#圖像,現在它不工作,但是如果我添加margin-left:5%到div#圖片,它將起作用。有誰知道爲什麼它是這樣的?爲什麼div沒有在其父母
結果看起來像this。
我添加了餘裕後,它運行得很好,如this。
嘗試:margin:0 auto;在#images css塊。你的所有div被強制爲60%的寬度。所以,你有一個智慧,你可以用這個塊來定位。 –