how can i make divs with irregular shape [closed] - html

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>

Related

how twelve point star works correctly?

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.

How to rotate some text in html css?

I want to do something like this.
I dont know the property of css should be used.
my code is:
<h1><b>#GIRLBOSSES</b></h1>
CSS:
h1 b {
position: absolute;
color: #fdd2e9;
margin-left: 127px;
margin-top: 191px;
}
You need several settings. Different for different browsers.
.rotate {
-ms-transform: rotate(7deg); /* IE 9 */
-webkit-transform: rotate(7deg); /* Chrome, Safari, Opera */
transform: rotate(7deg);
}
Look in JSfiddle:
https://jsfiddle.net/z5dcnrwa/
you can use css transform to do that
h1{
transform: rotate(-18deg);
transform-origin: top left;
}
Test live
h1 {
-ms-transform: rotate(-9deg); /* IE 9 */
-webkit-transform: rotate(-9deg); /* Chrome, Safari, Opera */
transform: rotate(-9deg);
}
Edit: In the title of the post you asked about vertical text. For vertical, set it to -90.
You are looking for the CSS3 transform Property. In your case, it would look something like this:
<h1 style="position: absolute; color: #fdd2e9; margin-left: 127px; margin-top: 191px; -ms-transform: rotate(-7deg); -webkit-transform: rotate(-7deg); transform: rotate(-7deg);"><b>#GIRLBOSSES</b></h1>
The operative styles are:
-ms-transform: rotate(-7deg); /* IE 9 */
-webkit-transform: rotate(-7deg); /* Chrome, Safari, Opera */
transform: rotate(-7deg);
Do you want something like this?
.tilted {
position: absolute;
color: #fdd2e9;
left: 50%;
top: 10%;
font-size:50px;
-webkit-transform: rotate(-8deg);
-ms-transform: rotate(-8deg);
transform: rotate(-8deg);
}
.wrap {
position: relative;
display: inline-block;
}
<div class="wrap">
<img src="http://lorempixel.com/400/200/" />
<h1 class="tilted"><b>#GIRLBOSSES</b></h1>
</div>

CSS multiple octagons

"Ugh, yet another css octagon".
This is something different, I swear. I did read similar questions on StackOverflow.
I would like to have the following on my page:
html {
box-sizing: border-box;
}
*,
*:before,
*:after {
box-sizing: inherit;
}
.octagon {
display: inline-block;
position: relative;
overflow: hidden;
-webkit-transform: rotate(22.5deg) scale(0.9) translateY(-4px);
-moz-transform: rotate(22.5deg) scale(0.9) translateY(-4px);
-ms-transform: rotate(22.5deg) scale(0.9) translateY(-4px);
-o-transform: rotate(22.5deg) scale(0.9) translateY(-4px);
transform: rotate(22.5deg) scale(0.9) translateY(-4px);
}
div.octagon > * {
position: relative;
overflow: hidden;
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-ms-transform: rotate(45deg);
-o-transform: rotate(45deg);
transform: rotate(45deg);
background: transparent;
border: 4px solid;
margin: 0;
}
div.octagon > *:after {
position: absolute;
/* There needs to be a negative value here to cancel
* out the width of the border. It's currently -4px,
* but if the border were 5px, then it'd be -5px.
*/
top: -4px;
right: -4px;
bottom: -4px;
left: -4px;
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-ms-transform: rotate(45deg);
-o-transform: rotate(45deg);
transform: rotate(45deg);
content: '';
border: inherit;
}
div.octagon > * > img {
display: block;
-webkit-transform: rotate(-67.5deg) scale(1.1) translateZ(0);
-moz-transform: rotate(-67.5deg) scale(1.1) translateZ(0);
-ms-transform: rotate(-67.5deg) scale(1.1) translateZ(0);
-o-transform: rotate(-67.5deg) scale(1.1) translateZ(0);
transform: rotate(-67.5deg) scale(1.1) translateZ(0);
backface-visibility: hidden;
}
.green .octagon {
color: green;
}
/* Grouping */
.octagons {
position: relative;
display: inline-block;
/* To take dimension of the main octagon */
margin-left: 30px;
font-size: 0;
/* Remove white space */
}
.background.octagon {
position: absolute;
width: 100%;
height: 100%;
}
.background.octagon > * {
width: 100%;
height: 100%;
}
.left.octagon {
left: -30px;
}
.right.octagon {
right: -30px;
}
<div class="green octagons">
<div class="left background octagon">
<div> </div>
</div>
<div class="right background octagon">
<div> </div>
</div>
<div class="octagon">
<p>
<img src="https://placeholdit.imgix.net/~text?txtsize=25&txt=People&w=175&h=175" alt="" width="175" height="175" />
</p>
</div>
</div>
As you probably see, this is a "div soup". Because the main octagon needs to clip the image, it needs to have the same variable dimension as the image. Also, the octagons have border and are responsive, so I can't use "border hack".
The two background octagons only need the borders, but it need to be the same dimension as the image as well.
I can't use SVG because the image will be entered by end-user.
My question is then: Is there a cleaner way to do this?

