Custom Link Shape and Animation with Clip-Path [duplicate] - html

This question already has answers here:
Setting the width of inline elements
(7 answers)
Closed 2 years ago.
I have recently been learning about the magical properties of clip-path in CSS, but I ran into a problem when trying to create a custom image link. I have been unable to get the actual shape to be a clickable link.
When I try and place an <a> within the clipped div, the shape itself will not be clickable - even if I set it to the same dimensions as it's parent div. This is my reference site for the linkable clip-path ( https://css-tricks.com/the-many-ways-to-link-up-shapes-and-images-with-html-and-css/ ).
I am wondering if it's not able to be a link since it has an animation upon mouse hover? Here is my code snippet.
/* Styles the link */
#inner-link {
width: 200px;
height: 200px;
}
/* Styles the parent container */
#button-container {
width: 200px;
height: 200px;
margin: 10%;
background-color: #ed991c;
clip-path: polygon(50% 0%, 100% 100%, 0% 100%, 0% 100%, 0% 100%, 0% 100%, 0% 100%);
}
#button-container:hover {
animation: arrow 0.5s forwards;
}
/* animation from triangle to arrow */
#keyframes arrow {
0% {
clip-path: polygon(50% 0%, 100% 100%, 0% 100%, 0% 100%, 0% 100%, 0% 100%, 0% 100%);
background-color: #ed991c;
}
100% {
clip-path: polygon(30% 0%, 100% 50%, 30% 100%, 30% 75%, 0% 75%, 0% 25%, 30% 25%);
background-color: #edd11c;
}
}
<div id="button-container">
<a id="inner-link" href="https://www.target.com/"><a>
</div>

a tag is an inline element, and inline elements don't have heights or widths.
A quick fix would be to add display: block or display: inline-block to your #inner-link.
#inner-link {
width: 200px;
height: 200px;
display: block;
}
#inner-link {
width: 200px;
height: 200px;
display: block;
}
/* Styles the parent container */
#button-container {
width: 200px;
height: 200px;
margin: 10%;
background-color: #ed991c;
clip-path: polygon( 50% 0%, 100% 100%, 0% 100%, 0% 100%, 0% 100%, 0% 100%, 0% 100%);
}
#button-container:hover {
animation: arrow 0.5s forwards;
}
/* animation from triangle to arrow */
#keyframes arrow {
0% {
clip-path: polygon( 50% 0%, 100% 100%, 0% 100%, 0% 100%, 0% 100%, 0% 100%, 0% 100%);
background-color: #ed991c;
}
100% {
clip-path: polygon( 30% 0%, 100% 50%, 30% 100%, 30% 75%, 0% 75%, 0% 25%, 30% 25%);
background-color: #edd11c;
}
}
<div id="button-container">
<a id="inner-link" href="https://www.target.com/"></a>
</div>

Related

Weird drop-shadow on certain backgrounds

