简体   繁体   English

如何将div的左侧与页面中心对齐?

[英]How would you align the left side of a div to the center of the page?

I have a stack of divs down the center of the page (using margin:auto) 我在页面中心有一堆div(使用margin:auto)

now I want to draw a line starting at the center and extending to the right (say 400 pixels). 现在我想绘制一条从中心开始并向右延伸的线(比如400像素)。 I'm a but stumped, any idea how to make this work nicely? 我是一个但很难过,知道如何使这项工作很好吗?

cheers! 干杯!

Use this css: 使用此css:

div.line
{
    position: absolute;
    left: 50%;
    width: 50%;
}
div.line
{
  width: 400px;
  height: 10px;
  margin: 0 auto;
  border-right: 400px solid black;
}

Put the content inside another tag. 将内容放在另一个标记内。

And style the tag as following(for example a div): 并将标记设置为以下样式(例如div):

div.special_tag {
  float: right;
  width: 50%;
}

Personally, I'd just use margins: 就个人而言,我只是使用边距:

Set to the left of the midline: 设置在中线的左侧:

.leftSide {
 width: 400px;
 height: 100px;
 margin: 0 50% 0 auto;
 background: #555;
 border: #777 1px solid;
}

or right side of midline 或中线的右侧

.rightSide {
 width: 400px;
 height: 100px;
 margin: 0 auto 0 50%;
 background: #555;
 border: #777 1px solid;
}

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

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