shaping a tricky shape on a div - html

I'm trying to achieve this shape in css, tried in several different ways, checked online for examples but looks like this shape is kind of tricky to accomplish.
Anyone that could have an idea of how to do this? Not sure if it's even possible with css only technique.
Thank you!

Yes, it is possible and it's very simple.
demo
Result:
:
I'm using just one element and a pseudo for the bottom left corner so the HTML is simply:
<div class='shape'></div>
Relevant CSS:
.shape {
overflow: hidden; /* to hide the top right corner
of the parallelogram formed by the pseudo */
position: relative;
width: 20em; height: 10em; /* any values really */
}
.shape:before {
position: absolute;
bottom: 0; left: 0;
width: 150%; height: 150%;
transform-origin: 0 100%;
transform: rotate(-3deg) skewX(-10deg);
background: black;
content: '';
}
You can get a lot of shapes using CSS transforms. And they are real shapes, you can have any kind of background behind.

I think it is perfect solution to your question...
#trapezoid {
height: 0;
width: 120px;
border-bottom: 80px solid #05ed08;
border-left: 45px solid transparent;
border-right: 5px solid transparent;
padding: 10 8px 5 5;
}

You could also use :before, :after pseudo and transform property. Here's an example.
#box {
width: 400px;
height: 200px;
background-color: #212121;
position: relative;
}
#box:after, #box:before {
display: block;
content: "\0020";
color: transparent;
width: 411px;
height: 45px;
background: white;
position: absolute;
bottom: -20px;
-moz-transform: rotate(-2deg);
-webkit-transform: rotate(-2deg);
-o-transform: rotate(-2deg);
-ms-transform: rotate(-2deg);
transform: rotate(-2deg);
}
#box:before {
bottom: 80px;
left: -200px;
-moz-transform: rotate(92deg);
-webkit-transform: rotate(92deg);
-o-transform: rotate(92deg);
-ms-transform: rotate(92deg);
transform: rotate(92deg);
}
You may have to change some values to get the shape you want.

Related

Simple CSS spinner element wobbles while rotating

I've been trying to create a simple css spinner which is shown while my page is loading by using a pseudo element overlaying a div where content will be shown.
It uses border-radius and transform: rotate() to achieve this effect but as you can see it wobbles strangely while rotating. The effect is more or less obvious depending on the screen size, zoom level and browser. I find it's most visible in MS Edge.
Example fiddle
.loading {
width: 75vh;
height: 100vh;
margin: auto;
background: white;
position: relative;
}
.loading::after {
border: 6vmin solid lightblue;
border-top: 6vmin solid darkblue;
position: absolute;
margin-top: 5vmin;
margin-left: 5vmin;
width: 15vmin;
height: 15vmin;
content: "";
border-radius: 50%;
animation: spin .5s linear infinite;
}
#keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
<div class="loading"></div>
There's some weird cut going on with the border-radius
Change it to border-radius: 1000px and see what happens
Changing the width and height to a pixel value seems to fix the issue. It may not be the best solution, but hey, it works.
To make this appropriate for all screen sizes, you need to use #media. In the bottom of the css I have added one that changes the size if the screen size is smaller than 700px just to show you how to do it, and if you want to change the numbers around or something, you at least know how #media can be used :)
Here is the code for changing the size depending on the screen-size of the users device.
#media (max-width: 700px){
.loading::after {
width: 100px;
height: 100px;
}
}
If you want to make it different on large screens too, just swap out "max-width: 700px" with "min-width: 1500px" or a value of your choice :)
http://jsfiddle.net/hfsqebsn/5/
Again, there are probably better ways, but this works :)
Edit: I think I may have changed around some other stuff in the fiddle I linked for testing purposes, so just beware of that :P
This issue was driving me crazy all day. I was able to solve it personally by making the ring thicker than desired and then masking over its inner and outer portions to hide the wobble from the viewer.
Solution.
https://codepen.io/corbinmosher/pen/GRWmYjy
Solution with background coloring to help with understanding it.
https://codepen.io/corbinmosher/pen/bGqWmEj
<div class="spinner__container">
<div class="spinner__ring"></div>
<div class="spinner__outline"></div>
</div>
.spinner__container {
position: relative;
width: 58px;
height: 58px;
background-color: white;
}
.spinner__ring {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: calc(100% - 8px);
height: calc(100% - 8px);
border-radius: 50%;
}
.spinner__ring:before {
position: absolute;
top: -1px;
left: -1px;
width: calc(100% + 2px);
height: calc(100% + 2px);
border: 10px solid lightblue;
border-top: 10px solid blue;
box-sizing: border-box;
content: '';
border-radius: 50%;
animation: rotate-spinner 1s linear infinite;
}
.spinner__ring:after {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: calc(100% - 8px);
height: calc(100% - 8px);
box-sizing: border-box;
content: '';
border-radius: 50%;
background-color: white;
}
.spinner__outline {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: calc(100% - 8px);
height: calc(100% - 8px);
border-radius: 50%;
border: solid 2px white;
}
#keyframes rotate-spinner {
0% {
transform: rotate(405deg);
}
100% {
transform: rotate(765deg);
}
}
#-webkit-keyframes rotate-spinner {
0% {
transform: rotate(405deg);
}
100% {
transform: rotate(765deg);
}
}

