I have these HTML and CSS:
#siteInfo input[type="button"] { background: none repeat scroll 0 0 #66A3D2; border-color: #FFFFFF #327CB5 #327CB5 #FFFFFF; border-radius: 10px 10px 10px 10px; border-style: solid; border-width: 1px; box-shadow: 1px 1px 3px #333333; color: #FFFFFF; cursor: pointer; font-weight: bold; padding: 5px; text-align: center; text-shadow: 1px 1px 1px #000000; }
<div id="siteInfo"> <p>Some paragraph.</p> <input type="button" value="Some Button"> </div>
I'd like the button to be aligned to the center; however, even with text-align: center
in the CSS, is still on the left. I also don't want to specify the width since I'd like it to change with the length of the text. How do I do that?
I know the solution to this is simple but I can't find a proper way to do it. I would sometimes wrap it around a <p>
tag that is center aligned but that's extra mark-up which I'd like to avoid.
HTML | <input> align Attribute left: It sets the alignment of image to the left. it is a default value. right: It sets the alignment of image to the right. middle: It sets the alignment of image to the middle.
Not with a fixed width of the textbox:Wrap a div around with text-align: center; . Show activity on this post. In modern browsers that support CSS 3 you can do an easy centering using these three lines of code: position: absolute; left: 50%; transform: translateX(-50%);
You need to put the text-align:center
on the containing div, not on the input itself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With