How make 3 divs skew in css

How to make a 3 div with distortion, as shown in the picture?
I have made this:
.cars {
width: 100%;
height: 500px;
}
.car {
width: 33.33333333%;
height: 100%;
background: #3498db;
position: relative;
-webkit-transform: skewx(-10deg);
-moz-transform: skewx(-10deg);
-o-transform: skewx(-10deg);
-ms-transform: skewx(-10deg);
transform: skewx(-10deg);
transform-origin: top left;
float: left;
display: inline;
}
.car:nth-child(2) {
background: #000
}
.car:nth-child(3) {
background: #ff0000
}
<div class="cars">
<div class="car"></div>
<div class="car"></div>
<div class="car"></div>
</div>
jsFiddle
Left div - left corner straight, right corner slanted
Center div - left and right corner slanted
Right div - left corner slanted, right corner straight
I have used CSS's :after pseudo class to add another red box after the last, slanted one. However this one isn't slanted, thus 'filling in' the bit of the slant that you don't want:
.car:nth-child(3):after {
/* create the box */
content: "";
display: block;
/* make it fill the required space */
width: 80%; /* (this is only 80 because it was a bit large at 100) */
height: 100%;
background: #ff0000;
/* transform it in the opposite direction to counter the -10deg skew of .car */
-webkit-transform: skewx(10deg);
-moz-transform: skewx(10deg);
-o-transform: skewx(10deg);
-ms-transform: skewx(10deg);
transform: skewx(10deg);
transform-origin: top left;
position: relative;
right: -20%; /* counteract the 80% width */
}
I did the same with the first div, and :before:
.car:nth-child(3):before{
content: "";
display: block;
width: 70%;
height: 100%;
background: #3498db;
-webkit-transform: skewx(10deg);
-moz-transform: skewx(10deg);
-o-transform: skewx(10deg);
-ms-transform: skewx(10deg);
transform: skewx(10deg);
transform-origin: top left;
position: relative;
right: 40%;
}
.cars {
width: 100%;
height: 500px;
margin-left: 100px;
}
.car {
width: 33.33333333%;
height: 100%;
background: #3498db;
position: relative;
-webkit-transform: skewx(-10deg);
-moz-transform: skewx(-10deg);
-o-transform: skewx(-10deg);
-ms-transform: skewx(-10deg);
transform: skewx(-10deg);
transform-origin: top left;
float: left;
display: inline;
}
.car:nth-child(2) {
background: #000;
}
.car:nth-child(3) {
background: #ff0000;
}
.car:nth-child(3):after {
content: "";
display: block;
width: 70%;
height: 100%;
background: #ff0000;
-webkit-transform: skewx(10deg);
-moz-transform: skewx(10deg);
-o-transform: skewx(10deg);
-ms-transform: skewx(10deg);
transform: skewx(10deg);
transform-origin: top left;
position: relative;
right: -30%;
}
.car:nth-child(1):before {
content: "";
display: block;
width: 70%;
height: 100%;
background: #3498db;
-webkit-transform: skewx(10deg);
-moz-transform: skewx(10deg);
-o-transform: skewx(10deg);
-ms-transform: skewx(10deg);
transform: skewx(10deg);
transform-origin: top left;
position: relative;
right: 40%;
}
<div class="cars">
<div class="car first"></div>
<div class="car"></div>
<div class="car last"></div>
</div>
<br><br>

How to create different shape of trapezoid images using css?

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.