Is it possible to distort images in CSS? (wave effect) - css

Im developing a website and one of the requests is a division with an image, like below:
But this is what i got:
Is it possible to make it in CSS?
I already inserted the image and set the background colors, the one thing left on this is that wave effect on the image.
The CSS code, ive only set its position:
`
/* Format coffepic */
img#coffee{
position: absolute;
top: 1200px;
}
`

Yes, you can do it with clip-path property, I attached a working snippet as example. See this for further information.
img {
clip-path: polygon(100% 0%, 0% 0% , 0% 65%, 1% 64.95%, 2% 64.8%, 3% 64.6%, 4% 64.3%, 5% 63.9%, 6% 63.45%, 7% 62.9%, 8% 62.25%, 9% 61.55%, 10% 60.8%, 11% 59.95%, 12% 59.05%, 13% 58.1%, 14% 57.1%, 15% 56.05%, 16% 55%, 17% 53.9%, 18% 52.8%, 19% 51.65%, 20% 50.5%, 21% 49.35%, 22% 48.2%, 23% 47.05%, 24% 45.9%, 25% 44.8%, 26% 43.75%, 27% 42.75%, 28% 41.75%, 29% 40.8%, 30% 39.9%, 31% 39.1%, 32% 38.35%, 33% 37.65%, 34% 37.05%, 35% 36.5%, 36% 36.05%, 37% 35.65%, 38% 35.35%, 39% 35.15%, 40% 35.05%, 41% 35%, 42% 35.05%, 43% 35.2%, 44% 35.45%, 45% 35.75%, 46% 36.15%, 47% 36.65%, 48% 37.2%, 49% 37.85%, 50% 38.55%, 51% 39.35%, 52% 40.2%, 53% 41.1%, 54% 42.05%, 55% 43.05%, 56% 44.1%, 57% 45.15%, 58% 46.3%, 59% 47.4%, 60% 48.55%, 61% 49.7%, 62% 50.85%, 63% 52%, 64% 53.15%, 65% 54.25%, 66% 55.35%, 67% 56.4%, 68% 57.45%, 69% 58.4%, 70% 59.35%, 71% 60.2%, 72% 61.05%, 73% 61.8%, 74% 62.45%, 75% 63.05%, 76% 63.6%, 77% 64.05%, 78% 64.4%, 79% 64.7%, 80% 64.85%, 81% 65%, 82% 65%, 83% 64.9%, 84% 64.75%, 85% 64.5%, 86% 64.2%, 87% 63.75%, 88% 63.25%, 89% 62.7%, 90% 62.05%, 91% 61.3%, 92% 60.5%, 93% 59.65%, 94% 58.75%, 95% 57.8%, 96% 56.8%, 97% 55.75%, 98% 54.65%, 99% 53.55%, 100% 52.4%);
}
<img src="https://previews.123rf.com/images/vandycandy/vandycandy1501/vandycandy150100067/35546889-coffee-grains.jpg" width="100%"/>

