How can I dock the slanted div to the above div?


random dude

I'm trying to add a div to another div so that its top border doesn't move when it is tilted.

HTML code:

 <div class="Container">
      <div class="Main"> </div>
      <div class="Shadow"></div>
 </div>

CSS code:

.Shadow
{
    height:70px;
    width:30px;
    transform:skew(20deg);
    background-color:lightgray;
}
.Container {
    display:inline-block;
}
.Main
{
    width:30px;
    height:100px;
    background-color:green;
}
}

violin

The following will move the border of the shadow div. Is there a way to avoid this and "dock" the upper side of the shadow div to the Maindiv so that it doesn't move (even when the "tilt" is changed in the animation)?

Thanks in advance

Harry

Yes, you can do it by using that transform-originproperty. Just set it like below to make sure the top of the shadow div is always docked to the bottom of the main div.

.Shadow {
    height:70px;
    width:30px;
    -webkit-transform:skew(20deg);
    -moz-transform:skew(20deg);
    transform:skew(20deg);
    -webkit-transform-origin: left top; /* add this setting */
    -moz-transform-origin: left top; /* add this setting */
    transform-origin: left top; /* add this setting */
    background-color:lightgray;
}

Demo | Convert Origin - MDN Spec

Related


How can I make the image "normal" in a slanted div?

Wiski So I want to make a diamond with an image, but the image is distorted. I am going to make it level (normal) and fill with diamonds. code I wrote . .diamond { width: 300px; height: 300px; border: 3px solid white; outline: 2px solid black; outlin

How can I make the image "normal" in a slanted div?

Wiski So I want to make a diamond with an image, but the image is distorted. I am going to make it level (normal) and fill with diamonds. code I wrote . .diamond { width: 300px; height: 300px; border: 3px solid white; outline: 2px solid black; outlin

How can I make the image "normal" in a slanted div?

Wiski So I want to make a diamond with an image, but the image is distorted. I am going to make it level (normal) and fill with diamonds. code I wrote . .diamond { width: 300px; height: 300px; border: 3px solid white; outline: 2px solid black; outlin

How can I make the image "normal" in a slanted div?

Wiski So I want to make a diamond with an image, but the image is distorted. I am going to make it level (normal) and fill with diamonds. code I wrote . .diamond { width: 300px; height: 300px; border: 3px solid white; outline: 2px solid black; outlin

How can I make the image "normal" in a slanted div?

Wiski So I want to make a diamond with an image, but the image is distorted. I am going to make it level (normal) and fill with diamonds. code I wrote . .diamond { width: 300px; height: 300px; border: 3px solid white; outline: 2px solid black; outlin

How can I make the image "normal" in a slanted div?

Wiski So I want to make a diamond with an image, but the image is distorted. I am going to make it level (normal) and fill with diamonds. code I wrote . .diamond { width: 300px; height: 300px; border: 3px solid white; outline: 2px solid black; outlin

How can I make a triangular div above a rectangular div?

database I am trying to create a triangle on top of a rectangular div. The triangle needs to be the width of the page and also be responsive. The top-right and top-left parts of the div (where no triangles exist) need to be transparent. I have an image of what

How to create a div with slanted text?

Mike Oberdick Okay, I've tried a lot and would like to know what you guys think. Right now, I'm using a floating control to get it working, but that's preventing me from styling the right post with flexbox. Here is what I am trying to create: This is my CSS (c

How to convert a div to a slanted perspective?

A-312 I am trying to convert a div to a green box. I want to get the 3D transform, not the mask: I found a way to use this generator , but the CSS code doesn't work for my fiddle: /*transform css3*/ #screen { transform: scale(1.0) scaleZ(1.0) rotateX(-16

How to create a div with slanted text?

Mike Oberdick Okay, I've tried a lot and would like to know what you guys think. Right now, I'm using a floating control to get it working, but that's preventing me from styling the right post with flexbox. Here is what I am trying to create: This is my CSS (c

How to convert a div to a slanted perspective?

A-312 I am trying to convert a div to a green box. I want to get the 3D transform, not the mask: I found a way to use this generator , but the CSS code doesn't work for my fiddle: /*transform css3*/ #screen { transform: scale(1.0) scaleZ(1.0) rotateX(-16

How can I move this div above the bootstrap navbar?

The road to love I'm trying to display items above the bootstrap navbar, but the navbar is showing on top of the item bar. Here is an example: $('.offerbutton').on('click', function () { $('.offertop').toggleClass('active'); }); .offertop { position: relat

How can I move this div above the bootstrap navbar?

The road to love I'm trying to display items above the bootstrap navbar, but the navbar is showing on top of the item bar. Here is an example: $('.offerbutton').on('click', function () { $('.offertop').toggleClass('active'); }); .offertop { position: relat

How to achieve a slanted right edge div?

Jamie Sexton I've been searching for a few days looking for code to skew the right edge of a div by 45 degrees. Here's an example of an image I specifically want to get... There seem to be many examples of "slope edge" divs, but I can't find one with a specifi

How to achieve a slanted right edge div?

Jamie Sexton I've been searching for a few days looking for code to skew the right edge of a div by 45 degrees. Here's an example of an image I specifically want to get... There seem to be many examples of "slope edge" divs, but I can't find one with a specifi

How to achieve a slanted right edge div?

Jamie Sexton I've been searching for a few days looking for code to skew the right edge of a div by 45 degrees. Here's an example of an image I specifically want to get... There seem to be many examples of "slope edge" divs, but I can't find one with a specifi

How to achieve a slanted right edge div?

Jamie Sexton I've been searching for a few days looking for code to skew the right edge of a div by 45 degrees. Here's an example of an image I specifically want to get... There seem to be many examples of "slope edge" divs, but I can't find one with a specifi

How to achieve a slanted right edge div?

Jamie Sexton I've been searching for a few days looking for code to skew the right edge of a div by 45 degrees. Here's an example of an image I specifically want to get... There seem to be many examples of "slope edge" divs, but I can't find one with a specifi

How can I create a slanted slanted header text next to it?

Jarcena .image { min-height: 100vh; } .bg-image { background-image: url('https://picsum.photos/1440/900'); background-size: cover; background-position: center; } <!--About Us --> <div class="container-fluid"> <div class="row no-gutter"> <div cla

How can I create a slanted slanted header text next to it?

Jarcena .image { min-height: 100vh; } .bg-image { background-image: url('https://picsum.photos/1440/900'); background-size: cover; background-position: center; } <!--About Us --> <div class="container-fluid"> <div class="row no-gutter"> <div cla

How can I create a slanted slanted header text next to it?

Jarcena .image { min-height: 100vh; } .bg-image { background-image: url('https://picsum.photos/1440/900'); background-size: cover; background-position: center; } <!--About Us --> <div class="container-fluid"> <div class="row no-gutter"> <div cla

How can I create a slanted slanted header text next to it?

Jarcena .image { min-height: 100vh; } .bg-image { background-image: url('https://picsum.photos/1440/900'); background-size: cover; background-position: center; } <!--About Us --> <div class="container-fluid"> <div class="row no-gutter"> <div cla