css 居中 div 的问题
我试图在页面中将 div 居中,但我有一个非常特殊的布局,不允许我将其与常规边距居中:自动属性。我所拥有的是,基本上是这样的:
HTML:
<div id="container">
<div id="sidebar">
some text
</div>
</div id="content">
some text
</div>
</div>
CSS:
#container{
margin: 0 auto;
width: 900px;
}
#sidebar{
float: left;
width: 300px;
}
#content{
float: left;
width: 600px;
}
这使我的容器居中,没有任何问题,但我需要的是相对于屏幕宽度居中“内容”div,这是我正在开发的网站,所以你可以更清楚地看到它: http://dirtymind.jvsoftware.com/ 和我努力制作的图像为了更好地解释我的问题: http://dirtymind.jvsoftware.com/img/csserror.png
有谁知道如何做到这一点?预先感谢大家。
I'm trying to center a div in my page but I have a very particular layout that doesn't let me center it with regular margin: auto properties. What I have is, basically this:
HTML:
<div id="container">
<div id="sidebar">
some text
</div>
</div id="content">
some text
</div>
</div>
CSS:
#container{
margin: 0 auto;
width: 900px;
}
#sidebar{
float: left;
width: 300px;
}
#content{
float: left;
width: 600px;
}
This centers my container with no problems but what I need is to center the "content" div relative to the width of the screen, here's the site that I'm working on so you can see it more clearly: http://dirtymind.jvsoftware.com/ and an image I made in an effort to better explain my problem: http://dirtymind.jvsoftware.com/img/csserror.png
Does anyone know how to accomplish this? Thanks all in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将容器的宽度增加侧边栏的宽度,并为内容块添加相同数量的右边距。
Increase the width of the container by the width of the sidebar, and add a right margin to the content block by the same amount.
据我所知,这是不可能的。
我会在以下选项之间进行选择:
As far as I know that is not possible the way you want it to be.
I would choose between the following options: