简体   繁体   English

HTML如何在同一行中不同地对齐两个单词

[英]HTML How to align two words differently in the same line

I have two words on the same line. 我在同一行上有两个字。 I want the first word and the second to be aligned to the left and to the right respectively on the same line. 我希望第一个单词和第二个单词在同一行上分别向左和向右对齐。 Does anyone know how to do this? 有谁知道如何做到这一点? Thanks 谢谢

Use a <span> with float: left for the left word, and another <span> with float: right for the right word. 将带有float: left<span>用于左边的单词,将带有float: right <span>用于右边的单词。 There are other alignment techniques as well, but I don't think it's possible without separating the words into their own elements. 还有其他对齐技术,但我认为如果不将单词分成自己的元素就不可能。

Adding on to what Agop said, another way is to have both the elements positioned absolutely in a parent <div> which has relative position. 除了Agop所说的那样,另一种方法是将两个元素都绝对定位在具有相对位置的父<div>中。 This way, the absolute position will be based on the parent. 这样,绝对位置将基于父级。 So right: 0 and left: 0 respectively will be to the left and right of the parent <div> . 所以right: 0left: 0将分别位于父<div>的左侧和右侧。

See this JSFiddle: http://jsfiddle.net/3ebrcnoL/ 看到这个JSFiddle: http : //jsfiddle.net/3ebrcnoL/

You can try this:- 您可以尝试以下方法:

<style type="text/css">
    .maindiv{width:1000px;height:auto;}
    .float_left{float:left;}
    .float_right{float:right;}
</style>
<div class="maindiv">
    <span class="float_left">Leftside</span>
    <span class="float_right">Rightside</span>
</div>

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

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