I’m making a diamond shape for a user’s image with the help of this CodePen demo.
But when I change the width and height according to my content the shape will disturb: see my JSFiddle Demo.
In the selector .losange, .losange div the original values for width and height are both 250px and in .losange .los1 they’re both 355px.
Here is my code:
.losange, .losange div {
margin: 0 auto;
transform-origin: 50% 50%;
overflow: hidden;
width: 130px; /* originally 250px */
height: 130px; /* originally 250px */
}
.losange {
transform: rotate(45deg) translateY(10px);
}
.losange .los1 {
width: 130px; /* originally 355px */
height: 130px; /* originally 355px */
transform: rotate(-45deg) translateY(-74px);
}
.losange .los1 img {
width: 100%;
height: auto;
}
You need to calculate right translate values:
.losange, .losange div {
margin: 0 auto;
transform-origin: 50% 50%;
overflow: hidden;
width: 92px;
height: 92px;
}
.losange {
transform: rotate(45deg) translateY(10px) translateX(10px);
}
.losange .los1 {
width: 130px;
height: 130px;
transform: rotate(-45deg) translateY(-27px);
}
.losange .los1 img {
width: 100%;
height: auto;
}
<div class="losange">
<div class="los1">
<img src="http://photos-d.ak.instagram.com/hphotos-ak-xpa1/10483342_1471091656483347_532843009_n.jpg" />
</div>
</div>
UPDATE:
Changed sizes - now Losange width is 130 pixels.
Related
i have this, and i would like to keep the img normal and rotate the div to a parallelogram, which i managed like this
.parallelogram {
width: 180px;
height: 60px;
overflow: hidden;
-webkit-transform: skew(-21deg);
-moz-transform: skew(15deg);
-o-transform: skew(15deg);
position: relative;
}
.img {
position: absolute;
width: 440px;
height: 150px;
-webkit-transform: skew(21deg);
-moz-transform: skew(-15deg);
-o-transform: skew(-15deg);
left: 10px;
top: -10px;
}
<div class="parallelogram">
<div class="img">
<img src="https://archive.org/download/AILS-A79-7082/A79-7082.jpg" alt="">
</div>
</div>
My problem is that the img keeps its parent width.
even though i ask it to be 440px its 180px. and i dont understand why.
I tried with vw, and % and none of it works!
Thank you in advance
.parallelogram {
width: 180px;
height: 60px;
overflow: hidden;
-webkit-transform: skew(-21deg);
-moz-transform: skew(15deg);
-o-transform: skew(15deg);
position: relative;
background-color:blue;/*added for testing*/
}
.img {
position: absolute;
width: 440px;
height: 150px;
-webkit-transform: skew(21deg);
-moz-transform: skew(-15deg);
-o-transform: skew(-15deg);
left:-20px;
right:0px;
top:-10px;
background-color:red;/*added for testing*/
opacity: 0.5;/* makes overlap area purple*/
}
<div class="parallelogram">
<div class="img">
<img..../>
</div>
</div>
I made left:-20px; and right:0px; to make the img appear like parallelogram.
I found this Is there are way to make a child DIV's width wider than the parent DIV using CSS? so I wanted to give it try. I hope this helps.
For the image to take the width of the .img div, you also need this rule, since the <img> tag is a child of the div with class .img:
.img img {
width: 100%;
height: auto;
}
(height: auto; is actually not necessary, since it's the default)
ADDITION AFTER COMMENT:
You have to remove overflow: hidden; from the outer DIV:
.parallelogram {
width: 180px;
height: 60px;
-webkit-transform: skew(-21deg);
-moz-transform: skew(15deg);
-o-transform: skew(15deg);
position: relative;
background-color: blue;
/*added for testing*/
}
.img {
position: absolute;
width: 440px;
height: 150px;
-webkit-transform: skew(21deg);
-moz-transform: skew(-15deg);
-o-transform: skew(-15deg);
left: -20px;
right: 0px;
top: -10px;
background-color: red;
/*added for testing*/
opacity: 0.5;
/* makes overlap area purple*/
}
.img img {
width: 100%;
height: auto;
}
<div class="parallelogram">
<div class="img">
<img src="http://placehold.it/180x60/#0d0"/>
</div>
</div>
I am trying to make a responsive cuboid using HTML/CSS but the right face of the cuboid is not aligning with the remaining faces.
Can anyone help me out with this?
I am pasting a jsfiddle link for the same, below:
#container {
width: 100vw;
height: 100vh;
perspective: 1000px;
perspective-origin: 50% 50%;
}
#container div {
height: 100vh;
/*width: 100%;*/
position: absolute;
/*display: inline-block;*/
transform-origin: 50% 50%;
transform-style: preserve-3d;
}
#left {
width: 100vh;
background: steelblue;
transform: translateX(-50vh) translateZ(-50vh) rotateY(90deg);
}
#right {
width: 100vh;
background: teal;
transform: translateX(50vw) rotateY(-90deg);
}
#floor {
width: 100%;
background: #55DF03;
transform: translateY(50vh) translateZ(-50vh) rotateX(90deg);
}
#ceil {
width: 100%;
background: grey;
transform: translateY(-50vh) translateZ(-50vh) rotateX(90deg);
}
#back {
width: 100%;
background: #2091FE;
transform: translateZ(-100vh);
}
<div id="container">
<div id="left"></div>
<div id="floor"></div>
<div id="right"></div>
<div id="ceil"></div>
<div id="back"></div>
</div>
https://jsfiddle.net/srikanthaero/4s8wovjm/
Here is the responsive 3D Cuboid face:
#container {
width: 100vw;
height: 100vh;
perspective: 1000px;
perspective-origin: 50% 50%;
}
#container div {
height: 100vh;
/*width: 100%;*/
position: absolute;
/*display: inline-block;*/
transform-origin: 50% 50%;
transform-style: preserve-3d;
}
#left {
width: 100vh;
background: steelblue;
transform: translateX(-50vh) translateZ(-50vh) rotateY(90deg);
}
#right {
width: 100vh;
background: teal;
transform: translateX(0%) rotateY(-90deg);
right: 0px;
TRANSFORM-ORIGIN: 100% 100% !important;
}
#floor {
width: 100%;
background: #55DF03;
transform: translateY(50vh) translateZ(-50vh) rotateX(90deg);
}
#ceil {
width: 100%;
background: grey;
transform: translateY(-50vh) translateZ(-50vh) rotateX(90deg);
}
#back {
width: 100%;
background: #2091FE;
transform: translateZ(-100vh);
}
<div id="container">
<div id="left"></div>
<div id="floor"></div>
<div id="right"></div>
<div id="ceil"></div>
<div id="back"></div>
</div>
I have changed the way to move the elements, it's easier to change the transform origin that to play with translates:
body {
margin: 0px;
}
#container {
width: 100vw;
height: 100vh;
perspective: 1000px;
perspective-origin: 50% 50%;
}
#container div {
height: 100vh;
width: 100vw;
position: absolute;
transform-style: preserve-3d;
}
#container #left {
width: 100vh;
background: steelblue;
transform-origin: left center;
transform: rotateY(90deg);
}
#container #right {
width: 100vh;
background: teal;
transform-origin: right center;
transform: rotateY(-90deg);
right: 0px;
}
#floor {
width: 100%;
background: #55DF03;
transform: translateY(50vh) translateZ(-50vh) rotateX(90deg);
}
#ceil {
width: 100%;
background: grey;
transform: translateY(-50vh) translateZ(-50vh) rotateX(90deg);
}
#back {
width: 100%;
background: #2091FE;
transform: translateZ(-100vh);
opacity: 0.5;
}
<div id="container">
<div id="left"></div>
<div id="floor"></div>
<div id="right"></div>
<div id="ceil"></div>
<div id="back"></div>
</div>
On a side note, you are asking:
For left face, when I use 'translateX(-50vh)', it aligns perfectly. But I felt that it should have aligned on 'translateX(-50vw)'. How '-50vh' is sufficient?
The left side has a width of 100vh. The transform origin is center, so the rotation of 90deg is made around a point that is 50vh (the half of 100vh) to the right of the left border of the element. To make it fit, you need to translate in X minus this amount.
Also, if you want to keep your original way of work, the right style should be
#right {
width: 100vh;
background: teal;
right: 0px;
transform: translateX(50vh) translateZ(-50vh) rotateY(-90deg);
}
Notice that positioning it to the right simplifies a lot the problem.
Using CSS, I am trying to create a rectangular prism with rounded edges like those in the photo below.
So far, I have specified the border radius for the top and bottom sides. The problem is that I do not know a way to get the left and right edges of the other sides to curl inwards. As a result, there should not be any holes at the corners. Is there a certain CSS property or trick I could use to do that?
Code from https://jsfiddle.net/jkantner/oqo73a2h/:
.cube {
top: 100px;
left: 100px;
position: relative;
transform-style: preserve-3d;
transform: rotateX(30deg) rotateY(-45deg);
}
.left, .right, .front, .top, .back, .bottom {
position: absolute;
}
.left, .right {
background: #06a;
width: 150px;
height: 150px;
}
.front, .back {
background: #048;
width: 300px;
height: 150px;
}
.top, .bottom {
background: #08c;
border-radius: 30px;
width: 300px;
height: 150px;
}
.front {
z-index: 2;
}
.top {
transform-origin: 0% 100%;
transform: translateY(-150px) rotateX(-90deg);
z-index: 2;
}
.left {
transform-origin: 100% 100%;
transform: translateX(-150px) rotateY(90deg);
z-index: 2;
}
.right {
transform-origin: 0% 0%;
transform: translateX(300px) rotateY(-90deg);
}
.back {
transform: translateZ(150px);
}
.bottom {
transform-origin: 0% 0%;
transform: translateY(150px) rotateX(90deg);
}
<div class='cube'>
<div class='front'></div>
<div class='top'></div>
<div class='left'></div>
<div class='right'></div>
<div class='back'></div>
<div class='bottom'></div>
</div>
If you specify the border-radius for the left and right sides and the front and back sides, just as you did for the top and bottom:
.left, .right {
background: #06a;
border-radius: 30px;
width: 150px;
height: 150px;
}
.front, .back {
background: #048;
border-radius: 30px;
width: 300px;
height: 150px;
}
You will get a rounded rectangular prism, as seen here.
div.scroll {
position:absolute;
-moz-transform: rotate(-7deg);
-ms-transform: rotate(-7deg);
-o-transform: rotate(-7deg);
-webkit-transform: rotate(-7deg);
background-color: #00FFFF;
width: 190px;
height: 250px;
overflow: scroll;
z-index:1;
margin:0 auto;
left:220px;
top:68px;
}
size {
max-width: 100%;
max-height:100%;
}
<div class="size"><div class="scroll"><iframe src="http://www.kopfkino-kollektiv.de"></iframe></div></div>
Im coding a portfolio site and i have a problem with iframe.
wether it has my given ratio OR it is responsive! i need both! as you can see in the screenshot i need to hover the iframe exaxtly over the ipads screen at all time ! can you guys help me?
HTML
<div class="size"><div class="scroll"><iframe src="http://www.kopfkino-kollektiv.de"></iframe></div></div>
CSS
div.scroll {
position:absolute;
-moz-transform: rotate(-7deg);
-ms-transform: rotate(-7deg);
-o-transform: rotate(-7deg);
-webkit-transform: rotate(-7deg);
background-color: #00FFFF;
width: 190px;
height: 250px;
overflow: scroll;
z-index:1;
margin:0 auto;
left:220px;
top:68px;
}
size {
max-width: 100%;
max-height:100%;
}
SCREENSHOT
now
should
Style the iframe to take up 100% width and height of parent container, and
Fix parent .scroll container to remove forced scrollbars via scroll:auto and either remove the whitespace or use font-size:0 to prevent issues caused by the whitespace in your markup (otherwise two sets of scrollbars may appear).
Adjust the iframe margin or position as needed to get the correct overlay. But you didn't include link to background image, so I can't show you this until you do that.
div.scroll {
position: absolute;
-moz-transform: rotate(-7deg);
-ms-transform: rotate(-7deg);
-o-transform: rotate(-7deg);
-webkit-transform: rotate(-7deg);
background-color: #00FFFF;
width: 190px;
height: 250px;
overflow: auto;
z-index: 1;
margin: 0 auto;
left: 220px;
top: 68px;
font-size: 0;
margin: 0;
padding: 0;
}
size {
max-width: 100%;
max-height: 100%;
}
iframe {
width: 100%;
height: 100%;
border: 0;
margin: 0;
padding: 0;
}
<div class="size">
<div class="scroll">
<iframe src="http://www.kopfkino-kollektiv.de"></iframe>
</div>
</div>
I have to make a logo shape in my website. The design is given below. How do I develop that?
For the first part of the logo I have created it using CSS3 skew property,
I have fiddled the link below. How do I develop the triangle section and the third part of the logo. The triangle is slider, so images inside should change.
https://jsfiddle.net/iamshajeer/x2og8utk/1/
.logo-menu {
height: 76%;
left: 11%;
margin: 0 auto;
width: 80%;
}
.first-part {
display: inline-block;
left: 135px;
position: relative;
transform: skew(-22deg);
width: 180px;
}
.menu-1{
background:red
}
.menu-2{
background:blue
}
.menu-3{
background:yellow
}
<div class="logo-menu">
<div class="first-part">
<div class="menu-1" style="height: 167px;">
<h3>About Us</h3>
</div>
<div class="menu-2" style="height: 167px;">
<h3>Gallery</h3>
</div>
<div class="menu-3" style="height: 167px;">
<h3>Get in Touch with</h3>
</div>
</div>
</div>
You could use CSS transforms to rotate and skew an element into a diamond, and then reverse those transforms for the child elements. If you have overflow: hidden; on the diamond and position the diamond in a wrapper that also has overflow: hidden;, you could produce a clipping triangle with content using just CSS.
Working Example (Codepen):
/* Clip the bottom half of the diamond. */
.triangle-wrap {
width: 400px;
height: 400px;
position: relative;
overflow: hidden;
}
/* Rotate and skew to create a diamond. */
.triangle {
background: grey;
position: absolute;
bottom: -50%;
width: 100%;
height: 100%;
overflow: hidden;
-webkit-transform: rotate(45deg) skew(20deg, 20deg);
-moz-transform: rotate(45deg) skew(20deg, 20deg);
-ms-transform: rotate(45deg) skew(20deg, 20deg);
transform: rotate(45deg) skew(20deg, 20deg);
}
/* Reset the skew and rotation. */
.triangle-reset {
width: 100%;
height: 100%;
position: relative;
-webkit-transform: skew(-20deg, -20deg) rotate(-45deg);
-moz-transform: skew(-20deg, -20deg) rotate(-45deg);
-ms-transform: skew(-20deg, -20deg) rotate(-45deg);
transform: skew(-20deg, -20deg) rotate(-45deg);
}
/* Create a content wrapper. */
.triangle-content {
background: url('http://placehold.it/400x400') no-repeat;
background-position: center center;
background-size: cover;
position: relative;
width: 120%;
height: 120%;
left: -10%;
bottom: 65%;
}
/* Visual aid. */
html {
min-height: 100%;
background: linear-gradient(to bottom, #336666 0%,#663366 100%);
}
<div class="triangle-wrap">
<div class="triangle">
<div class="triangle-reset">
<div class="triangle-content">
</div>
</div>
</div>
</div>
background-clip is what you're looking for. Check out this great article:
https://css-tricks.com/clipping-masking-css/
Here's an online tool to help you generate shapes:
http://bennettfeely.com/clippy/
After you generate each shape, you can position them to look like your image.
It is not perfect what you want but near to that.
Right side first div not looking good.
.third-part {
display: inline-block;
left: 500px;
position: relative;
transform: skew(22deg);
width: 180px;
}
.logo-menu {
height: 76%;
left: 11%;
margin: 0 auto;
width: 80%;
}
.first-part {
display: inline-block;
left: 135px;
position: relative;
transform: skew(-22deg);
width: 180px;
}
.menu-1{
background:red
}
.menu-10{
background: blue;
/* Skew */
left: -70px;
position: relative;
transform: skew(50deg);
width: 190px;
}
.menu-2{
background:blue
}
.menu-3{
background:yellow
}
.second-part {
top: 36%;
}
.second-part {
}
.second-part {
display: inline-block;
height: 100%;
left: 240px;
position: absolute;
top: 25%;
width: 520px;
}
.second-part .triangle-shape {
left: 4%;
margin: 0;
max-width: 700px;
position: absolute;
}
.wrap {
display: inline-block;
margin: 240px 0;
transform: rotate(45deg) translate3d(0px, 0px, 0px);
transition: transform 300ms ease-out 0s;
width: 500px;
}
.crop {
height: 465px;
margin: 0;
overflow: hidden;
position: relative;
transform: skew(22deg, 22deg) translate3d(0px, 0px, 0px);
width: 450px;
}
.crop img {
height: 650px;
left: -50%;
opacity: 1;
position: absolute;
top: -50%;
transform: skew(-20deg, -20deg) rotate(-45deg);
transition: opacity 300ms ease-in-out 0s;
width: 500px;
}
}
.second-part .triangle-shape {
left: 4%;
margin: 0;
max-width: 700px;
position: absolute;
}
.wrap {
display: inline-block;
margin: 240px 0;
transform: rotate(45deg) translate3d(0px, 0px, 0px);
transition: transform 300ms ease-out 0s;
width: 500px;
}
.crop {
height: 465px;
margin: 0;
overflow: hidden;
position: relative;
transform: skew(22deg, 22deg) translate3d(0px, 0px, 0px);
width: 450px;
}
.crop img {
height: 650px;
left: -50%;
opacity: 1;
position: absolute;
top: -50%;
transform: skew(-20deg, -20deg) rotate(-45deg);
transition: opacity 300ms ease-in-out 0s;
width: 500px;
}
<div class="logo-menu">
<div class="first-part">
<div class="menu-1" style="height: 167px;">
<h3>About Us</h3>
</div>
<div class="menu-2" style="height: 167px;">
<h3>Gallery</h3>
</div>
<div class="menu-3" style="height: 167px;">
<h3>Get in Touch with</h3>
</div>
</div>
<div class="second-part">
<div class="triangle-shape">
<div class="wrap">
<div class="crop">
<img alt="" src="http://s23.postimg.org/wlo0phrsb/triangle01.jpg">
<h2>Projects</h2>
</div>
</div>
</div>
</div>
<div class="third-part">
<div class="menu-10" style="height: 120px;">
<h3>Products</h3>
</div>
<div class="menu-2" style="height: 167px;">
<h3>Services</h3>
</div>
<div class="menu-3" style="height: 167px;">
<h3>Location Map</h3>
</div>
</div>
</div>
Hope it will help to move forward.
Check Fiddle.
You can use SVG (http://www.w3schools.com/svg/) to draw and position the shapes and then apply CSS over them like color and backgound to get the desired results.