2015-09-04 43 views
1
    this is my alignment : 
      this is my alignment one : 
     this is my alignment one two : 
    this is my alignment one two three : 

style="position:absolute;top:63px;left:151px;width:88px;margin-left:-132px;margin-top:5px" 

<span id="resultModel.hdPk1Label" name="resultModel.hdPk1Label" class="singleFormLabel" style="position:absolute;top:36px;left:151px;width:88px;margin-left:-132px;margin-top:5px"><font class="essential_mark">*</font>label.hdPk1 &nbsp;:&nbsp;</span> 

对准一些句子我有一些元件/标签&我想安排/在上述方式将它们对准并且使用上述代码,但其对准,如下所示:我想使用CSS

this is my alignment : 
this is my alignment one : 
this is my alignment one two : 
this is my alignment one two three : 

我怎样才能达到我想要的效果?

+2

'text-align:right'? – Siguza

+1

您可能希望包含要安排的所述“元素/标签”的HTML,否则可能会使我们难以理解您的困难。 – Serlite

+0

请给我们一个你的标记的例子。即。 jsfiddle.net并告诉我们您的限制。是否允许在短语的周围添加元素? –

回答

4

从你的描述,你只是在寻找text-align: right;

span 
 
{ 
 
    display: inline-block; 
 
    white-space: pre; 
 
    text-align: right; 
 
}
<span> 
 
    this is my alignment : 
 
    this is my alignment one : 
 
    this is my alignment one two : 
 
    this is my alignment one two three : 
 
</span>

5
<div class="right">this is my alignment :<br/> 
    this is my alignment one :<br/> 
this is my alignment one two :</div> 

CSS

.right 
{ 
    text-align:right; 
} 

小提琴

https://jsfiddle.net/oa7tbcgj/

+0

'
',而不是'
'。 – Siguza

+0

你是对的,改变了 – Jesse

+0

style =“position:absolute; top:97px; left:170px; width:48px; margin-left:-132px; text-align:right; margin-top:5px”缩进 – SOP

1

见代码:

div { 
 
    position:absolute; 
 
    /* top:63px; adding your top margin of 5px from this value gives you a new property of... */ 
 
    top:68px 
 
    
 
    /* left:151px; subtracting your negative left margin of 132px from this value gives you a new property of... */ 
 
    left: 19px; 
 
    
 
    /* width:88px; 88px is not wide enough for standard font size to make lines at this length */ 
 
    width:250px; 
 
    
 
    text-align:right; /* aligns text to the right instead of to the left */ 
 
    
 
    /* Don't use margins on positioned elements unless you're trying to 'hack' something to be centered relative to some percentage position (ex left:50%; margin-left:-(half of this block's explicit width)). When you use positioning and margins you can no longer look at a single property declaration (ie "margin-top" or "left") to determine the positioning of your element. That makes maintaining your code more difficult and planning your layout around your positioned element more complicated. */ 
 
    /* margin-left:-132px; */ 
 
    /* margin-top:5px; */ 
 
} 
 

 
p { 
 
    /* paragraph tags, by default, have a top and bottom margin of 1em. We need to overwrite this default to get your lines to stack like you want them to */ 
 
    margin:0; 
 
    }
<div> 
 
    <p>this is my alignment :</p> 
 
    <p>this is my alignment one :</p> 
 
    <p>this is my alignment one two :</p> 
 
    <p>this is my alignment one two three :</p> 
 
</div> 
 

1

检查小提琴:https://jsfiddle.net/esc0se6x/

HTML

<div class="right"> 
    <span id="resultModel.hdPk1Label" name="label1" class="singleFormLabel">label.hdPk1 &nbsp;:&nbsp;</span> 
    <span id="resultModel.hdPk1Label" name="label2" class="singleFormLabel">loremloremdPk1 &nbsbsp;dPk1 &nbsp;:&nbsp;</span> 
    <span id="resultModel.hdPk1Label" name="label3" class="singleFormLabel">label.loremdPk1 &nbsbsp;:&nbsp;hdPk1 &nbsp;:&nbsp;</span> 
</div> 

CSS

.right { 
    text-align:right; 
} 

.right > span { 
    display:block; 
}