Forgive me for asking such a simple question, I'm new to both HTML and CSS. Is there an easy way to center a textarea? I figured I'd just try using
textarea{
margin-left: auto;
margin-right: auto;
}
but it (obviously?) didn't work.
Forgive me for asking such a simple question, I'm new to both HTML and CSS. Is there an easy way to center a textarea? I figured I'd just try using
textarea{
margin-left: auto;
margin-right: auto;
}
but it (obviously?) didn't work.
you wrap your textarea with a div, give it width and then you align it with
text-align:center;
Set
text-align
of the element's parent tocenter
, like this:HTML:
CSS:
Here is an example: http://jsfiddle.net/ujzLt/
The margins won't affect the textarea because it is not a block level element, but you can make it display block if you like:
By default, textareas are
display: inline
, which is why you can put them side-by-side easily, and why thetext-align: center
answers work too.The textarea can also be centered by putting it inside a flexbox container like this:
add
display: block;
to your textarea styles