簡體   English   中英

斜邊div顏色CSS JS

[英]Diagonal Side div color css js

我有2 div這樣

<div class="container">
    <div class="one"></div>
    <div class="two"></div>
</div>

CSS:

.container {
    width:100%;
}


.one , .two {
    width:50%;
    display:inline-block;
}

我想給這個2 divs像這樣的對角線側面顏色

在此處輸入圖片說明

我嘗試rotate但它給了我一些白點。
有人可以幫我嗎?

父級上的單個漸變將產生視覺效果:

 html { min-height:100%; background:linear-gradient(140deg, rgb(153, 180, 211)50%, rgb(217, 181, 150) 50%) } 
 example on HTML background sized at 100% viewport's height at the minimum. 

嘗試使用svg路徑CSS背景屬性。 請參見下面的示例。

 .container { background: red; height: 117px; } .one { float: left; width: 50%; height: 117px; background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='100%' height='100%' viewBox='0 0 100 100' fill='blue' preserveAspectRatio='none'><path d='M0 0 L0 100 L50 100 L100 0 Z' /></svg>") no-repeat; } .two { float: left; width: 50%; height: 117px; } 
 <div class="container"> <div class="one"></div> <div class="two"></div> </div> 

您可以在容器中使用剪切路徑和2 div,

https://codepen.io/anon/pen/OOXPmv

的HTML

<div id="wrapper">
  <div id="left"></div>
  <div id="right"></div>
</div>

的CSS

body, html {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  background: #ccc;
}

#wrapper {
  width: 100%;
  height: 100%;
  background: #111;
}

#left {
  position: absolute;
  top: 0;
  left: 0;
  width: 101%; /* If you make it 100%, you get a bit of black showing along the diagonal */
  height: 100%;
  background: #99b4d3;
  -webkit-clip-path: polygon(0 0, 76% 0, 24% 100%, 0% 100%);
  clip-path: polygon(0 0, 76% 0, 24% 100%, 0% 100%);
}

#right {
  position: absolute;
  top: 0;
  right: 0;
  width: 100%;
  height: 100%;
  background: #d9b596;
  -webkit-clip-path: polygon(76% 0, 100% 0, 100% 100%, 24% 100%);
  clip-path: polygon(76% 0, 100% 0, 100% 100%, 24% 100%);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM