简体   繁体   English

我如何左对齐div

[英]How do I left align a div

I would like some help with left aligning the content on the site I am working on. 我需要一些帮助,以使我正在工作的网站上的内容左对齐。 I have a menu on the left hand side and I need a content div to site adjacent to this menu. 我在左侧有一个菜单,并且需要一个内容div才能与该菜单相邻。

In my CSS I currently have the following: 在我的CSS中,我目前有以下内容:

#pageContent_wrapper {
    width:100%;

}
#container {
    width:940px;
    height:100%;
    margin: 0 auto;
}

.page-content {
    float:left;
    padding: 30px 0;
}

The HTML Looks like this: HTML看起来像这样:

<div id="pageContent_wrapper">
    <div id="container">
       <div class="page-content">
          <p>Content goes Here</p>
       </div>
    </div>
</div>

This doesn't work though. 但是,这不起作用。 Essentially I am trying to left align a div with the main content in it. 本质上,我试图使div与其中的主要内容对齐。

Remove margin: 0 auto; 删除margin: 0 auto; from the #container . 来自#container
You also don't need float: left in the .page-content . 您也不需要float: left.page-content
Whole CSS should look like this: 整个CSS应该如下所示:

#pageContent_wrapper {
    width:100%;
}
#container {
    width:940px;
    height:100%;
}

.page-content {
    padding: 30px 0;
}

add in you css 加入你的CSS

 text-align:left

And remove 并删除

margin: 0 auto;

waiting for your replay.... 等待您的重播...

Thanks @matewka you are quite right adding position absolute to the container is not a good idea I have had a couple of people say the same thing. 谢谢@matewka,您完全正确地在容器中添加绝对位置不是一个好主意,我有几个人说过同样的话。 So instead what I have done is added a float:left to the container with padding-left:270px which works perfectly! 因此,相反,我所做的是向padding-left:270px的容器中添加了一个float:left ,效果很好! Because it means no matter what the content within my container it will always sit that many pixels away from the menu on the left and the content is left aligned with the float. 因为这意味着无论容器中的内容是什么,它始终与左侧菜单相距许多像素,并且内容与浮动对象保持对齐。

I don't think I explained exactly what the problem was when I wrote my question. 我认为我写问题时并没有确切说明问题所在。 Thank you for your help though. 谢谢您的帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM