2

I am trying to create a specific shape with specific color to keep it as a background. I successfully created gradient color that I want but I am struggling with getting shape right.

Here is what I have done and what is am trying to achieve,

My Work :

enter image description here

Expectation :

enter image description here

Code :

.grad {
  height: 400px;
  width: 900px;
  background: linear-gradient(110deg, #62e6a5 50%, #9ae7ba 50%, #9ae7ba 52%, #d1f5de 52%, #d1f5de 0);
}
<div class="grad"></div>

I am open to use any other method as long as it is only one 'div'. I don't want to use two different div which are causing many issues in responsive design. I tried using clip-path but that too did not help because of the nature of the design.

Any help would be appreciated.

2
  • Use pseudo-elements to achieve the offset effect you're after. Commented Mar 6, 2018 at 21:57
  • I tried using pseudo-elements but could not make the shape I want because I have never used them before. That's the nice suggestion. Let me try again. Thanks. Commented Mar 6, 2018 at 22:03

2 Answers 2

2

Use multiple gradient then adjust dimension and position to obtain what you want:

.grad {
  height: 100px;
  width: 300px;
  background:
  linear-gradient(110deg, #62e6a5 50%, #9ae7ba 50%, #9ae7ba 52%, #d1f5de 52%, #d1f5de 0) 0 0/100% calc(100% - 10px) no-repeat,
  linear-gradient(110deg, #62e6a5 52%, transparent 0) 0 100%/100% 100% no-repeat;
}
<div class="grad"></div>

Sign up to request clarification or add additional context in comments.

5 Comments

Looks perfectly fine.Thanks. The only problem I found was with responsiveness which is a huge concern for me.
wow that was so quick and easy solution.Thank you. I wish I would have thought of it. I want to learn linear-gradient more deeply, would you please provide some reference document which explains all the arguments for the gradient so I can learn it myself?
@Developer123 you won't find 1 reference with everything but i would say that you have two main part ... the gradient that you can consider a simple backgroud-image THEN the other property i use after, background-size, background-position that allow you to have what you want so you need first to learn what is inside the gradient then learn how to adjust size/position to obtain what you want. I advise you to check this website css-tricks.com/search-results/?q=gradient where you will find many good thing .. you can also check some of my previous answers as i did a lot with gradient :)
Thank you for the reference. I will definitely check out the link you have provided and your previous answers.
@Developer123 here is a link where you can easily find them stackoverflow.com/… .. you can also search within SO for gradient question/answer ;)
0

Use pseudo-elements like :before and :after

.grad{
  position: relative;
  height:200px;
  width:450px;
  margin-bottom: 10px;
  background: linear-gradient(110deg, #62e6a5 50%, #9ae7ba 50%, #9ae7ba 52%, #d1f5de 52%, #d1f5de 0);
}

.grad-new{
  position: relative;
  height:200px;
  width:450px;
  margin-bottom: 10px;
  overflow: hidden;
  background: linear-gradient(110deg, #62e6a5 50%, #9ae7ba 50%, #9ae7ba 52%, #d1f5de 52%, #d1f5de 0);
}

.grad-new:before{
  content: '';
  position: absolute;
  width: 3%;
  height: 10px;
  bottom: 0;
  right: 55.6%;
  background: #62e6a5;
  transform: skew(-20deg);
}
.grad-new:after{
  content: '';
  position: absolute;
  width: 100%;
  height: 10px;
  bottom: 0;
  left: 44.4%;
  background: #fff;
  transform: skew(-20deg);
}
<div class="grad"></div>
<div class="grad-new"></div>

1 Comment

I tried to do with pseudo-elements before posting this question but I failed. However, it was so thoughtful of you to put the white line to cover right part. Excellent. Thank you. The only problem I found with the solution is responsiveness.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.