I have an online generator for such shape: https://css-generators.com/wavy-shapes/.
All you need is to select the top/bottom configuration, adjust the size and you get the code. I simply updated (manually) the position of the top wave to get the alignment you want.
.box {
height: 200px;
background: url(https://previews.123rf.com/images/vandycandy/vandycandy1501/vandycandy150100067/35546889-coffee-grains.jpg) 50%/cover;
--mask:
radial-gradient(51.22px at 50% 72.00px,#000 99%,#0000 101%) 50% 0/160px 51% repeat-x,
radial-gradient(51.22px at 50% -32px,#0000 99%,#000 101%) calc(50% - 80px) 40px/160px calc(51% - 40px) repeat-x,
radial-gradient(51.22px at 50% calc(100% - 72.00px),#000 99%,#0000 101%) calc(50% - 80px) 100%/160px 51% repeat-x,
radial-gradient(51.22px at 50% calc(100% + 32.00px),#0000 99%,#000 101%) 50% calc(100% - 40px)/160px calc(51% - 40px) repeat-x;
-webkit-mask: var(--mask);
mask: var(--mask);
}
<div class="box"></div>

Related

CSS Clip-Path Generator not working for me

How to fit my image in the correct position? I just straight away copy the code from CSS path maker through website. But I couldn’t resize the image from my actual image in HTML. May I know what are the codes that needed or any way to fix the image?
My Code script
.brazilimg{
background-image:url("image/brazil.jpg");
clip-path: polygon(20% 0%, 80% 0%, 100% 20%, 100% 80%, 80% 100%, 20% 100%, 0% 80%, 0% 20%);
width: 280px;
height:280px;
margin-top:400px; margin-left:60px; }
[my code script][1]
[CSS Clip Path Generator][2]
My final outcome after entering the code
The original image that I want to create image clipping
Your CSS is clipping the image but the image is not centred within the div so you get just the top part. Also there is a large top margin which means you just see the top part, as shown in your image in the question. Here's the whole clipped image - as you see, just the top part.
If we add to the .brazilimg class something that tells the system to center the image within the div, clipping the right and left sides so as to maintain the image's aspect ratio, we see the correct image. background-size: cover; is what we have added.
Here is a snippet showing the problem before the image is centred, but with the large top margin commented out so we see the whole image:
.brazilimg{
background-image:url("https://i.stack.imgur.com/bUUz7.jpg");
clip-path: polygon(20% 0%, 80% 0%, 100% 20%, 100% 80%, 80% 100%, 20% 100%, 0% 80%, 0% 20%);
width: 280px;
height:280px;
/*margin-top:400px;*/
margin-left:60px;
}
<div class="brazilimg"></div>
And here is a snippet with the cover added to centralise the image:
.brazilimg{
background-image:url("https://i.stack.imgur.com/bUUz7.jpg");
clip-path: polygon(20% 0%, 80% 0%, 100% 20%, 100% 80%, 80% 100%, 20% 100%, 0% 80%, 0% 20%);
width: 280px;
height:280px;
/*margin-top:400px;*/
margin-left:60px;
/* added to ensure the image is centrally located */
/* and make this CSS class more general for different images' aspect ratios */
background-size: cover;
}
<div class="brazilimg"></div>

How to make a CSS3 Clip Path

I want to make figure 1
like as figure 2
using clip path, is it possible?
thanks.
clip-path is still a very experimental CSS3 element and therefore isn't very well supported and what support there is is minimal.
Using the CSS3 clip-path element to generate the polygon only allows for straight corners as its all point based rather than allowing for curves.
Heres an example:
body {
background: #555;
margin: 0;
}
img {
-webkit-clip-path: polygon(98% 0, 100% 2%, 100% 88%, 98% 90%, 25% 90%, 20% 99%, 15% 90%, 2% 90%, 0 88%, 0 2%, 2% 0);
clip-path: polygon(98% 0, 100% 2%, 100% 88%, 98% 90%, 25% 90%, 20% 99%, 15% 90%, 3% 90%, 0 88%, 0 2%, 2% 0);
}
<img src="http://lorempixel.com/200/200/" />
Your best alternative would be to use an actual SVG element and reference it within the CSS to do the cut out. If you want a perfect shape but sadly no support on IE, this is the way to go.
SVG Only Version
body {
background: #555;
margin: 0;
}
img {
clip-path: url(#svgPath);
-webkit-clip-path: url(#svgPath);
}
<svg height="0" width="0">
<defs>
<clipPath id="svgPath">
<path fill="#FFFFFF" d="M50,0 L450,0 Q500,0 500,50 L500,400 Q500,450 450,450 L200,450 L175,500 L150,450 L50,450 Q0,450 0,400 L0,50 Q0,0 50,0z" />
</clipPath>
</defs>
</svg>
<img src="http://lorempixel.com/500/500/" />

Image inside triangle css?

I'd like to achieve a custom image triangle shape with rounded corner like this using css
I looking for how achieve like this but nothing,
i want to achieve my css can do result like this,any ideas?
Sorry if my question has looks like other question
Thanks
You could use clip-path. It allows you to show only part of an element and hide the rest, so make a polygon with sufficient dots for the rounded effect at corners.
.tri {
position: relative;
width: 130px;
height: 130px;
background: url("http://pdphoto.org/images/tacos.jpg");
clip-path: polygon(1% 78%, 46% 2%, 49% 0, 54% 0, 57% 2%, 98% 78%, 98% 83%, 95% 87%, 89% 88%, 6% 89%, 2% 87%, 0 83%);
}
<div class="tri"></div>

Is it possible to make backgound repeat from bottom left corner of screen to top right?

I have some image pattern, and I want it to strike an element(e.g. body). I could create pseudo element with background and rotate it for n degree, but it's a bad solution because I don't know proportions of the block.
Any ideas how I could achieve it using CSS only?
While there isn't a CSS property that does what you want, it can be hacked in.
It's a bit ugly and it's not a real repeat, but it might work for you.
HTML:
<div class="container"></div>​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​
CSS:
.container {
width: 500px;
height: 500px;
background-image:
url("http://i.stack.imgur.com/R5Ux6.png"),
url("http://i.stack.imgur.com/R5Ux6.png"),
url("http://i.stack.imgur.com/R5Ux6.png"),
url("http://i.stack.imgur.com/R5Ux6.png"),
url("http://i.stack.imgur.com/R5Ux6.png"),
url("http://i.stack.imgur.com/R5Ux6.png"),
url("http://i.stack.imgur.com/R5Ux6.png"),
url("http://i.stack.imgur.com/R5Ux6.png"),
url("http://i.stack.imgur.com/R5Ux6.png"),
url("http://i.stack.imgur.com/R5Ux6.png"),
url("http://i.stack.imgur.com/R5Ux6.png");
background-position:
0% 100%,
10% 90%,
20% 80%,
30% 70%,
40% 60%,
50% 50%,
60% 40%,
70% 30%,
80% 20%,
90% 10%,
100% 0%;
background-repeat: no-repeat;
}​
http://jsfiddle.net/z4FD3/
Here I repeated the same image 10 times. You can do it as many times as you want, just add more lines and smaller intervals between the positions (e.g.: 0% 100%, 2% 98%, 4% 96%).
why not making a pattern that will look like it goes slant like the example above

Screen Resolution & Web Page Problems?

When I change my screen resolution to 800x600, 640x480 and so on half my web page gets cut off including images I cant even use the scroll bar at all to see the rest of the page, I'm using percentages as well as pixels using CSS. Need help fixing? All browsers are affected. Here is a sample.
#top {
background: #424ee0;
margin: 0px;
padding: 0px;
width: 100%;
overflow: hidden;
}
#center-top {
margin: 0px;
padding: 5px 0px 5px 0px;
width: 1200px;
margin: 0 auto;
text-align: center;
overflow: hidden;
color: orange;
}
You have:
overflow: hidden;
Specified in top. Top also has:
width: 100%.
This means that it's set to 100% of the container. If center-top is contained by top, then its width is likely way more than 100% of the container (top). Overflow:hidden then overrides to scrollbar and hides all overflow.
If you want it to be visible either:
remove "overflow: hidden".
change it to "overflow: auto".
Something else:
You're explicitly setting width to 1200px. This means that anyone who has a horizontal resolution of less than 1200px, they will see scrollbars. Is that really what you want? Consider choosing a smaller width.
Before you try to fix your web page, have a look at these
Screen resolution statistics
Posted by Michael Bloch in web development (Sunday September 23, 2007 )
http://www.tamingthebeast.net/blog/web-development/screen-resolution-statistics-0907.htm
1 - 44.55% - 1024×768
2 - 13.98% - 1280×1024
3 - 12.43% - 1280×800
4 - 7.31% - 800×600
5 - 4.76% - 1440×900
6 - 3.47% - 1152×864
7 - 2.71% - 1680×1050
8 - 1.72% - 1280×768
9 - 0.97% - 1920×1200
10 - 0.81% - 1280×960
Note that 800 x 600 is only used by 7% of internet users and 640 x 480 didn't even make the list. That was in 2007. The author noted that 800 x 600 was rapidly dropping in popularity at that time.
Here's a chart that more clearly shows the trends:
Date Higher 1024x768 800x600 640x480 Unknown
January 2009 57% 36% 4% 0% 3%
January 2008 38% 48% 8% 0% 6%
January 2007 26% 54% 14% 0% 6%
January 2006 17% 57% 20% 0% 6%
January 2005 12% 53% 30% 0% 5%
January 2004 10% 47% 37% 1% 5%
January 2003 6% 40% 47% 2% 5%
January 2002 6% 34% 52% 3% 5%
January 2001 5% 29% 55% 6% 5%
January 2000 4% 25% 56% 11% 4%
http://www.w3schools.com/browsers/browsers_display.asp

Resources