how to text-align: left on a Button

Simon 306 Reputation points
2024-12-03T15:08:32.2833333+00:00

in a aspx page

how to text-align: left on a Button

i set like this

Style="text-align: left"

it dont help, the text are still centered

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,536 questions
{count} votes

4 answers

Sort by: Most helpful
  1. Michael Taylor 55,376 Reputation points
    2024-12-03T15:58:49.9466667+00:00

    Without showing us your HTML is it going to be hard to say. If you're using a third party framework like Bootstrap it is possible it is overriding your settings. If you have additional CSS classes applied they can stomp over things as well.

    The easiest way to figure out what is going on is to load the page in the browser and do the following:

    1. Open the developer tools (F12)
    2. Use the Select an Element tool in the top left corner to select your button. This takes you to the corresponding HTML.
    3. On the right side is the Styles tab. It will show you what styles are being applied and from where. The topmost styling wins. You can uncheck and check styles to remove/add them to test things out. If you still can't figure it out then go to the Computed tab and find the text-align property in the list of CSS properties. It will show you who ultimately is controlling the setting.
    0 comments No comments

  2. Lan Huang-MSFT 29,916 Reputation points Microsoft Vendor
    2024-12-04T08:45:18.5833333+00:00

    Hi @Simon,

    “text-align: left” should work, I guess you want to remove the margin. You can try the following code.

     <asp:Button ID="Button1" runat="server" Text="Button"  style="padding-left:0px; margin-left:0px;"   />
    

    User's image

    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread

    0 comments No comments

  3. Simon 306 Reputation points
    2024-12-04T16:36:06.0966667+00:00

    i am using vb.net and asp.net

    ther are no options the mantions

    i tested this line

    <asp:Button ID="Button1" runat="server" Text="Button" style="padding-left:0px; margin-left:0px;" />

    and it dont help

    0 comments No comments

  4. Albert Kallal 5,331 Reputation points
    2024-12-04T18:44:45.9+00:00

    As a general rule, if you don't make the button "larger" then the text, then you tend to not see any effects of text-align.

    However, if you make the button "larger" then the text, then text-align should work.

    Hence say this markup for a asp.net button.

    Note how I wanted to space out the next two buttons, so I added a margin-left.

                <asp:Button ID="Button1" runat="server" Text="Test button"
                    width="200px"
                    style="text-align:left"/>
    
                <asp:Button ID="Button2" runat="server" Text="Test button"
                    width="200px"
                    style="text-align:right;margin-left:50px"/>
    
                <asp:Button ID="Button3" runat="server" Text="Test button"
                    width="200px"
                    style="text-align:center;margin-left:50px"/>
    
    

    And the result is thus this:

    User's image

    And note how easy it is to add space between each button (no need for say using some table layout - just move each button over by adding margin-left.

    So, a style with text-align should work, but the button "width" will have to be set larger then the button text which by default will set the length of the button to see such effects. And even if you using a button class such as bootstrap, or whatever?

    Then say this markup:

                <asp:Button ID="Button1" runat="server" Text="Test button"
                    width="200px"
                    CssClass="btn burkebuttn"
                    style="text-align:left"/>
    
                <asp:Button ID="Button2" runat="server" Text="Test button"
                    width="200px"
                    CssClass="btn burkebuttn"
                    style="text-align:right;margin-left:50px"/>
    
                <asp:Button ID="Button3" runat="server" Text="Test button"
                    CssClass="btn burkebuttn"
                    width="200px"
                    style="text-align:center;margin-left:50px"/>
    
    

    Then once again, the text-align should still be respected.

    Hence this:

    User's image

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.