问题
I used CSS :before and :after to create a paper like layout with a div. It's fine but the width increases as the height increases. I've tried max-width but to no avail. Any ideas on how this can be prevented.
HTML
<div class="rack"></div><!-- End Rack -->
CSS
.rack {
width: 70%;
height: 100%;
background: #7FAE68;
margin: -255px 0 100px 0;
position: relative;
float: left;
left: 15%;
z-index: 9999;
transform:rotate(1deg);
-ms-transform:rotate(1deg);
-webkit-transform:rotate(1deg);
padding-bottom:50px;
}
.rack::before {
content: "";
background: #E1BB70;
position: absolute;
height: 100%;
width: 100%;
z-index: -2;
transform:rotate(1deg);
-ms-transform:rotate(1deg);
-webkit-transform:rotate(1deg);
float: left;
left: 0%;
}
.rack::after {
content: "";
background: #E5E8EC;
position: absolute;
height: 100%;
width: 100%;
z-index: -1;
transform:rotate(-1deg);
-ms-transform:rotate(-1deg);
-webkit-transform:rotate(-1deg);
border: solid 1px #ddd;
left: 0%;
}
Before height increase

After height increase

Jsfiddle link
Double the content in the fiddle to witness the problem.
回答1:
Add the following css to every class:
box-sizing:border-box
here is a fiddle: http://jsfiddle.net/npGy8/31/
Hope this helps.
来源:https://stackoverflow.com/questions/24524108/element-width-expands-as-height-increases