Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Float bug in chrome? 1px extra padding, but it's not padding

The following html and css shows two divs inside a container. The left div isn't floated; the right div is floated right.

The right div seems to be one pixel too narrow, and the red background color of the container is therefore showing through in that one pixel gap.

This is a simplification of my problem. http://jsfiddle.net/XPd9J/

HTML

<div class="inner-wrapper">

    <div class="right-sidebar">
        &nbsp;
    </div>

    <div class="content">
        &nbsp;<br /><br />
    </div>

</div>​

CSS

.inner-wrapper {
    position:relative;
    background-color:red;
    overflow:auto;
    width:90%;
    padding:0;
    margin:20px 0 0 20px;
}
.right-sidebar {
    position:relative;
    width:40% !important;
    background-color:lime;
    float:right;
    margin:0;
    padding:0;
}
.content {
    position :relative;
    width:60%;
    background-color:silver;
    margin:0;
    padding:0;
}
​
like image 243
WotNot Avatar asked Mar 25 '12 18:03

WotNot


People also ask

How do you stop padding from increasing width?

To avoid the width or height getting increased or decreased when using CSS properties like margin , padding , etc, we can use the CSS property called box-sizing and set its value to border-box on the element in CSS.

Why is padding added to width?

Padding is used to create space around an element's content, inside of any defined borders.

When using the padding property are you allowed to use negative values?

The padding property may be specified using one, two, three, or four values. Each value is a <length> or a <percentage> . Negative values are invalid.

What is the order of padding in CSS?

The padding property in CSS defines the innermost portion of the box model, creating space around an element's content, inside of any defined margins and/or borders. Padding values are set using lengths or percentages, and cannot accept negative values. The initial, or default, value for all padding properties is 0 .


1 Answers

Another easy option to get the full 100% is to set the parent element to overflow:hidden and your element to width:101%.

like image 95
Max Avatar answered Oct 10 '22 15:10

Max