简体   繁体   English

我怎样才能<span>向左</span>对齐<span>?</span>

[英]How can i align <span> to the left?

i need to align <span> to the left.我需要将<span>向左对齐。 I can't use:我不能使用:

position:absolute;
float:left;

Because when i use these, it is align in left but it cause me other problems.因为当我使用这些时,它在左边对齐,但它给我带来了其他问题。 Does anybody know about some other option ?有人知道其他选择吗?

EDIT: OK, i used float:left;编辑:好的,我使用了float:left; and it is on the left side but the other span beneath simply dont stay on his line.它在左侧,但下方的另一个跨度根本不停留在他的线上。 I cant do </br> after span i tried this, i tried clear:left;我不能做</br>跨度后我试过这个,我试过clear:left; it didnt help neither.它也没有帮助。

You should have a look at how floats work .你应该看看浮动如何工作的

Using absolute means that you can position your span with the given distances to the edges of your div.使用absolute意味着您可以使用到 div 边缘的给定距离来定位跨度。 Hence, using float: left;因此,使用float: left; in addition to this doesn't make sense.除此之外没有任何意义。

Instead you can do absolute positioning:相反,您可以进行绝对定位:

position: absolute;
left: 0px;

You need to declare your span as a display:block or inline-block and remove the position:absolute line.您需要将您的跨度声明为 display:block 或 inline-block 并删除 position:absolute 行。 Then it will float left with the declaration that you have above.然后它将与您上面的声明一起向左浮动。

{
    display: block;
    float: left;
}

The problem that you are encountering with may be that "All the other elements take the space to the right".您遇到的问题可能是“所有其他元素都占用右侧的空间”。 And that is exactly what they are supposed to do.而这正是他们应该做的。 To avoid this, grab your elements that are floating to the right automatically and do this:为避免这种情况,请抓住自动向右浮动的元素并执行以下操作:

 clear:both;

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

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