Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialFedor Andreev
6,438 PointsHow would you center a textarea with css?
The code for html
<textarea cols="40" rows="8" name="textarea"></textarea>
But I've looked everywhere on google and no code allows me to center it on the page with css? I've tried everything, and converting it to a block. Can someone write me a code for css that allows it to be centered? Perhaps something is wrong with my html code? (can't be I can see and click the textarea on my page).
Help!!
3 Answers
Stone Preston
42,016 Pointshard to say without looking at your code, but have you tried setting the left and right margins of it to auto and setting its display property to block?
textarea{
display: block;
margin-left: auto;
margin-right: auto;
}
text-areas are inline by default, so simply setting the margins wont work. you have to make it a block element as well.
Fedor Andreev
6,438 Points textarea{
display: block;
margin-left: auto;
margin-right: auto;
}
```<textarea cols="40" rows="8" name="textarea"></textarea>
```
Fedor Andreev
6,438 PointsIt's still on the left side :(
Stone Preston
42,016 Pointsits hard to tell what exactly is going on in your code blocks. its not formatted quite right. to format a code block you need to skip a line, type 3 backticks (they are below the escape key) then on a new line post your code, then on a new line type 3 more back ticks
Stone Preston
42,016 PointsStone Preston
42,016 Pointsyou will need to format your code using markdown to get html code to show up in forum posts. there is a link to a markdown cheatsheet at the bottom right corner of the post/comment box that explains how to format it.