I want to center textarea
element, but margin: 0 auto
doesn't work properly.
Also I tried to wrap element in div
which has margin: 0 auto
style.
<div style="margin: 0 auto;">
<textarea rows="4" cols"100"></textare>
</div>
I want to center textarea
element, but margin: 0 auto
doesn't work properly.
Also I tried to wrap element in div
which has margin: 0 auto
style.
<div style="margin: 0 auto;">
<textarea rows="4" cols"100"></textare>
</div>
You can do it with display: flex
and justify-content: center;
<div style="display:flex; justify-content:center;">
<textarea rows="4" cols"100"></textare>
</div>
If you want to center in HTML you can go for:
<center>
<h2>How Not to Center with HTML</h2>
</center>
This text may be centered... but you would be better off using CSS to center text or other elements on a web page. Like this:
HTML:
<div class="center">
<p>Some centered text</p>
</div>
CSS:
.center {
margin: auto;
width: 50%;
border: 3px solid green;
padding: 10px;
}
Set the div to display: table;
This allows the div to take the width of the textarea instead of taking up width:100%;
This should fix it:
<div style="margin: 0 auto; display:table;">
<textarea rows="4" cols="100">
</textarea>
</div>
I also noticed that your question had a few typos and this will not render correct HTML. It should be 'textarea' not 'textare'. Please correct them too and it should be good to go.
There is kinda tricky solution:
You should enclose the element inside wrapper
element, which have style="text-align: center"
and the element style should be display: inline-block
<div style="text-align: center">
<textarea rows="4" cols="100"></textarea>
</div>