Element width expands as height increases

偶尔善良 提交于 2019-12-11 09:41:32

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!