[英]How to make a DIV centered and has almost a 100% width and a 100% height
[英]Trying to make a div background image 100% height of window and div centered
我正在嘗試制作一個頁面,該頁面填充iPad上的屏幕,並在iPhone上具有2個黑邊,因為縱橫比不同。
背景圖像需要保持固定的形狀,而不是拉伸的。
我設法使div背景,正確的大小和形狀正確,但是我無法將其居中。 有人可以幫忙嗎? http://www.simonpetermedia.com/Aboutpage/about.html
html{
height:100%;
}
body {
font: 100% Verdana, Arial, Helvetica, sans-serif;
height: 100%;
background: #000000;
margin: 0;
padding: 0;
text-align: center;
color: #000000;
}
.oneColElsCtr #container {
position:fixed !important;
top:0;
right:0;
left:0;
bottom:0;
margin-right: auto;
margin-left: auto;
height: 100%;
background-image: url("aboutbg.jpg");
background-size: auto 100%;
background-repeat: no-repeat;
margin: 0 auto;
border: 0px solid #000000;
text-align: left;
min-height: 100%;
}
.oneColElsCtr #mainContent {
padding: 0px;
}
-->
</style></head>
<body class="oneColElsCtr">
<div id="container">
<div id="mainContent">
<h1> </h1>
<!-- end #mainContent --></div>
</div>
</body>
background-size:cover;
編輯為
background-size:contain; background-position:center;backround-color:#E2AA7B;
將此添加到#container
css
background-position: center center;
我已經在Google Chrome瀏覽器上打開了您的頁面,並打開了元素檢查器。 在您的“容器” div處,放置一個“ background-position:center;”。 使它水平粘貼到中心。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.