最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Diagonal Side div color css js - Stack Overflow

programmeradmin1浏览0评论

i have 2 div like this

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

CSS :

.container {
    width:100%;
}


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

I want to give this 2 divs a diagonal side color to be like this

I tried rotate but it gave me some white spot.
Can any one help me please ?

i have 2 div like this

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

CSS :

.container {
    width:100%;
}


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

I want to give this 2 divs a diagonal side color to be like this

I tried rotate but it gave me some white spot.
Can any one help me please ?

Share Improve this question asked Nov 5, 2017 at 16:51 Zak-DevZak-Dev 851 silver badge13 bronze badges 1
  • 1 You only need to rotate one div above the other. Can you provide the code you tried ? – 3Dos Commented Nov 5, 2017 at 16:55
Add a ment  | 

3 Answers 3

Reset to default 4

A single gradient on the parent will do the visual:

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.

You can use clip paths and 2 div within a container,

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%);
}

Try using an svg path css background property. See example below.

.container {
  background: red;
  height: 117px;
}

.one {
  float: left;
  width: 50%;
  height: 117px;
  background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3/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>

发布评论

评论列表(0)

  1. 暂无评论