Skip to content

.width(value) sets incorrect width value if block has border and value specified in ems and box-sizing:border-box #1712

@mgol

Description

@mgol

Originally reported by tde: http://bugs.jquery.com/ticket/14038

API documentation specifies: "Note that .width("value") sets the content width of the box regardless of the value of the CSS box-sizing property."

There are two key factors leading to this bug

"box-sizing:border-box"
"border:1px solid black"
width specified in ems
Code that reproduces this bug

<html>
    <head>
        <style>
            #container {width:100%;}
            #box {border:1px solid black; margin:0 auto; box-sizing:border-box;}
        </style>
        <script type="text/javascript" src="http://code.jquery.com/jquery-2.0.1.js"></script>
        <script>
            var $ = jQuery.noConflict();
            $(document).ready(function() {
                $('#box').width('10em'); // width should be 10em, but jquery set it to 12em
            });
        </script>
    </head>
    <body>
        <div id="container">
            <div id="box">
                <p>some text</p>
            </div>
        </div>
    </body>
</html>

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions