2015-11-10 30 views
-1

我想在中心顯示我的頁面(寬度:80%auto;)我正在使用Center類,但它不工作。任何人都可以告訴我如何顯示我的頁面兩側保留20%的餘量。如何在中心顯示我的頁面,兩邊都有20%的邊距?

這裏是我的源代碼(HTML)

<html> 
<head> 
<link rel="stylesheet" href="mystyle.css"> 
<title>GR PROVIDER</title> 
</head> 
<body> 
<div class="wrapper"> 
<div class="center"> 
<div class="Header"> 
<div class="heading"> 
<h2> Gulf Resources Provider </h2> 
</div> 
<div class="socialmedia"> 
<ul> 
<li> <a href=""> <img src="GRProvider/Facebook.jpg"> </a> </li> 
<li> <a href=""> <img src="GRProvider/LinkedIn.jpg"></a> </li> 
<li> <a href=""> <img src="GRProvider/Google.jpg"> </a> </li> 
<li> <a href=""> <img src="GRProvider/Twitter.jpg"> </a> </li> 
</ul> 
</div> 
</div> 

<div class="images"> 
<div class="pics"> 
<img src="GRProvider/Img.jpg" /> 
</div> 
<div class="pics"> 
<img src="GRProvider/Img_2.jpg"/> 
</div> 
</div> 

<div class="diagram"> 
<div class="sample"> 
<img src="GRProvider/Img_3.jpg"/> 
</div> 
<div class="sample"> 
<img src="GRProvider/Img_4.jpg"/> 
</div> 
</div> 

<div class="main_content"> 
<div class="navigation"> 
<ul> 
<li> <a href="#"> HOME </a> </li> 
<li> <a href="#"> ABOUT US </a> </li> 
<li> <a href="#"> CAREER </a> </li> 
<li> <a href="#"> CONTACT US </a> </li> 
</ul> 
</div> 
<div class="Slider"> 
<div class="slider_img"> 
<img src="GRProvider/Slider.jpg"> 
</div> 
</div> 
</div> 

<div class="Info"> 
<div class="About_Us"> 
<p> Lorem Ipsum is simply dummy text of the printing and typesetting indutry. Lorem Ipsum has been 
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has 
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has bee 
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has bee 
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been 
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has Lorem Ipsum is simply dummytextoftheprintingandtypesettingindustry.LoremIpsum............. </p> 
</div> 
<div class="button"> 
<button type="button"> READ MORE </button> 
</div> 
</div> 

<div class="content"> 
<div class="text"> 
<img src="GRProvider/Img_4.jpg" /> 
<h4> PRODUCT INFORMATION </h4> 
<h5> consectetur adipiscing elit. Etiam tristique tristique any 
varius. Donec nec vestibulum ligula. Aenean turpis do 
feugiat a luctus in, rhoncus risus. Maecenas dui\vitae 
consequat massa imperdietut. elit ut tempus lobortis, 
eros leo molestie velit, nonegestas augue nulla </h5> 
</div> 
<div class="text"> 
<img src="GRProvider/Img_5.jpg" /> 
<h4> PRODUCT INFORMATION </h4> 
<h5> consectetur adipiscing elit. Etiam tristique tristique any 
varius. Donec nec vestibulum ligula. Aenean turpis do 
feugiat a luctus in, rhoncus risus. Maecenas dui\vitae 
consequat massa imperdietut. elit ut tempus lobortis, 
eros leo molestie velit, nonegestas augue nulla </h5> 
</div> 
<div class="text"> 
<img src="GRProvider/Img_6.jpg" /> 
<h4> PRODUCT INFORMATION </h4> 
<h5> consectetur adipiscing elit. Etiam tristique tristique any 
varius. Donec nec vestibulum ligula. Aenean turpis do 
feugiat a luctus in, rhoncus risus. Maecenas dui\vitae 
consequat massa imperdietut. elit ut tempus lobortis, 
eros leo molestie velit, nonegestas augue nulla </h5> 
</div> 
</div> 
<div class="footer"> 
<h6> Copyright by Bitsprovider.com </h6> 
</div> 
</div> 
</div> 
</body> 
</html> 

這裏是我的CSS代碼(mystyle.css)

