I'm trying to make a new layout when I encountered this behaviour where the computed width is different from the specified width. So now, I'm curious on the way the width is computed in this scenario.
I know I can use .row-1 { width: calc(100% - 70px); }
so row-2
will have 70px
width, but I want to know how width: 100%
works with px width in this case.
I expect the width of row-2
to be 70px
, but the computed value is somewhere in between 60px - 69px
.
html,
body {
width: 100%;
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.container {
display: flex;
width: 100%;
}
.row {
border: 1px solid black;
padding: 5px;
}
.row-1 {
width: 100%;
}
.row-2 {
width: 70px;
}
<html>
<body>
<div class="container">
<div class="row row-1">row 1</div>
<div class="row row-2">row 2</div>
</div>
</body>
</html>
EDIT: The last sentence may be confusing as to what my inquiry is about. What I want to know is the way the browser computes the width of row-2
in this scenario. Why is it not 70px
like the specified width?