简体   繁体   English

如何在同一行上对齐2个文本?

[英]How can I align my 2 texts on the same row?

I'm trying to achieve something simple and the rules make it non-trivial. 我正在尝试实现一些简单的规则,这些规则使其变得不平凡。 Here is my fiddle . 这是我的小提琴 It is non-trivial for me to align the elements in a natural way, I think the elements should be on the same row when I make a float:left . 以自然的方式对齐元素对我而言并非难事,我认为在进行float:left时元素应位于同一行上。

Hx elements have default margins. Hx元素具有默认边距。

The "space" from the top cause by the margin-top property of the H1 element. H1元素的margin-top属性导致从顶部开始的“空格”。 Consider using a reset.css file to reset those default values. 考虑使用reset.css文件重置这些默认值。 Another thing is the line-height property. 另一件事是line-height属性。

In conclusion: 结论:

  • margin-top:0;
  • line-height: 20px; (choose a value that fits to your needs) (选择一个适合您需求的值)

http://jsfiddle.net/ynrmwgt9/4/ http://jsfiddle.net/ynrmwgt9/4/

I would recommend to wrap your div in a container div . 我建议将div包装在容器div中 A little bit like bootstrap system. 有点像引导系统。

See the fiddle, and ask me if you have questions about :) 看小提琴,问我是否对:)有疑问

I'm using something like this : 我正在使用这样的东西:

<div class='row'>
    <div class='col'>Content 1</div>
    <div class='col'>Content 2</div>
</div>

The stylesheet has to specify that row fill 100% of the width, and your two columns, the half, then 50% each. 样式表必须指定该row占宽度的100%,然后指定两列,即一半,然后各占50%。

.row
{
    width:100%;
}

.col
{
    width:50%;
    float:left;
    text-align:center;
}

Text align center is just for make it beautiful 文字对齐中心只是为了使其美观

http://jsfiddle.net/ynrmwgt9/2/ http://jsfiddle.net/ynrmwgt9/2/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM