I am working on a website where I need to use different trapezoid shape of images. Here I am giving you that image in link:
Thanks Riccardo, Appreciate your effort.
Following are the 2 points I still need to sort it out.
This is the image that I got after implement your code.
Shape of the site will be skewed but not the image. The current shape is perfect but all images are also got skewed along with the shape which I don't want. I want all the images not to be shown as skewed as it is showing right now. So need guidance on that particular issue.
And the 2nd most important thing is about the total structure of the site. My site will be in 100% but in Container, you have given fixed height and width but I want the height and the width will be 100%.
I have tried by putting 100% width instead of current pixels but it all messed up. Here I am posting my given css. The left part of the shape is fixed, its not increasing while I am giving the widhth 30%. And the right side shape is moving far right and in between middle and right shape the container backgroup is shown which is in orange color as per the css code. And eventually I messed up all things, Here is thislink of that:
One more thing I would like to add is that Can it be possible to put 100% height on that container. Because whenever I tried to put height 100%, the whole structure get vanished. So any solution in that particular height point?
The both image issue and width height 100% issue are important for the website to function. So need your guidance on this.
HTML STRUCTURE FOR REFERENCE:
<div id="container">
<span id="left">
<img src=""/>
</span>
<span id="middle">
<img src=""/>
</span>
<span id="right"></span>
</div>
I made this example for you with pure css.
Now let explain how I made it.
I take a container, set the dimension of that and the relative position.
#container{
width: 600px;
background-color: orange;
height: 300px;
overflow: hidden;
position: relative;
}
If you set the overflow: hidden all the element inside the container will be truncated and they can't expand outside of the parent.
After that I put 3 span in the container, they are inline element so I can't set their width or height. To do that I set their display: property to inline-block. Now I can give to the span a dimension.
The span are in a absolute position because I want the spans to be able to overlap.
For that after the absolute position use z-index.
The 3 span ids.
#left {
position: absolute;
left: -100px;
display: inline-block;
width: 300px;
background-color: red;
height: 300px;
transform: skew(-20deg, 0deg);
-ms-transform: skew(-20deg, 0deg); /* IE 9 */
-webkit-transform: skew(-20deg, 0deg); /* Safari and Chrome */
z-index: 1;
overflow: hidden;
}
#left img {
-webkit-transform: skew(20deg,0deg);
}
#middle {
position: absolute;
left: 200px;
display: inline-block;
width: 200px;
background-color: green;
height: 300px;
transform: skew(-20deg, 0deg);
-ms-transform: skew(-20deg, 0deg); /* IE 9 */
-webkit-transform: skew(-20deg, 0deg); /* Safari and Chrome */
z-index: 3;
border-right: 10px solid white;
border-left: 10px solid white;
overflow: hidden;
}
#middle img {
-webkit-transform: skew(20deg, 0deg);
margin-left: -50px;
}
#right {
position:absolute;
right:-100px;
display:inline-block;
width:400px;
background-color:gray;
height:300px;
transform:skew(-20deg,0deg);
-ms-transform:skew(-20deg,0deg); /* IE 9 */
-webkit-transform:skew(-20deg,0deg); /* Safari and Chrome */
z-index:2;
overflow:hidden;
}
As you can see there are the skew transformation for the shapes, and also the overflow: hidden because I don't want the img inside the span go outside the parent area.
When I put an img inside the skewed span, it take also the skew of the shape. So apply the
#nameofskewedcontainer img {
-webkit-transform: skew(20deg, 0deg);
}
where the skew property are exactly the opposite that is applied to the span. With that I keep the img with the standard shape without skew. (try to remove that in jsfiddle demo and see)
So I hope I was clear. For everything leave a comment!
SECOND UPDATED SOLUTION:
WIDTH 100%
CSS->
#container {
width: 100%;
height: 300px;
overflow: hidden;
position: relative;
}
#left {
position: absolute;
left: -100px;
display: inline-block;
width: 50%;
height: 300px;
transform: skew(-20deg, 0deg);
-ms-transform: skew(-20deg, 0deg); /* IE 9 */
-webkit-transform: skew(-20deg, 0deg); /* Safari and Chrome */
z-index: 1;
overflow: hidden;
}
#left img {
transform: skew(20deg, 0deg);
-moz-transform: skew(20deg, 0deg);
-webkit-transform: skew(20deg, 0deg);
}
#middle {
position:absolute;
left: 30%;
display: inline-block;
width: 40%;
height: 300px;
transform: skew(-20deg, 0deg);
-ms-transform: skew(-20deg, 0deg); /* IE 9 */
-webkit-transform: skew(-20deg, 0deg); /* Safari and Chrome */
z-index: 3;
border-right: 10px solid white;
border-left: 10px solid white;
overflow: hidden;
}
#middle img {
transform: skew(20deg, 0deg);
-moz-transform: skew(20deg, 0deg);
-webkit-transform: skew(20deg, 0deg);
margin-left: -50px;
}
#right {
position: absolute;
right: -100px;
display: inline-block;
width: 50%;
background-color: gray;
height: 300px;
transform: skew(-20deg, 0deg);
-ms-transform: skew(-20deg, 0deg); /* IE 9 */
-webkit-transform: skew(-20deg, 0deg); /* Safari and Chrome */
z-index: 2;
}
Anyway roy, remember that in stackoverflow you can ask of something, but also you have to practice with the answers that are given to you. This is the only way you can really learn something.
Related
I am new to front-end developer and I am learning css basics , I can understand the following code
#twelve-point-star {
height: 100px;
width: 100px;
margin: 30px;
background: blue;
position: absolute;
}
#twelve-point-star:before {
height: 100px;
width: 100px;
background: blue;
content: "";
position: absolute;
/* Rotate */
-moz-transform: rotate(30deg);
-webkit-transform: rotate(30deg);
-ms-transform: rotate(30deg);
-o-transform: rotate(30deg);
transform: rotate(30deg);
}
#twelve-point-star:after {
height: 100px;
width: 100px;
background: blue;
content: "";
position: absolute;
/* Rotate */
-moz-transform: rotate(-30deg);
-webkit-transform: rotate(-30deg);
-ms-transform: rotate(-30deg);
-o-transform: rotate(-30deg);
transform: rotate(-30deg);
}
<p>twelve point star</p>
<div id="twelve-point-star"></div>
We have created a different kind of triangle and rotate that position to achieve this position. But what purpose we used :before and :after ?
See...you need total 12 stars. If you apply css only #twelve-point-star, you will get 4 corners...you need 8 corners more...For that you have used the :before to get 4 corners more and :after to get final 4 corners pseudo classes to get total 12 corners..
Try to change the color you will see the real visual.
Stack Snippet
#twelve-point-star {
height: 100px;
width: 100px;
margin:30px;
background: blue;
position: absolute;
}
#twelve-point-star:before {
height: 100px;
width: 100px;
background: red;
content:"";
position: absolute;
/* Rotate */
-moz-transform: rotate(30deg);
-webkit-transform: rotate(30deg);
-ms-transform: rotate(30deg);
-o-transform: rotate(30deg);
transform: rotate(30deg);
}
#twelve-point-star:after {
height: 100px;
width: 100px;
background: black;
content:"";
position: absolute;
/* Rotate */
-moz-transform: rotate(-30deg);
-webkit-transform: rotate(-30deg);
-ms-transform: rotate(-30deg);
-o-transform: rotate(-30deg);
transform: rotate(-30deg);
}
<body>
<p>
twelve point star
</p>
<div id="twelve-point-star">
</div>
</body>
Reference Link
::before
::after
:before
means that before every #twelve-point-star, the css in #twelve-point-star:before will be applied to #twelve-point-star. Likewise for :after, except that it is place after every #twelve-point-star. So what happens in the code is that you basically make 3 squares that are rotated in different directions, which creates that effect.
W3schools is a great source for you to learn css.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
how can i create a two divs shown in images one div should be in pink color and other one in blue color.I want to create same shapes like in this example but with using two divs
example Image
Using css transform skew property you can skew the right container and shift it to the left. Note the right end of the skewed container is strategically hidden by applying an overflow hidden property to the parent container
Snippet below
#container {
width: 700px;
height: 200px;
white-space: nowrap;
overflow: hidden;
}
#left {
position: relative;
width: 70%;
height: 100%;
display: inline-block;
background-color: #ED145B;
}
#right {
position: relative;
width: 20%;
height: 100%;
display: inline-block;
background-color: #212635;
}
#right {
transform: skew(-30deg, 0deg);
-moz-transform: skew(-30deg, 0deg);
-webkit-transform: skew(-30deg, 0deg);
-o-transform: skew(-30deg, 0deg);
-ms-transform: skew(-30deg, 0deg);
right: 10%;
width: 500px;
}
<div id="container">
<div id="left"></div>
<div id="right"></div>
</div>
.skew {
width: 10px;
height: 100px;
background: black;
-webkit-transform: skew(0deg); /* Chrome, Opera */
-ms-transform: skew(0deg); /* IE */
transform: skew(0deg); /* Padrão */
}
.positive {
-webkit-transform: skew(10deg); /* Chrome, Opera */
-ms-transform: skew(10deg); /* IE */
transform: skew(10deg); /* Padrão */
}
.negative {
-webkit-transform: skew(-10deg); /* Chrome, Opera */
-ms-transform: skew(-10deg); /* IE */
transform: skew(-10deg); /* Padrão */
}
<span>0 DEG</span>
<div class="skew"></div>
<span>10 DEG</span>
<div class="skew positive"></div>
<span>-10 DEG</span>
<div class="skew negative"></div>
How do i add a skew box shadow on a div element?
I've tried adding an absolute div behind the div but this doesn't seem to work correctly.
The css i tried is:
.shadow-box-bg {
background-color: rgba(0,0,0,0.8);
width: 150px;
height: 100px;
position: absolute;
z-index: 9;
-webkit-transform: skew(20deg);
-moz-transform: skew(20deg);
-o-transform: skew(20deg);
transform: scale(2.3) rotate(88deg) translateX(67px) translateY(-17px) skewX(3deg) skewY(-2deg);
}
It seems as though i could have better luck using a div shadow. But i have no idea how to make it skew.
You could use pseudoelements instead of creating empty div for styling purpose only
e.g. http://codepen.io/anon/pen/yNQjgB
Markup
<div class="skewedshadow"></div>
CSS
div {
width: 200px;
height: 400px;
background: #b33049;
}
.skewedshadow {
position: relative;
}
.skewedshadow:before {
position: absolute;
z-index: -1;
content: "";
width: inherit;
height: inherit;
background: rgba(0,0,0, .45);
transform: rotate(1.5deg) translateX(10px) translateY(15px) skewX(4deg) skewY(-4deg);
}
Result
I have this side-pane. It's height is 80%. In this side-pane I have a text. I want this to always be in the middle.
Main div:
.simulation {
height: 80%;
width: 500px;
border: 1px solid #ccc;
box-shadow: 8px 8px 7px #A5A5A5;
background: #FFF;
position: absolute;
top: 10px;
z-index: 100;
left: -450px;
transition: 500ms ease all;
}
Sub div:
.simulation .simulation-content .simulation-bar .heading {
position: relative;
margin-top: 340px; /* How do I get this in the middle?? */
-webkit-transform: rotate(-90deg);
}
I can't get the margin-top right when i express it in %.
Plunkr: http://plnkr.co/edit/Z8xZNYLNvShQDVPZMZgk?p=preview
You could align the child element vertically at the middle of the parent by positioning the child absolutely and a combination of top: 50% and transform: translateY(-50%).
In this particular instance — Example:
.simulation .simulation-content .simulation-bar .heading {
position: absolute;
top: 50%;
left: 0;
-webkit-transform: translate(-30%, -50%) rotate(-90deg);
-moz-transform: translate(-30%, -50%) rotate(-90deg);
-ms-transform: translate(-30%, -50%) rotate(-90deg);
-o-transform: translate(-30%, -50%) rotate(-90deg);
transform: translate(-30%, -50%) rotate(-90deg);
}
An explanation can be found here:
How to center a "position: absolute" element
You can use also flexboxes to achieve it. just add:
display: flex;
flex-flow: column nowrap;
justify-content: center;
to your "main-content"
I am trying to rotate this div, fix it and float it to the RIGHT like this [jsbin.com/ujebik/1][1] but it don't completely float to the RIGHT
HTML:
<div class="logo">
ROTATE THIS TEXT
</div>
CSS:
.logo {
position: fixed;
top: 20px;
right: 0;
z-index: 100;
width: 250px;
-webkit-transform: rotate(-90deg);
-moz-transform: rotate(-90deg);
transform: rotate(-90deg);
font-size:20px;
background-color:green
}
UPDATE:
want this:
but Have this:
Try to add transform-origin: 100% 100%; to make the div rotate around its lower right corner instead of its center (http://jsbin.com/iniweq/2/)
I am guessing what you are trying to do is have the element on the left? If this is the case then you need to change your CSS to
.logo {
position: fixed;
top: 20px;
left: 0;
z-index: 100;
width: 250px;
-webkit-transform: rotate(-90deg);
-moz-transform: rotate(-90deg);
transform: rotate(-90deg);
font-size:20px;
background-color:green
}
Here is a fiddle: http://jsfiddle.net/Er3yL/
Or if what you are trying to say is that you want to 'float' it to the extreme RIGHT, then I am guessing that the parent element for .logo is not stretched to 100% of the window. Either you can correct that or if you want to keep it that way then you can add a negative value to right, like this
.logo {
position: fixed;
top: 20px;
right: -20px;
z-index: 100;
width: 250px;
-webkit-transform: rotate(-90deg);
-moz-transform: rotate(-90deg);
transform: rotate(-90deg);
font-size:20px;
background-color:green
}