中心div [英] Center div

查看:79
本文介绍了中心div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


我有两个div':


< div class =" container">

< div class =" message"> message< / div>

< / div>


我需要将div消息置于中心在div容器里面。

但我也想要div消息在它周围有一个20px的恒定余量




我该怎么做?

我试过以下CSS但是它不起作用:


..container

{

border:solid 1px red;

text-align:center;

}


..message

{

border:实心1px蓝色;

清除:两者;

保证金:20px auto;

text-align:left;

宽度:100%;

}


谢谢,

Miguel

Hello,

I have two div''s:

<div class="container">
<div class="message">message</div>
</div>

I need to center the div "message" inside the div "container".
But I also want the div "message" to have a constant margin of 20px
around it.

How can I do this?
I tried the following CSS but it is not working:

..container
{
border: solid 1px red;
text-align: center;
}

..message
{
border: solid 1px blue;
clear: both;
margin: 20px auto;
text-align: left;
width: 100%;
}

Thanks,
Miguel

推荐答案

文章

< 11 ********************** @ i56g2000hsf .googlegroups .com>,

" shapper" < md ***** @ gmail.comwrote:
In article
<11**********************@i56g2000hsf.googlegroups .com>,
"shapper" <md*****@gmail.comwrote:

您好,


我有两个div'' :


< div class =" container">

< div class =" message"> message< / div>

< / div>


我需要将div消息置于中心位置在div容器里面。

但我也想要div消息周围有20px / b $ b的恒定保证金。


我该怎么做?
Hello,

I have two div''s:

<div class="container">
<div class="message">message</div>
</div>

I need to center the div "message" inside the div "container".
But I also want the div "message" to have a constant margin of 20px
around it.

How can I do this?



您是否尝试过:


..container {


border:固体1px红色;

text-align:center;

}


..message {

border:solid 1px blue;

margin:20px;

}


-

dorayme


Have you tried:

..container {

border: solid 1px red;
text-align: center;
}

..message {

border: solid 1px blue;
margin: 20px;
}

--
dorayme


是的,


在Firefox和Opera中,消息div从容器外部移到

正确,在IE中,容器比定义的宽度大。


有什么想法吗?


谢谢,
Miguel


dorayme写道:
Yes,

In Firefox and Opera the message div gets outside the container to the
right and in IE the container gets bigger then the defined width.

Any idea?

Thanks,
Miguel

dorayme wrote:

文章

< 11 ***********************网站www.ba>,
< md ***** @ gmail.comwrote:
In article
<11**********************@i56g2000hsf.googlegroups .com>,
"shapper" <md*****@gmail.comwrote:

您好,


我有两个div'' :


< div class =" container">

< div class =" message"> message< / div>

< / div>


我需要将div消息置于中心位置在div容器里面。

但我也想要div消息周围有20px / b $ b的恒定保证金。


我该怎么做?
Hello,

I have two div''s:

<div class="container">
<div class="message">message</div>
</div>

I need to center the div "message" inside the div "container".
But I also want the div "message" to have a constant margin of 20px
around it.

How can I do this?




你试过吗:


.container {


边框:实心1px红色;

text-align:center;

}


.message {


border:solid 1px blue;

margin:20px;

}


-

dorayme



Have you tried:

.container {

border: solid 1px red;
text-align: center;
}

.message {

border: solid 1px blue;
margin: 20px;
}

--
dorayme


文章

< 11 *********** **********@k58g2000hse.googlegroups。 com>,

" shapper" < md ***** @ gmail.comwrote:

In article
<11*********************@k58g2000hse.googlegroups. com>,
"shapper" <md*****@gmail.comwrote:


>

dorayme写道:
>
dorayme wrote:

文章

< 11 ********************** @ i56g2000hsf。 googlegroups .com>,

" shapper" < md ***** @ gmail.comwrote:
In article
<11**********************@i56g2000hsf.googlegroups .com>,
"shapper" <md*****@gmail.comwrote:

你好,

>

我有两个div':

>

< div class =" container">

< div class =" ; message"> message< / div>

< / div>

>

我需要将div消息置于中心位置;在div容器里面。

但我也想要div消息在它周围有一个20px的恒定保证金



>

我该怎么做?
Hello,
>
I have two div''s:
>
<div class="container">
<div class="message">message</div>
</div>
>
I need to center the div "message" inside the div "container".
But I also want the div "message" to have a constant margin of 20px
around it.
>
How can I do this?



你试过吗:


.container {


border:solid 1px红色;

text-align:center;

}


.message {


border:solid 1px blue;

margin:20px;

}


Have you tried:

.container {

border: solid 1px red;
text-align: center;
}

.message {

border: solid 1px blue;
margin: 20px;
}


是的,


在Firefox和Opera中,消息div从容器外部移到

右边,在IE中,容器变得大于定义的容器宽度。


有什么想法吗?
Yes,

In Firefox and Opera the message div gets outside the container to the
right and in IE the container gets bigger then the defined width.

Any idea?



最好不要发布帖子,修复此处。你试过了吗?你带了

你的汽车?你用过我的代码?在FF中它有你提到的缺点

?你能否发一个显示这个的网址。


-

dorayme

Best not to top post, fixed here. You tried it exactly? you took
out your auto? and you used my code? And in FF it had the faults
you mention? Can you please post a URL showing this.

--
dorayme


这篇关于中心div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