Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
699 views
in Technique[技术] by (71.8m points)

hiding background color overflow HTML/CSS

I'm trying to put a background color shape, like a big div rotate on the background of my website but the problem is when I place this background where I want it to be its creating me a big margin right & bottom ( because of the end of that div that I have created for putting my background )

here is what I have done :

.fill-2{
    position: absolute;
    top: 45%;
    width: 100%;
    z-index: -2;
    background-color: #A08823;
    opacity: 30%;
    height: 200vh;
    -moz-transform: rotate(20deg);
    -webkit-transform: rotate(20deg);
    -o-transform: rotate(20deg);
    -ms-transform: rotate(20deg);
    transform: rotate(20deg);  
} 
<body>
    <div class="fill-1"></div>
    <div class="container">
        <!-- my content -->
    </div>
    <div class="fill-2"></div>
</body>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The question is a bit unclear, but here are some hints: The absolutely positioned (background) element should be a child element of your main element. Then you can apply position: relative;, overflow: hidden; and optionally a fixed height to the main element (.container in my example below), which will hide those parts of the background that go beyond the main element:

.fill-2 {
  position: absolute;
  top: 45%;
  width: 100%;
  z-index: -2;
  background-color: #A08823;
  opacity: 30%;
  height: 200vh;
  -moz-transform: rotate(20deg);
  -webkit-transform: rotate(20deg);
  -o-transform: rotate(20deg);
  -ms-transform: rotate(20deg);
  transform: rotate(20deg);
}

.container {
  height: 300px;
  position: relative;
  overflow: hidden;
}
<body>
  <div class="fill-1"></div>
  <div class="container">
    <!-- my content -->
    <div class="fill-2"></div>
  </div>
</body>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...