I applied a drop-shadow filter on my clip-path, while the shadow works well on white background, it does not work at all on a darker one (example below) -
It just looks like some weird lines instead of a blurred shadow, The shadow is a bit darker then the background, making the shadow completly black makes it work at the start of the shadow but to the end it has these lines once again.
The code:
body {
margin: 0;
overflow-x: hidden;
height: 2000px;
}
body .headerText {
position: absolute;
top: 50vh;
left: 40vw;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
font-size: 8vh;
z-index: 10;
color: white;
mix-blend-mode: exclusion;
}
body .headerWrap {
position: fixed;
filter: drop-shadow(-30px -30px 60px #363636) drop-shadow(-30px -30px 90px #414141);
-webkit-filter: drop-shadow(-30px -30px 60px #363636) drop-shadow(-30px -30px 90px #414141);
}
body .headerWrap header {
position: fixed;
width: 100vw;
height: 100vh;
background-color: #2e2e2e;
-webkit-clip-path: polygon(0% 0%, 40% 0%, 28% 100%, 0% 100%);
clip-path: polygon(0% 0%, 40% 0%, 28% 100%, 0% 100%);
-webkit-animation: rotate 1s 1;
animation: rotate 1s 1;
-webkit-animation-play-state: paused;
animation-play-state: paused;
-webkit-animation-fill-mode: forwards;
animation-fill-mode: forwards;
-webkit-animation-delay: calc(var(--scroll) * -3s);
animation-delay: calc(var(--scroll) * -3s);
}
#-webkit-keyframes rotate {
to {
-webkit-clip-path: polygon(0% 0%, 20% 0%, 14% 100%, 0% 100%);
clip-path: polygon(0% 0%, 20% 0%, 14% 100%, 0% 100%);
}
}
#keyframes rotate {
to {
-webkit-clip-path: polygon(0% 0%, 20% 0%, 14% 100%, 0% 100%);
clip-path: polygon(0% 0%, 20% 0%, 14% 100%, 0% 100%);
}
}
body .landing {
width: 100vw;
height: 100vh;
background-color: white;
}
body .content {
width: 100vw;
height: 200vh;
background-color: #424242;
}
<html lang="en">
<head>
</head>
<body>
<div class="headerText"><h1>Hello bruddas</h1></div>
<div class="headerWrap">
<header></header>
</div>
<script>
window.addEventListener('scroll', () => {
document.body.style.setProperty('--scroll',window.pageYOffset / (document.body.offsetHeight - window.innerHeight));
}, false);
</script>
<div class="landing"></div>
<div class="content"></div>
</body>
Answer
The shadow works fine on both colors.
You can barely (or not...) see it, but it's there.
The lines are in fact the shadow.
The problem here, is the low amount of colors rendered by the screen due to the low contrast between the darkest and lightest colors (for the dark one).
Screens have a limited amount of colors. It also depends on the screen type and settings, sometimes you can easily see it (and it's ugly), sometimes you can barely notice that behavior (you just see a smooth gradient).
Example
Here is an example:
Notice I used the same shadow for both sides.
You should be able to see the lines on darker tones (the top of the left side, and all the right side). Maybe you cannot see the lines at all, again, it depends on the output device and settings.

CSS Shape for Div mentioned in the Image

I have 2 images of CSS Div Shape. I want to make my DIVs like in the image.
Any help would be great.
.imageOne {
clip-path: polygon(0 0, 100% 0%, 100% 11%, 0 0);
height: 100px;
background: blue;
}
.imageTwo {
clip-path: polygon(80% 30%, 100% 41%, 100% 41%, 0 40%, 0 40%);
height: 100px;
background: blue;
}
<div class="imageOne">
</div>
<div class="imageTwo">
</div>
You can adjust the like below:
.imageOne {
clip-path: polygon(0 0, 100% 0%, 100% 100%, 0 40%); /* adjust the 40% here */
height: 100px;
background:
linear-gradient(to bottom left,transparent 49%,#b3e1ff 50%)
bottom left/200% 60% /* adjust the 200% here, 60% = 100% - 40% (from the top) */
no-repeat
#e1f4ff;
}
.imageTwo {
/* here ----v v---- and here the same */
clip-path: polygon(100% 100%,100% 70%, 80% 0, 0 70%,0 100%);
/* adjust this to control the top ----^ */
height: 100px;
background: #e1f4ff;
}
<div class="imageOne">
</div>
<div class="imageTwo">
</div>

struggling to give shape to div same as image shape

I have one image with drop-shadow and I want text at the bottom of the image with overlay class named img_text which takes the same shape as image. I don't know how to create this.
Can anyone help me how to achieve this?
Here I have attached what I want.
Here is my code in pen that I have done.
The issue is, a child element cannot be related to it's parents background, the two shapes are independent of each other.
This is a classical HTML challenge, when table layouts were pulled together with interactive effects, to use more images in more colourful images with Photoshop filters applied to text menu items or gifs.
As Basil suggested an additional image could provide the illusion that the two shapes are related, alternatively the base image could look as required, then only one line of label may be provided.
This CSS may be applied:
backdrop-filter: sepia(.9) hue-rotate(0deg)
Rather than the background on .images_div .img_text
Play around with the hue-rotate to see if you can make the same orange.
The only way to achieve this is by using an image background that have the same shape with less opacity like this one instead of this background-color: rgba(0,0,0,0.5);.
You can try this code
CSS code
* {
box-sizing: border-box;
}
.container {
position: relative;
}
.container p {
position: absolute;
bottom: 0px;
left: 0px;
right: 0px;
overflow: hidden;
background-color: rgba(0,0,0,0.5);
color: #F2F2F2;
font-size: 22px;
text-align: center;
background-color: red;
width: 180px;
display: block;
padding: 10px 15px;
text-align: center;
text-transform: uppercase;
color: #fff;
}
.container .image_sec_img p:hover{
background-color: rgba(248,105,60,0.75);
}
.one{
margin-left: 16px;
}
and the html code
<div class="container">
<div class="image_sec_img">
<img src="https://i.stack.imgur.com/Xcapo.png">
<p class="one">Hello</p>
</div>
</div>
Try to implement this way.
.image_box {
display: inline-block;
clip-path: polygon(0% 100%, 0% 5%, 10% 3%, 20% 1.7%, 35% 0.4%, 50% 0%, 65% 0.4%, 80% 1.7%, 90% 3%, 100% 5%, 100% 93%, 90% 95.7%, 80% 97.7%, 70% 99.2%, 60% 99.9%, 50% 100%, 40% 99.3%, 30% 97.7%, 20% 95.9%, 10% 95.3%, 0% 96%);
padding: 0px 0px 4px 5px;
position: relative;
}
.image_box:before {
background-color: #f8693c;
left: 0px;
top: 20px;
bottom: 0;
right: 5px;
position: absolute;
content: "";
}
.content {
position: absolute;
bottom: 0;
left: 0px;
right: 0px;
background-color: rgba(248, 105, 60, 0.9);
color: #fff;
padding: 15px 15px 30px 25px;
clip-path: polygon(0% 0%, 100% 0%, 100% 93%, 90% 95.7%, 80% 97.7%, 70% 99.2%, 60% 99.9%, 50% 100%, 40% 99.3%, 30% 97.7%, 20% 95.9%, 10% 95.3%, 0% 96%);
}
.image_box img {
display: block;
clip-path: polygon(0% 100%, 0% 5%, 10% 3%, 20% 1.7%, 35% 0.4%, 50% 0%, 65% 0.4%, 80% 1.7%, 90% 3%, 100% 5%, 100% 93%, 90% 95.7%, 80% 97.7%, 70% 99.2%, 60% 99.9%, 50% 100%, 40% 99.3%, 30% 97.7%, 20% 95.9%, 10% 95.3%, 0% 96%);
}
<div class="image_box">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcT6lRhSay69skaUU-y9M7J_drwez_QBJTPholjizBmGbfJbLYVH&s">
<div class="content">
Image Title
</div>
</div>
Hope this will works fine for you.
Thank you...
here you go miss Akshita sorry for my side
css
.cont1 {
display: inline-block;
clip-path: polygon(0% 100%, 0% 5%, 10% 3%, 20% 1.7%, 35% 0.4%, 50% 0%, 65% 0.4%, 80% 1.7%, 90% 3%, 100% 5%, 100% 93%, 90% 95.7%, 80% 97.7%, 70% 99.2%, 60% 99.9%, 50% 100%, 40% 99.3%, 30% 97.7%, 20% 95.9%, 10% 95.3%, 0% 96%);
padding: 0px 0px 4px 5px;
position: absolute;
}
.cont1:before {
background-color: #f8693c;
left: 0px;
top: 40px;
bottom: 0;
right: 5px;
position: absolute;
content: "";
}
.text1{
position: absolute;
bottom: 0;
left: 0px;
right: 0px;
background-color: rgba(248, 105, 60, 0.9);
color: #fff;
text-align: center;
padding: 15px 15px 30px 25px;
clip-path: polygon(0% 0%, 100% 0%, 100% 93%, 90% 95.7%, 80% 97.7%, 70% 99.2%, 60% 99.9%, 50% 100%, 40% 99.3%, 30% 97.7%, 20% 95.9%, 10% 95.3%, 0% 96%);
}
.cont1 img {
display: block;
clip-path: polygon(0% 100%, 0% 5%, 10% 3%, 20% 1.7%, 35% 0.4%, 50% 0%, 65% 0.4%, 80% 1.7%, 90% 3%, 100% 5%, 100% 93%, 90% 95.7%, 80% 97.7%, 70% 99.2%, 60% 99.9%, 50% 100%, 40% 99.3%, 30% 97.7%, 20% 95.9%, 10% 95.3%, 0% 96%);
}
html
<div class="cont1">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcT6lRhSay69skaUU-y9M7J_drwez_QBJTPholjizBmGbfJbLYVH&s">
<div class="text1">
Hello
</div>
</div>

How to make a border around clip path shape? [duplicate]

This question already has answers here:
Hexagon shape with a border/outline
(7 answers)
Closed 3 years ago.
I am trying to create hexagon shaped buttons that have a transparent background and white 1px solid border around the hexagon I created with clip path. However, when I apply a border part of it is cut off. How can I achieve this look?
Here is my code:
.project-button div{
position: relative;
display: inline-block;
padding: 1rem;
margin: 0 1rem 1rem 1rem;
color: #d9d9d9;
font-size: 1rem;
font-weight: 700;
border: 1px solid white;
-webkit-clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
background-repeat: no-repeat;
transition: background-size .5s, color .5s;
}
.to-top {
background-position: 50% 100%;
background-size: 100% 0%;
}
.project-button div:hover {
background-size: 100% 100%;
background-image: linear-gradient(white, white);
color: #51d0de;
}
<div class="project-button">
<div class="to-top>View Code"></div>
</div>
This is what i Got so far,
I've used filter: drop-shadow()
For your transparent background you can use same color as parent
.hexagon{
background: white;/*giving color is important*/
padding: 40px;
width: 20%;
text-align: center;
clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
}
/* main code */
.container{
filter: drop-shadow(0px 0px 1px black);
}
<div class="container">
<div class="hexagon">Button</div>
</div>
I hope it helps.
Note: filter is used on parent div.

pseudo-element affect clip-path

I'm trying to do something seemingly easy but its not working out for me.
I have a simple button with a shimmer hover effect. I want have the same button effect applied to a button that is shaped like a hexagon. I thought I'd be pragmatic and just overlay the button with a clip-path (I don't care about the browser support). but, sadly the pseudo-element affect the clip-path making it unusable. Am I missing something simple? Or will the combination of these two never work?
.button {
outline:none;
border:none;
padding:20px;
display:block;
margin:0 auto;
cursor:pointer;
font-size:16px;
font-weight: bold;
background-color:#DBBD68;
text-transform: uppercase;
position:relative;
transition:all 0.5s ease;
overflow: hidden;
color:#fff;
&.hex{
width: 280px;
height: 280px;
position:absolute;
top: 0;
left:0;
-webkit-clip-path: polygon(20% 50%, 12% 60%, 20% 70%, 82% 70%, 89% 60%, 80% 50%);
clip-path: polygon(20% 50%, 12% 60%, 20% 70%, 82% 70%, 89% 60%, 80% 50%);
}
&:before {
content: '';
background-color: rgba(255,255,255,.5);
width:100%;
height:20px;
position:absolute;
left:-135px;
transform: rotateZ(45deg)
}
I made a Fiddle to showcase the issue: https://jsfiddle.net/0m5wmvu8/
You tried to do something crazy with .hex, but the only thing you should have added was the clip-path. Just change it to:
&.hex{
-webkit-clip-path: polygon(50% 0, 80% 0, 100% 50%, 80% 100%, 20% 100%, 0 50%, 20% 0);
clip-path: polygon(50% 0, 80% 0, 100% 50%, 80% 100%, 20% 100%, 0 50%, 20% 0);
}
https://jsfiddle.net/8sfc3ott/