Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scrollbar added to an element when width is 100%

Tags:

html

css

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?

like image 899
Zed Avatar asked Feb 16 '23 23:02

Zed


2 Answers

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

like image 140
Rohit Azad Malik Avatar answered Feb 26 '23 22:02

Rohit Azad Malik


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

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

Demo

like image 35
mishik Avatar answered Feb 26 '23 22:02

mishik