4

I'm curious why overflow: auto; rule adds scrollbar in this case

CSS:

textarea {
    width: 100%;
    margin:0;
    padding:0;

}

.span4 {
    width: 300px;

}

aside {
    overflow: auto;
}

html:

<aside class="span4">    
    <textarea cols="40" rows="20"></textarea>       
</aside>

http://jsfiddle.net/ZnsW9/ If this textarea has 100% width, and without margins and paddings, how is that overflowing the container box?

Zaheer Ahmed
  • 28,160
  • 11
  • 74
  • 110
Zed
  • 5,683
  • 11
  • 49
  • 81

2 Answers2

7

Used to box-sizing

textarea {
            width: 100%;
            margin:0;
            padding:0;
    -webkit-box-sizing:border-box;
    -moz-box-sizing:border-box;
    box-sizing:border-box;

        }

Demo

Rohit Azad Malik
  • 31,410
  • 17
  • 69
  • 97
  • thanks, this box-sizing seems like a wonderful thing, I just can't beleive that still it can't be used in firefox without -moz- prefix – Zed Jul 10 '13 at 10:59
1

Scrollbar is added because of border. Add border: none; rule to textarea:

textarea {
    width: 100%;
    margin:0;
    padding:0;
    border: none;
}

Demo

mishik
  • 9,973
  • 9
  • 45
  • 67