English 中文(简体)
Center DIV 在一个DIV内部?
原标题:Center DIV Within a DIV?
  • 时间:2012-01-11 23:33:07
  •  标签:
  • css
  • html

I need help in centering one DIV withing a DIV.

我想有一辆汽车宽度的集装箱DIV,来接收整个屏幕宽度(称为其头盔)。

内部主管 集装箱,我想再增加三维:

  • A Left DIV (400px wide)
  • A Center DIV (100px wide)
  • A right DIV (200px wide).

我直接希望DIV在屏幕中间。 现在,我只能把它放在左边和右DIV之间。

Thanks for any help.

最佳回答

<>CSS:

.leftDiv{
  float: left;
  width: 400px;
}
.rightDiv{
  float: right;
  width: 200px;
}
.centerDiv{
  width: 100px;
  margin: 0 auto;
}

<>光>:

<div>
   <div class="leftDiv">left</div>
   <div class="rightDiv">right</div>
   <div class="centerDiv">center</div>
</div>

http://www.hchr.org。

守则:

全面筛选:

问题回答

这一工作。

。headerContainer{
  width:auto !important;
}
。leftDiv{
  float:left;
  width:400px;
}
。rightDiv{
  float:right;
  width:200px;
}
。centerDiv{
  display:inline;
  width:100px;
  margin-left:auto;
  margin-right:auto;
}

<div class="headerContainer">
 <div class="leftDiv"></div>
 <div class="centerDiv"></div>
 <div class="rightDiv"></div>
</div>

你们可以做的是,在使双方平等的情况下,再增加一个四分之三,并设定了<条码>可见性:隐蔽性;(而不是<条码>显示:无);这样,它就会成为中间四分之一。

例如,在本案件中,有1@400px, 另有1 @ 100px, 另有1 @ 200px, 隐藏,@ 200px。

Regards, Richard

由于flex ,你可以使用现代解决办法。 cs3的概念。

.parent {
  display: flex;
  height: 300px;
  /* Or whatever */
  background-color: green;
}
.child {
  width: 100px;
  /* Or whatever */
  height: 100px;
  /* Or whatever */
  margin: auto;
  /* Magic! */
  background-color: yellow;
}
<div class="parent">
  <div class="child ">Div1</div>
</div>




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签