How can I draw a hexagon and fit all children to its fullest?

I need to make a hexagon that contains mini shapes inside of it.
Like so:
I can make a hexagon div but I cant get my smaller shapes fit in it. They fit as if my hexagon is a rectangle.
I tried:
<style>
.hexagon {
overflow: hidden;
-webkit-transform: rotate(120deg);
-moz-transform: rotate(120deg);
-ms-transform: rotate(120deg);
-o-transform: rotate(120deg);
transform: rotate(120deg);
cursor: pointer;
}
.hexagon-in1 {
overflow: hidden;
width: 100%;
height: 100%;
-webkit-transform: rotate(-60deg);
-moz-transform: rotate(-60deg);
-ms-transform: rotate(-60deg);
-o-transform: rotate(-60deg);
transform: rotate(-60deg);
}
.hexagon1 {
width: 400px;
height: 200px;
margin: 0 0 0 -80px;
}
</style>
<div class="hexagon hexagon1"><div class="hexagon-in1"></div></div>
Hex shape generator using Sass
HTML
<div class="hex-shape"></div>
SASS(scss)
// need for mathematical calculations
$SQUARE_ROOT_3: 1.73;
$hex-shape-w: 100px;
$hex-shape-h: round($hex-shape-w / $SQUARE_ROOT_3);
$hex-shape-color: red;
.hex-shape {
position: relative;
display: inline-block;
box-sizing: border-box;
width: $hex-shape-w;
height: $hex-shape-h;
background-color: $hex-shape-color;
margin: ($hex-shape-h / 2) 0;
&::before,
&::after {
position: absolute;
left: 0;
content: '';
display: inline-block;
border-bottom: $hex-shape-h / 2 solid $hex-shape-color;
border-right: $hex-shape-w / 2 solid transparent;
border-left: $hex-shape-w / 2 solid transparent;
}
&::before {
top: -50%;
}
&::after {
bottom: -50%;
transform: scale(-1);
}
&:hover {
background-color: green;
&::before,
&::after {
border-bottom-color: green;
}
}
}
This is shape generator.
And I did one pen exmple https://codepen.io/stojko/pen/boWOwK?editors=1100
You can change shape size by changing $hex-shape-w variable and also if you make them bigger you must change $hex-container-w variable.
I wish I had more time to do this with JavaScript.
If you find this answer helpful, let me know.

Did CSS break my heart?

