So I have a clip path to create a downward arrow between the sections. In other words, I have gradient on section 1, and then a gradient on section 2. In section 2, I've clip-pathed it so that it looks like a downward arrow that is connected to the first section.
What doesn't make sense, is that this code is the same for all the other sections (with differnet id's obviously), but it's showing properly. At the top of section 2, it has a 1px line that's visible (and showcases the different sections) as not being connected. But the problem isn't anywhere else. I've cleared cache, attempted to change the code, and even used the dev tools. Nothing is working. Any help is appreciated.
Here is the image so you can see what it looks like:
Here is the code:
#divider-red-section-3 {
position: relative;
background-size: cover;
background-color: $white-bg;
height: 15rem;
width: auto;
.primary-overlay-4 {
background: $primary-what-amidoing-overlay;
position: absolute;
-webkit-clip-path: polygon(100% 30%, 50% 100%, 0 30%, 0 0, 100% 0);
clip-path: polygon(100% 30%, 50% 100%, 0 30%, 0 0, 100% 0);
top: 0;
left: 0;
width: 100%;
height: 100%;
}
}
Related
i'm trying to apply a gradient to a skewed div but the gradient starts where the skew starts and it doesn't apply the gradient i'm looking for no matter what angle i use.
This is the gradient i'm trying to replicate
but I get a very different result...the colors are off and it's too green on the right side of mine. You can notice that on the image above, the gradient starts at the little wedge at the bottom but mine starts on the entire bottom part.
.main {
height: 80vh;
background-color: white;
}
.skew-div {
height: 100%;
width: 100%;
position: absolute;
top: 0;
background: linear-gradient(180deg, #1D2345 0%, #242766 27.88%, #294B7C 52.91%, #2E6E92 76.86%, #40CE9C 104.51%);;
transform: skewY(-12deg);
transform-origin: 0;
}
<div class="main">
<div class="skew-div">
</div>
</div>
is this possible without just placing the image as a background?
Use clip-path
.main {
height: 80vh;
background-color: white;
position:relative;
}
.skew-div {
height: 100%;
width: 100%;
position: absolute;
top: 0;
background: linear-gradient(180deg, #1D2345 0%, #242766 27.88%, #294B7C 52.91%, #2E6E92 76.86%, #40CE9C 104.51%);
clip-path: polygon(0 0, 100% 0, 100% 70%, 0 100%);
}
<div class="main">
<div class="skew-div">
</div>
</div>
You can use clip-path property
.main {
height: 80vh;
background-color: white;
}
.skew-div {
height: 100%;
width: 100%;
position: absolute;
top: 0;
background: linear-gradient(180deg, #1D2345 0%, #242766 27.88%, #294B7C 52.91%, #2E6E92 76.86%, #40CE9C 104.51%);
;
clip-path: polygon(0 0, 100% 0, 100% 75%, 0% 100%);
}
<div class="main">
<div class="skew-div">
</div>
</div>
Instead of using transform: skewY() you may use clip-path property. transform sometimes creates some sudden confusing problems. That's why you should sometimes escape using that property. Else use it using proper Browser Vendor Prefixes.
If you feel any difficulty configuring clip-path property then you may use this 3rd party website for clip-path value generation =>
https://bennettfeely.com/clippy/
I created a diagonal line on a container div: when I zoom a whitespace (or maybe a margin) of 1px appears on the bottom of my div showing a piece of the background color of the parent div.
I have been facing this problem for days without a solution.
You can view it here: https://codepen.io/Sirvasile/pen/GyPapb
div {
position: relative;
width: 100%;
height: 212px;
background-color: orange;
}
div::after {
content: "";
position: absolute;
bottom: 0;
width: 0;
height: 0;
border-style: solid;
border-width: 0 0 40px 100vw;
border-color: transparent transparent white transparent;
}
<div></div>
This is a screenshot of the div without zoom.
This is a screenshot of the div when the web page is zoomed (> 100%) (experienced using Google Chrome and Safari):
P.S. I already tried using transform: translateY(1px) but I can't accept it as a solution because using it the div has no more a perfect diagonal line.
I've dealt with similar problems, though not this exact one, and I believe the cause, ultimately, is a rounding error that ends up leaving a spare pixel. It's a browser bug that you won't fix with CSS alone, and transform: translateY(1px) might be the only guaranteed fix to the above code.
But, we can probably avoid that bug just by creating this effect by different means.
div {
position: relative;
width: 100%;
height: 212px;
background-color: orange;
-webkit-clip-path: polygon(100% 0, 100% calc(100% - 40px), 0 100%, 0 100%, 0 0);
clip-path: polygon(100% 0, 100% calc(100% - 40px), 0 100%, 0 100%, 0 0);
}
<div></div>
Have you tried replacing 100% with100vw ?
Sometime using these two different values for the same element can resolve to a weird scroll appearing.
I want to create a triangle which looks like red triangle in below image:
So, I tried my luck with css as follows:
HTML:
<div class="div-1"></div>
<div class="div-2"></div>
<div class="div-3"></div>
CSS:
.div-1 {
position: absolute;
bottom: 0; left: 0;
border-bottom: 385px solid #222;
border-right: 175px solid transparent;
width: 0;
z-index: 5;
pointer-events:none;
}
.div-2 {
position: absolute;
bottom: 0; left: 45px;
border-bottom: 285px solid #ED3237;
border-right: 130px solid transparent;
width: 0;
z-index: 5;
}
.div-3 {
position: absolute;
bottom: 0; left: 45px;
border-bottom: 286px solid #222;
border-right: 105px solid transparent;
width: 0;
z-index: 5;
pointer-events:none;
}
And I got it. Here is the JSFiddle
Now, I want to change the triangle's color to blue when I hover over it.
So, I tried this CSS:
.div-2:hover{
border-bottom: 285px solid blue;
}
At first sight it looks like it is working fine. But we can notice the problem if we take a look at it closely.
Whenever mouse pointer is on transparent area of .div-2, then also color of triangle is changed. I don't want that. I only want to change the color of triangle to blue when cursor is hovered over visible(red) part of .div-2.
So, I again searched on google. Which explained me that I should use rotate transform instead of borders of div.
But I can't find a good tutorial on creating right angled triangles of different width and height as used above. So, I asked this question. Here is the question: How to create a triangle as shown in above image using rotate transform, css3 property.
Update:
SVG is really easy. But I want it done with css because I also intend to hide the bottom part of carousel as shown here:
With all due respect, your request doesn't make much sense. From where I see it, you should not be asking for do this using that (or the other) technique.
Code is convention.
It all boils down to using some conventions over others, in order to display the result we want in particular browsers. It really does not matter what technique or language one uses, as long as they achieve the result without side-effects on other functionality/behavior.
Getting back to your question, you'll always have trouble trying to control the :hover state of an element while hovering a border but not the other.
You could, of course, add a mask to your element thus limiting pointer-events but, than again, why not use the mask in the first place, for display?
Here's how I'd tackle this layout:
.image-container {
background-color: #222;
position: relative;
}
.image-container img {
display: block;
width: 100%;
height: 100%;
object-fit: cover;
-webkit-clip-path: polygon(0 0, 73% 0, 100% 50%, 100% 100%, 27% 100%);
clip-path: polygon(0 0, 73% 0, 100% 50%, 100% 100%, 27% 100%);
}
l-border,
r-border {
position: absolute;
height: 100%;
width: 100%;
background-color: #600;
top: 0;
transition: background-color .5s cubic-bezier(.5, 0, .3, 1);
}
l-border:hover,
r-border:hover {
background-color: red;
}
l-border {
-webkit-clip-path: polygon(0 0, 24% 100%, 27% 100%);
clip-path: polygon(0 0, 24% 100%, 27% 100%);
}
r-border {
-webkit-clip-path: polygon(73% 0, 100% 50%, 76% 0);
clip-path: polygon(73% 0, 100% 50%, 76% 0);
}
body {
margin: 0;
}
/* changing both borders when hovering image
just showing you it's possible */
.image-container img:hover ~ * {
background-color: #f50;
}
<div class="image-container">
<img src="https://unsplash.it/1200/450" />
<l-border></l-border>
<r-border></r-border>
</div>
Depending on image ratio or even responsiveness, you might prefer px instead of %:
.image-container img {
-webkit-clip-path: polygon(0 0, calc(100% - 150px) 0, 100% 50%, 100% 100%, 150px 100%);
clip-path: polygon(0 0, calc(100% - 150px) 0, 100% 50%, 100% 100%, 150px 100%);
}
l-border {
-webkit-clip-path: polygon(0 0, 130px 100%, 150px 100%);
clip-path: polygon(0 0, 130px 100%, 150px 100%);
}
r-border {
-webkit-clip-path: polygon(calc(100% - 130px) 0, 100% 50%, calc(100% - 150px) 0);
clip-path: polygon(calc(100% - 130px) 0, 100% 50%, calc(100% - 150px) 0);
}
What I personally do is go to Clippy to get a basic shape polygon going fast (close to what I want) and fine-tune it to my needs in browser, applied to the live example until it fits the current bill.
You should note clip-path is not fully supported, currently at 88.42% support. One could say there is nothing "micro" or "soft" about the clip-path property at the moment.
I tried my best https://codepen.io/CrUsH20/pen/owWeNo
You can change stylus preprocessor in settings it'll be shown as pure CSS. You'll need to press down-arrow at middle block and select View compiled CSS.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I want to create a diagonal background image as seen in the attached image. I can create a diagonal line using linear-gradient however as I have two different angles this didn't work.
Using Linear Gradients:
This can be done using multiple background images and positioning them accordingly. In the snippet below I've used 3 different layers - one for the top angle (a triangle which is transparent for 50% and is colored for the rest), one for the middle which is essentially nothing but a solid colored rectangle, this is created using linear gradients as it is easier to control the dimensions of an image and finally one for the bottom angle (same approach as the top one but this has a different height and so different angle.)
The output is also responsive as you can see by hovering the element in the below snippet. In the 2nd div, I've set different colors for each image so that you can see how it is formed.
div {
height: 300px;
width: 100%;
background: linear-gradient(to bottom right, transparent 50%, lightblue 51%), linear-gradient(lightblue, lightblue), linear-gradient(to top right, transparent 50%, lightblue 51%);
background-size: 100% 30px, 100% calc(100% - 130px), 100% 100px;
background-position: top left, left 30px, bottom left;
background-repeat: no-repeat;
transition: all 1s ease; /* just for demo */
}
/* just for demo */
div {
margin-bottom: 10px;
}
div:hover {
height: 400px;
}
div:nth-of-type(2) {
background: linear-gradient(to bottom right, transparent 50%, lightblue 51%), linear-gradient(lightpink, lightpink), linear-gradient(to top right, transparent 50%, lightgreen 51%);
background-size: 100% 30px, 100% calc(100% - 130px), 100% 100px;
background-position: top left, left 30px, bottom left;
background-repeat: no-repeat;
}
<div></div>
<div></div>
Using SVG: recommended
This is the approach that I generally recommend and is the best. It involves creating the shape using SVG and then placing it absolutely behind the div element.
div {
position: relative;
height: 300px;
width: 100%;
}
svg {
position: absolute;
height: 100%;
width: 100%;
}
polygon {
fill: lightblue;
}
<div>
<svg viewBox='0 0 300 100' preserveAspectRatio='none'>
<polygon points='0,10 300,0 300,100 0,75z' />
</svg>
</div>
Using Clip-path:
Another approach that can be used is to position a pseudo-element behind the main div and then set a clip-path in the required shape to this pseudo-element.
Note: This snippet will currently work only in WebKit powered browsers. Firefox would need the clip-path to be created via SVG element whereas IE doesn't support it all.
div {
position: relative;
height: 300px;
width: 100%;
}
div:before {
position: absolute;
content: '';
height: 100%;
width: 100%;
background: lightblue;
-webkit-clip-path: polygon(0% 5%, 100% 0%, 100% 100%, 0% 75%);
clip-path: polygon(0% 5%, 100% 0%, 100% 100%, 0% 75%);
}
<div></div>
CSS Perspective
You can use a CSS Perspective Transform to create the shape you want.
div {
margin-top: 25px;
width: 500px;
height: 150px;
transform: perspective( 800px ) rotateY( -25deg );
background: blue;
}
<div></div>
CSS Tricks Docs
Perspective - CSS | MDN
You can apply perspective to the parent container of the rotated div to give it 3-dimensional depth from the front of the viewport.
N.B. For the difference between transform: perspective(value) and perspective: value, see the CSS Tricks Almanac entry on perspective:
Important: Please note the perspective property doesn't affect how the element is rendered; it simply enables a 3D-space for children
elements. This is the main difference between the transform: perspective() function and the perspective property. The first
gives element depth while the latter creates a 3D-space shared by all
its transformed children.
After applying a 3-dimensional depth to the parent container using perspective, you can then apply rotateY to the div you want to rotate.
Working Example:
section {
position: relative;
width: 600px;
perspective: 800px;
transform: translateX(-60px);
}
div:nth-of-type(1) {
position: absolute;
top:30px;
left: 0;
width: 100%;
height: 100px;
background-color: rgb(235,250,255);
transform: rotateY(320deg);
}
div:nth-of-type(2) {
position: absolute;
top: 0;
left: 220px;
width: 120px;
height: 140px;
background-color: rgb(103,201,236);
box-shadow: 6px 6px 6px rgba(127,127,127,0.5);
}
div:nth-of-type(3) {
position: absolute;
top: 24px;
left: 340px;
width: 120px;
height: 140px;
background-color: rgb(255,255,255);
box-shadow: 6px 6px 6px rgba(127,127,127,0.5);
}
<section>
<div></div>
<div></div>
<div></div>
</section>
Im doing the following in css:
background: linear-gradient(rgba(0, 0, 0, 0.75), rgba(0, 0, 0, 0.75)), url('../img/back.jpg') no-repeat fixed center;
i want to stretch the image to 100% 100%, how should i do so?
Use background-size: 100% 100%;.
Alternatively:
background: linear-gradient(rgba(0, 0, 0, 0.75), rgba(0, 0, 0, 0.75)), url('../img/back.jpg') no-repeat fixed center / 100% 100%;
try
background-size:100% 100% // or cover
From what I know, you cannot stretch an image in background with CSS.
To start, you can use more accurate CCS:
body {
background-image: url('../img/back.jpg');
background-repeat: no-repeat;
background-color: rgba(0, 0, 0, 0.75);
}
But the picture will not stretch with this.
An other possibility than CSS, is to use a cell of a table with a picture, in a div that is set to background:
<div class=background>
<table width=100%><TR><TR>
<img src="../img/back.jpg" width=100%></TR>
</TR></TR></table>
</div>
And in CSS, you have to create layers with different z-index:
div.background {
z-index: -1;
position: fixed;
left: 0px;
top: 0px;
float: top;}
div.notbackground {
z-index: 0;
position: absolute;
left: 0px;}
the rest of your page should be placed in the "notbackground" div to appear in higher layer, so the picture is really on background. z-index=0 is higher than z-index=-1 (you ca use any numbers). This way your picture will appear as a background.
It's possible that some advanced CSS do the trick but after a quick search on Google I still don't know.