CSS:中心块,但将内容对齐到左边 [英] CSS: Center block, but align contents to the left

查看:255
本文介绍了CSS:中心块,但将内容对齐到左边的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个整个块在其父对象中居中,但我想让块的内容对齐。

I want a whole block to be centered in its parent, but I want the contents of the block to be left aligned.

示例最好

在此页面上:

http:// yaml- online-parser.appspot.com/?yaml=%23+ASCII+Art%0d%0a---+%7c%0d%0a++%5c%2f%2f%7c%7c%5c%2f%7c%7c% 0d%0a ++%2f%2f +%7c%7c ++%7c%7c __%0d%0a& type = python

ascii艺术应该居中

the ascii art should be centered (as it appears) but it should line up and look like "YAML".

或者:

http://yaml-online-parser.appspot。 com / yaml =%3f + - +底特律+老虎%0d%0a ++ - +芝加哥+幼崽%0d%0a%3a%0d%0a ++ - + 2001-07-23%0d%0a%0d%0a%3f +%5b + New + York + Yankees%2c%0d%0a ++++亚特兰大+ Braves +%5d%0d%0a%3a +%5b + 2001-07-02%2c + 2001-08-12%2c%0d%0a + +++ 2001-08-14 +%5d%0d%0a

错误消息应该与在控制台中一样排列。

the error message should all line up as it does in a console.

推荐答案

重新发布其他问题的工作答案:如何水平居中一个可变宽度的浮动元素?

Reposting the working answer from the other question: How to horizontally center a floating element of a variable width?

假设被浮动的元素和将被居中的元素是具有id =content的div ... ...

Assuming the element which is floated and will be centered is a div with an id="content" ...

<body>
<div id="wrap">
   <div id="content">
   This will be centered
   </div>
</div>
</body>

并套用下列CSS

#wrap {
    float: left;
    position: relative;
    left: 50%;
}

#content {
    float: left;
    position: relative;
    left: -50%;
}

这里是一个很好的参考, http://dev.opera.com/articles/view/35-floats-and-clearing/ #centeringfloats

Here is a good reference regarding that http://dev.opera.com/articles/view/35-floats-and-clearing/#centeringfloats

这篇关于CSS:中心块,但将内容对齐到左边的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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