1

我正在尝试将我的主容器居中,但无论我做什么,它仍然会向左浮动......我将所有内容放在自己的 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;
}
4

1 回答 1

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;
}
于 2013-09-26T15:27:19.113 回答