Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Align Center CSS

Status
Not open for further replies.

aspnetvbcsharpnerd

Programmer
Jun 30, 2008
6
SE
I know how to align text center text-align: center;

How do I align an input to to be center?

 
It doesn't the textbox isn't isn't at the center it just next to text.
This is what I have so far.

Code:
    <h1>Item</h1>
    
    <p><strong>ItemId</strong><asp:TextBox ID="txtItemId" runat="server" CssClass="alignment-center"></asp:TextBox></p>
    <p><strong>Name</strong><asp:TextBox ID="txtItem" runat="server" CssClass="alignment-center"></asp:TextBox></p>
    
    <p style="float: right;"><asp:Button ID="btnSave" runat="server" Text="Search" CssClass="button" OnClick="btnSearch_Click" /></p>
    
    <br />

Css
.alignment-center {
text-align: center;
}
 
This forum deals specifically with client-side code - for asp.net (server-side code) try forum855 - otherwise post the clientside code here

___________________________________________________________
If you want the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
Steam Engine Prints
 
You cannot assign text-align to the inline element. Inline element does not have any alignment. You need to assign the text-align to its block-level parent element. In your case, that would be the paragraph (<p>).

___________________________________________________________
[small]Do something about world cancer today: Comprehensive cancer control information at PACT[/small]
 
Ok, I'll have the same issue using client-side code

If I add to the paragraph then everything becomes center and it work.
Code:
<p class="alignment-center"><strong>ItemId</strong><input class="alignment-center" /></p>

But I want the text to be at the left and the input to be at the center.
Is this possible?

 
You will have to put them in two separate containers. The text (that should actually be inside a label element) in one block floated left and input in another block, either floated left next to it or floated right (depending on the your design). It seems that definition list might be a good way to go.

___________________________________________________________
[small]Do something about world cancer today: Comprehensive cancer control information at PACT[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top