开发者

Left align the label control in <div> tag

开发者 https://www.devze.com 2023-02-06 04:27 出处:网络
I was trying 开发者_开发问答to set the alignment of elements within my web page that has some ASP.NET controls. Inside, the div tag, I need to set the alignment of Label control so that it is always r

I was trying 开发者_开发问答to set the alignment of elements within my web page that has some ASP.NET controls. Inside, the div tag, I need to set the alignment of Label control so that it is always right aligned in div.

How can I set this? Thanks!

Edit: Here's the HTML code:

<div id="UserLoggedinMessage" style="float:right; width:280px">    
    <div style="float:right;width:350px">
        <asp:Label ID="Label3" runat="server"></asp:Label>     
        <asp:LinkButton ID="LinkButton1" runat="server" onclick="LinkButton1_Click">Login now</asp:LinkButton>     

        <!-- Serch Box -->    
        <div id="WLSearchBoxDiv" style="float:right">    
        </div>
        <!-- Seach Box -->
    </div>
</div>

So, this gives me my search box and Login Button in the same line. But the Login button is left aligned. I have correct this.


Here is my stab at it, but I'm making some assumptions about how you want things positioned. By using float:right; on each separate div, you can remove any extra spacing generated, and by reordering them in reverse you can get them to line up from right to left properly:

<div id="UserLoggedinMessage" style="float:right; width:280px;">

    <!-- removed width of 350, 350 inside div of 280 doesn't make sense -->
    <!-- also separated everything into separate divs and reordered them -->
    <div style="float:right;">
        <asp:LinkButton ID="LinkButton1" runat="server" onclick="LinkButton1_Click">Login now</asp:LinkButton>
    </div>  
    <div style="float:right;">
        <asp:Label ID="Label3" runat="server" />
    </div>
    <!-- Search Box -->
    <div id="WLSearchBoxDiv" style="float:right">

    </div>
    <!-- Seach Box -->
</div>


You can take another div control in div and set style float:right to inner div.


try this :

<div style="float:right">
  This is some text and or other controls
</div>

supplying the 'div' with this formatting will move all the inner contents to the right-most position.


You could try absolute positioning of the label, ie. { position: absolute; right: 0 }. This would however mean that the parent needs to be absolute positioned as well, which might be an issue.

Providing more code might us help single out a good solution.


In the style attribute, insert this:

line-height:25px;
0

精彩评论

暂无评论...
验证码 换一张
取 消