How to center a textarea using CSS?

前端 未结 5 2253
长发绾君心
长发绾君心 2021-01-31 08:00

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{
          


        
5条回答
  •  眼角桃花
    2021-01-31 08:15

    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:

    textarea {
        display: block;
        margin-left: auto;
        margin-right: auto;
    }
    

    before and after

    By default, textareas are display: inline, which is why you can put them side-by-side easily, and why the text-align: center answers work too.

    The textarea can also be centered by putting it inside a flexbox container like this:

    
    
    

提交回复
热议问题