无法居中div容器 [英] Can't center a div container
本文介绍了无法居中div容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图以我的主容器为中心,但无论我做什么,它仍然浮动左边...
我将所有内容放入自己的Div中的原因是我使用了Jquery循环背景,并且我想将我的内容与我的背景分开。但正如前面提到的,我真的不能让我的Div容器中心......
我希望有人比我更熟练一点,可以弄清楚这一点!
I'm trying to center my main container, but whatever I do it still floats left... The reason I am placing all of my content in a own Div, is that i use a Jquery cycle background, and I want to separate my content from my background. But as mentioned I really cant make my Div container center... I hope someone a bit more skilled than me can figure this out!
这是我的html:
This is my 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:
and this is my 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;
}
推荐答案
/ p>
With this as your HTML
<div id="container">
<div id="header">
<img src="images/header.png">
</div>
容器的宽度为其父母的100%
The container will be 100% fo the width of it's parent
将标题居中
To center the header
#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;
}
这篇关于无法居中div容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文