Following this question, I created a JSFiddle, but the output doesn't seem so good:
Here is the CSS, taken from the answer there:
#heart {
position: relative;
width: 100px;
height: 90px;
margin-top: 10px;
/* leave some space above */
}
#heart:before {
position: absolute;
content: "";
left: 50px;
top: 0;
width: 52px;
height: 80px;
background: red;
/* assign a nice red color */
border-radius: 50px 50px 0 0;
/* make the top edge round */
}
#heart:before {
-webkit-transform: rotate(-45deg);
/* 45 degrees rotation counter clockwise */
-moz-transform: rotate(-45deg);
-ms-transform: rotate(-45deg);
-o-transform: rotate(-45deg);
transform: rotate(-45deg);
-webkit-transform-origin: 0 100%;
/* Rotate it around the bottom-left corner */
-moz-transform-origin: 0 100%;
-ms-transform-origin: 0 100%;
-o-transform-origin: 0 100%;
transform-origin: 0 100%;
}
#heart:after {
left: 0;
/* placing the right part properly */
-webkit-transform: rotate(45deg);
/* rotating 45 degrees clockwise */
-moz-transform: rotate(45deg);
-ms-transform: rotate(45deg);
-o-transform: rotate(45deg);
transform: rotate(45deg);
-webkit-transform-origin: 100% 100%;
/* rotation is around bottom-right corner this time */
-moz-transform-origin: 100% 100%;
-ms-transform-origin: 100% 100%;
-o-transform-origin: 100% 100%;
transform-origin: 100% 100%;
}
Did I miss something, or that love got old (it's about 2 years old)?
I was messing around a bit with your JSfiddle and I noticed that you were only drawing one side of your heart :(
Here's the updated CSS that will fix your poor broken heart
#heart:before, #heart:after {
position: absolute;
content: "";
left: 50px;
top: 0;
width: 52px;
height: 80px;
background: red;
/* assign a nice red color */
border-radius: 50px 50px 0 0;
/* make the top edge round */
}
Here's a link to the working JSfiddle: https://jsfiddle.net/arfc63Le/1/
You missed the second selector for your second CSS rule.
The four rules should be:
#heart {}
#heart:before,
#heart:after {}
#heart:before [}
#heart:after {}
Here is the full demo:
#heart {
position: relative;
width: 100px;
height: 90px;
margin-top: 10px;
}
#heart:before,
#heart:after {
position: absolute;
content: "";
top: 0;
width: 52px;
height: 80px;
background: red;
border-radius: 50px 50px 0 0;
}
#heart:before {
left: 50px;
transform: rotate(-45deg);
transform-origin: 0 100%;
}
#heart:after {
left: 0;
transform: rotate(45deg);
transform-origin: 100% 100%;
}
<div id="heart"></div>
Looks like you missed one of the steps. It isn't very obvious in the other answer.
You need a copy of
#heart:before {
position: absolute;
content: "";
left: 50px;
top: 0;
width: 52px;
height: 80px;
background: red;
/* assign a nice red color */
border-radius: 50px 50px 0 0;
/* make the top edge round */
}
for #heart:after. So you need to add the following and it works (JSFiddle)
#heart:after {
position: absolute;
content: "";
left: 50px;
top: 0;
width: 52px;
height: 80px;
background: red;
/* assign a nice red color */
border-radius: 50px 50px 0 0;
/* make the top edge round */
}

Creating a skew box shadow on 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

CSS - Deactivate top div

How can I deactivate the top DIV so that I can select what's under it?
Check what I did here:
http://jsfiddle.net/zE5Ze/2/
#triangle_w {
width: 1000px;
height: 178px;
overflow: hidden;
position: fixed;
left: -24px;
top: -82px;
/*outline: 1px solid pink;*/
-moz-transform: rotate(-10deg);
-webkit-transform: rotate(-10deg);
}
#triangle {
width: 961px;
height: 176px;
background: url('http://i.imgur.com/FTGa2.png') no-repeat;
position: absolute;
left: 10px;
bottom: -80px;
/*outline: 1px solid red;*/
-moz-transform: rotate(10deg);
-webkit-transform: rotate(10deg);
}
#triangle #menu {
-moz-transform: rotate(-10deg);
-webkit-transform: rotate(-10deg);
/*outline: 1px solid red;*/
}
Without the rotation: http://jsfiddle.net/zE5Ze/5/
As you can see, the areas inside the red outline are not selectable.
Is there a way to do this without having to fiddle with CSS rotations?
I'd like to deactivate the triangle, and leave only the menu and the thumbs active.
Simple. Give a z-index.
#triangle #menu a {z-index: 5;}
Fiddle: http://jsfiddle.net/zE5Ze/3/
Or set a width!
#triangle_w {width: 100px;}
Fiddle: http://jsfiddle.net/zE5Ze/4/