我正试图将我的主容器放在中心位置,但无论我做什么,它仍会漂浮在左边...... 我将所有内容放在自己的Div中的原因是我使用Jquery循环背景,我想将我的内容与我的背景分开。但如上所述,我真的不能让我的Div集装箱中心...... 我希望比我更熟练的人可以解决这个问题!
这是我的HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Forside</title>
<link rel="stylesheet" type="text/css" media="screen" href="style.css" />
<script type="text/javascript" src="http://code.jquery.com/jquery- 1.6.3.min.js"></script> <script type="text/javascript" src="jquery.cycle.all.js"></script>
<script>
$(document).ready(function() {
$('#slideshow').cycle({
fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
pager: '#smallnav',
pause: 1,
speed: 1800,
timeout: 3500
});
});
</script>
</head>
<body>
<div class="bx-overlay">
</div>
<div id="slideshow">
<img src="images/3.jpg" alt="san diego"/>
<img src="images/2.jpg" alt="bridge"/>
<img src="images/1.jpg" alt="mountains"/>
<img src="images/4.jpg" alt="waves"/>
<img src="images/5.jpg" alt="americanflag"/>
<img src="images/6.jpg" alt="football"/>
</div>
<div id="container">
<div id="header">
<img src="images/header.png">
</div>
</div>
</body>
</html>
这是我的css:
#slideshow, img.bgM {
min-height: 100%;
min-width: 1024px;
width: 100%;
height: auto;
position: fixed;
top: 0;
left: 0;
z-index:-9999;
}
.bx-overlay {
width: 100%;
height: 100%;
position: fixed;
top: 0px;
left: 0px;
background: transparent url(images/pattern.png) repeat top left;
z-index:-1;}
#container{
position: absolute;
text-align:center;
margin-left: auto;
margin-right: auto;
}
#header {
display: block;
margin-left: auto;
margin-right: auto;
position: absolute;
text-align:center;
margin:0 auto;
}
答案 0 :(得分:2)
将此作为您的HTML
<div id="container">
<div id="header">
<img src="images/header.png">
</div>
容器将是其父亲
的宽度的100%将标题居中
#header {
display: block; <-- not required as it's a div
margin-left: auto; <-- not required as it's a overridden by last margin property
margin-right: auto; <-- not required as it's a overridden by last margin property
position: absolute; <-- remove this
text-align:center; <-- only required if you are centering text
margin:0 auto; <-- this will center provided you add a width OR max-width
width: add a value;
}