设置div宽度,对齐div中心和文本左对齐 [英] Set a div width, align div center and text align left

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

问题描述

我有一个小问题,但我不能得到解决。
我有一个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屋!

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