设置div宽度,对齐div中心和文本左对齐 [英] Set a div width, align div center and text align left
问题描述
我有一个小问题,但我不能得到解决。
我有一个864px宽的内容标题,背景图像重复y和页脚图像。
现在我有这个< div>
在背景图像,我想它像855px宽度和文本左对齐但对齐中心,因此它适合在bg。
I have a small problem but I can't get it solved.
I have a content header of 864px width, a background image repeated-y and footer image.
Now I have this <div>
over the background image and I want it to be like 855px width and the text align left but yet aligned center so it fits in the bg.
我曾经有一些宽度一些填充,但我发现这是我的屏幕分辨率的正确填充。
I once had it oke width some padding left but I figured out that was the correct padding for my screen resolution.
简单来说就是:
设置div宽度 - 对齐div中心 - 对齐其文本(内容)。
Soo briefly it is: Setting a div width - align the div center - align its text (content) left.
推荐答案
在内部div上设置自动边距:
Set auto margins on the inner div:
<div id="header" style="width:864px;">
<div id="centered" style="margin: 0 auto; width:855px;"></div>
</div>
或者,文本对齐父对象中心,并强制文本在内部div上左对齐:
Alternatively, text align center the parent, and force text align left on the inner div:
<div id="header" style="width:864px;text-align: center;">
<div id="centered" style="text-align: left; width:855px;"></div>
</div>
这篇关于设置div宽度,对齐div中心和文本左对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!