* { 
    margin: 0; 
    padding: 0; 
} 
body { 
    background-color: #1e93a5; 
    width: 80% auto; 
} 
.wrapper { 
    float: left; 
    width: 100%; 
} 
.center { 
    float: left; 
    width: 80% auto; 
} 
.header { 
    float: left; 
    width: 100%; 
} 
.heading { 
    float: left; 
    width: 70%; 
} 
h2 { 
    color: #fff; 
    padding: 0 25%; 
} 
.socialmedia { 
    float: left; 
    width: 30%; 
} 
.images { 
    display: inline-block; 
    float: left; 
    width: 18%; 
} 
.pics img { 
    display: inline-block; 
    width: 100%; 
} 
.diagram { 
    display: inline-block; 
    float: right; 
    width: 18%; 
} 
.sample img { 
    width: 100%; 
} 
.main_content { 
    float: left; 
    position: static; 
    width: 60%; 
} 
.navigation { 
    float: left; 
    width: 100%; 
} 
.navigation > ul { 
    float: left; 
    width: 100%; 
} 
.navigation > ul li { 
    float: left; 
    list-style: outside none none; 
    text-decoration: none; 
    width: 25%; 
} 
.navigation > ul li a { 
    background-color: #2dacbe; 
    color: black; 
    float: left; 
    text-align: center; 
    text-decoration: none; 
    width: 100%; 
} 
.slider { 
    float: left; 
    width: 1%; 
} 
.slider > img { 
    width: 139%; 
} 
ul { 
    float: left; 
    width: 100%; 
} 
li { 
    float: left; 
    list-style: outside none none; 
    text-decoration: none; 
    width: 11%; 
} 
a { 
    border: 1px solid #0e8393; 
    color: black; 
    float: left; 
    text-align: center; 
    text-decoration: none; 
    width: 100%; 
} 
.info { 
    float: left; 
    width: 100%; 
} 
.About_Us { 
    float: left; 
    width: 100%; 
} 
p { 
    background-color: #2ea4b6; 
    color: #fff; 
    float: left; 
    text-align: justify; 
    width: 100%; 
} 
.button { 
    float: right; 
} 
.content { 
    float: left; 
    width: 100%; 
} 
.text { 
    float: left; 
    width: 33%; 
} 
.text > img { 
} 
h4 { 
    background-color: #263270; 
    color: #fff; 
    width: 93%; 
} 
h5 { 
    color: #fff; 
    width: 100%; 
} 
.footer { 
    float: left; 
    width: 100%; 
} 
h6 { 
    color: #fff; 
    text-align: center; 
} 
+0

1它應該是'margin:auto',而不是'width'和2個元素左移,所以它們不會顯示居中。 –

+1

[需要幫助在頁面上集中div類的可能的重複](http://stackoverflow.com/questions/29881384/need-help-centering-a-div-class-on-page) – Mogsdad

+0

20%的餘量每一方也意味着你的內容只能是60%而不是80% –

回答

0

使用margin: autowidth: 80% auto你想的不居中你的容器。同樣你的wrapper類似乎對我來說毫無用處。你不需要所有那些float: left s。

+0

它不工作..任何人都可以建議我任何其他答案。 –

+0

那麼用什麼來替代那些float:left。 –

+0

任何人都可以告訴我更多相關的答案....在此先感謝 –

1

1 - 刪除所有的float:left;。 2 - 刪除您DIV包裝器 3 - 把你的內容的80%的寬度和使用margin: 0 auto;

+0

謝謝Ichabrand。這個對我有用。 –

1

刪除不必要的div,你只需要兩到實現你在做什麼。 避免使用body進行佈局,因爲使用它可能會犯很多不必要的錯誤。

在下面的CSS代碼中,body只設置背景顏色,wrapper漂浮在中間,兩邊都有20%的邊距,你可以隨意使用標頭。

請不要使用float,直到找到真正需要使用它爲止。閱讀w3schools優秀的CSS教程。 http://www.w3schools.com/css/

body { 
    background-color: #1e93a5; 
    } 

    .wrapper { 
    width: 60%; 
    margin: 0 auto; // Shortcode for Margin: 0 (top), auto (right), 0 (bottom), auto (left) 
    } 

    .header { 
    width: 100%; 
    } 
0

對於div來中心本身在頁面上使用的CSS

保證金左:自動; margin-right:auto;

刪除其他不必要的東西,你不需要它們。讓我知道它是否有效。