How to inscribe the following shape with CSS inside div? - html

FIDDLE
HTML
<div id="DiamondCenter">
<div id="triangle-topleft"></div>
</div>
CSS
#DiamondCenter {
position:fixed;
top:2%;
left:48%;
background: #24201a;
height:40px;
width:40px;
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-ms-transform: rotate(45deg);
-o-transform: rotate(45deg);
transform: rotate(45deg);
z-index:20 !important;
}
#triangle-topleft {
width: 0;
height: 0;
border-top: 40px solid gray;
border-right: 40px solid transparent;
}

Using SVG:
While using SVG, you could make use of path and polyline elements to draw the required shape. As indicated by Paulie_D in comments, SVG is the better choice for such complex shapes instead of CSS (though this can be achieved with CSS also).
The approach is very simple and is as follows:
One path element for the top polygon which is drawn by joining the points at coordinates (0,50), (50,0), (100,50) and (50,70).
Another path element for the bottom polygon which is drawn by joining the points at (0,50), (50,70) and (100,50).
One polyline element for the orange border which is nothing but a line connecting (0,50), (50,70) and (100,50).
svg {
height: 100px;
width: 100px;
}
path#top {
fill: gray;
}
path#bottom {
fill: black;
}
polyline#border {
stroke: orange;
stroke-width: 2;
fill: none;
}
<svg viewBox="0 0 100 100">
<path id="top" d="M0,50 L50,0 100,50 50,70z" />
<path id="bottom" d="M0,50 L50,100 100,50 50,70z" />
<polyline id="border" points="0,50 50,70 100,50" />
</svg>
Using CSS:
You can achieve the shape provided in question by using 2 pseudo-elements which are both rotated and skewed. The dimension of each pseudo-element is calculated using Pythagoras theorem.
The shape produced using this method is responsive and can adapt to changes in dimension. Hover the shape within the snippet to see how it adapts.
*,
*:after,
*:before {
box-sizing: border-box;
}
#DiamondCenter {
position: fixed;
top: 2%;
left: 48%;
background: #24201a;
height: 40px;
width: 40px;
transform: rotate(45deg);
z-index: 20 !important;
overflow: hidden;
}
#DiamondCenter:after {
position: absolute;
content: '';
bottom: 0px;
left: -1px; /* half the width of border-left */
height: calc(100% / 1.414);
width: calc(100% / 1.414);
background: black;
border-left: 2px solid orange;
transform: rotate(40deg) skewX(-20deg);
transform-origin: bottom left;
}
#DiamondCenter:before {
position: absolute;
content: '';
top: -1px; /* half the width of border-top */
right: 0px;
height: calc(100% / 1.414);
width: calc(100% / 1.414);
background: black;
border-top: 2px solid orange;
transform: rotate(-40deg) skewY(-20deg);
transform-origin: top right;
}
/* Just for demo */
#DiamondCenter{
transition: all 1s;
}
#DiamondCenter:hover{
top: 5%;
height: 80px;
width: 80px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
<div id="DiamondCenter"></div>
In the below snippet, I have set different background colors for the pseudo-elements to illustrate how the shape is achieved.
*,
*:after,
*:before {
box-sizing: border-box;
}
#DiamondCenter {
position: fixed;
top: 2%;
left: 48%;
background: #24201a;
height: 40px;
width: 40px;
transform: rotate(45deg);
z-index: 20 !important;
overflow: hidden;
}
#DiamondCenter:after {
position: absolute;
content: '';
bottom: 0px;
left: -1px;
height: calc(100% / 1.414);
width: calc(100% / 1.414);
background: seagreen;
border-left: 2px solid orange;
transform: rotate(40deg) skewX(-20deg);
transform-origin: bottom left;
}
#DiamondCenter:before {
position: absolute;
content: '';
top: -1px;
right: 0px;
height: calc(100% / 1.414);
width: calc(100% / 1.414);
background: skyblue;
border-top: 2px solid orange;
transform: rotate(-40deg) skewY(-20deg);
transform-origin: top right;
}
/* Just for demo */
#DiamondCenter{
transition: all 1s;
}
#DiamondCenter:hover{
top: 5%;
height: 80px;
width: 80px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
<div id="DiamondCenter"></div>

This is quite a complicated shape to complete in CSS, but as shown by others it is possible.
A good alternative though would be to use SVG. Its a vector graphic so it scales brilliantly for responsiveness and is very well supported (CanIUse)
<svg width="50%" height="50%" viewBox="0 0 10 10">
<path d="M5,1
L9,5
L5,9
L1,5z" fill="grey" />
<path d="M1,5
L5,6
L9,5
L5,9z" stroke="orange" stroke-width=".1" stroke-dasharray="0,0,8.23,15" />
</svg>

You can create diamond shape using this css , suppose this is div where you want above shape id should be same as css (cut-diamond)
#cut-diamond {
border-style: solid;
border-color: transparent transparent red transparent;
border-width: 0 25px 25px 25px;
height: 0;
width: 50px;
position: relative;
margin: 20px 0 50px 0;
}
#cut-diamond:after {
content: "";
position: absolute;
top: 25px;
left: -25px;
width: 0;
height: 0;
border-style: solid;
border-color: red transparent transparent transparent;
border-width: 70px 50px 0 50px;
}
JSFiddle Demo

Related

How to make rounded corners Hexagon with CSS? [duplicate]

This is my CSS.
CSS
#hexagon-circle {
width: 100px;
height: 55px;
background: red;
position: relative;
border-radius: 10px;}
#hexagon-circle:before {
content: "";
position: absolute;
top: -25px;
left: 0;
width: 0;
height: 0;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
border-bottom: 29px solid red;
border-radius: 10px;}
#hexagon-circle:after {
content: "";
position: absolute;
bottom: -25px;
left: 0;
width: 0;
height: 0;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
border-top: 29px solid red;
border-radius: 10px;}
The output is 4 edges of hexagon is curved, but top and the bottom is not. I want to make all edge of hexagon curved. How to make top and bottom edge to be curved? or How to make the top edge of triangle to be curved?
http://jsfiddle.net/yR7zt/1
I think you are looking for this.
.hex {
position: relative;
margin: 1em auto;
width: 10em;
height: 17.32em;
border-radius: 1em/.5em;
background: orange;
transition: opacity .5s;
}
.hex:before,
.hex:after {
position: absolute;
width: inherit;
height: inherit;
border-radius: inherit;
background: inherit;
content: '';
}
.hex:before {
-webkit-transform: rotate(60deg);
transform: rotate(60deg);
}
.hex:after {
-webkit-transform: rotate(-60deg);
transform: rotate(-60deg);
}
<div class="hex"></div>
I understand this is a fairly old question, but I thought I'd add an answer to show more about how it works.
So, first off, we need to create a single element on the page. I have gone for a size of height:300px; width:180px; and a border radius of 10px. Just because I like the roundness of the number (forgive the pun). Giving this element a position:relative; means that we can herein position everything absolutely in relative terms to this div.
We then need to create two pseudo elements, with the same height and width as the parent.
Because the pseudo elements are exactly that, pseudo elements, we need to add a content: to them. And since because we can put stuff within the parent, we don't really need these, so set them to "";
this leads us onto how to create the hexagon, rather than the rectangle we currently have. To do that, we're going to have to include a rotation in order to generate the other sides of the hexagon. With there being 6 sides, and the angles needing to add to 360, we can rotate one of the pseudo element by 60 degrees. The other we'll rotate by -60 degrees (or 300degrees, if you'd prefer).
This leaves us with our 'hexagon' in which we can add some nice styling and hover animations as need be:
.roundHex {
position: relative;
margin: 0 auto;
background: rgba(0, 0, 0, 0.2);
border-radius: 10px;
height: 300px;
width: 180px;
transition: all 1s;
line-height:300px;
text-align:center;
color:white;
font-size:20px;
}
.roundHex:before,
.roundHex:after {
content: "";
position: absolute;
top: 0;
left: 0;
background: inherit;
border-radius: inherit;
height: 100%;
width: 100%;
z-index:-1;
}
.roundHex:before {
-webkit-transform: rotate(60deg);
-moz-transform: rotate(60deg);
transform: rotate(60deg);
transition: all 1s 0.5s;
}
.roundHex:after {
-webkit-transform: rotate(-60deg);
-moz-transform: rotate(-60deg);
transform: rotate(-60deg);
transition: all 1s 1s;
}
.roundHex:hover {
background: tomato;
}
<div class="roundHex">HOVER ME</div>
Jsfiddle demo also available
I will consider the same trick I used in the previous answer Where I will build the hexagon using clip-path
.hex {
width: 200px;
display: inline-block;
color:orange;
}
.hex::before {
content: "";
display: block;
background:currentColor;
padding-top: 90%;
clip-path: polygon(25% 0%, 75% 0%, 100% 50%, 75% 100%, 25% 100%, 0% 50%);
}
<div class="hex"></div>
Then I will apply an SVG filter:
.hex {
width: 200px;
display: inline-block;
color:orange;
filter: url('#goo');
}
.hex::before {
content: "";
display: block;
background:currentColor;
padding-top: 86.6%; /* 100%*cos(30) */
clip-path: polygon(25% 0%, 75% 0%, 100% 50%, 75% 100%, 25% 100%, 0% 50%);
}
<div class="hex"></div>
<div class="hex" style="color:blue;width:150px;"></div>
<div class="hex" style="color:red;width:100px;"></div>
<svg style="visibility: hidden; position: absolute;" width="0" height="0" xmlns="http://www.w3.org/2000/svg" version="1.1">
<defs>
<filter id="goo"><feGaussianBlur in="SourceGraphic" stdDeviation="8" result="blur" />
<feColorMatrix in="blur" mode="matrix" values="1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 19 -9" result="goo" />
<feComposite in="SourceGraphic" in2="goo" operator="atop"/>
</filter>
</defs>
</svg>
And in the opposite direction
.hex {
width: 200px;
display: inline-block;
margin:0 5px;
color:orange;
filter: url('#goo');
}
.hex::before {
content: "";
display: block;
background:currentColor;
padding-top: 115%; /* 100%/cos(30) */
clip-path: polygon(0% 25%,0% 75%,50% 100%,100% 75%,100% 25%,50% 0%);
}
<div class="hex"></div>
<div class="hex" style="color:blue;width:150px;"></div>
<div class="hex" style="color:red;width:100px;"></div>
<svg style="visibility: hidden; position: absolute;" width="0" height="0" xmlns="http://www.w3.org/2000/svg" version="1.1">
<defs>
<filter id="goo"><feGaussianBlur in="SourceGraphic" stdDeviation="8" result="blur" />
<feColorMatrix in="blur" mode="matrix" values="1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 19 -9" result="goo" />
<feComposite in="SourceGraphic" in2="goo" operator="atop"/>
</filter>
</defs>
</svg>
Try this way :(works in chrome and in ie 10)
<br><br><br>
<div id="hexagon-circle"></div>
<style>
#hexagon-circle {
position: relative;
margin: 1em auto;
width: 10em; height: 17.32em;
border-radius: 1em/.5em;
opacity: .25;
background: orange;
transition: opacity .5s;
cursor: pointer;
}
#hexagon-circle:before, #hexagon-circle:after {
position: absolute;
width: inherit; height: inherit;
border-radius: inherit;
background: inherit;
content: '';
}
#hexagon-circle:before {
transform: rotate(60deg);
-ms-transform:rotate(60deg); /* IE 9 */
-webkit-transform:rotate(60deg); /* Opera, Chrome, and Safari */
}
#hexagon-circle:after {
transform: rotate(-60deg);
-ms-transform:rotate(-60deg); /* IE 9 */
-webkit-transform:rotate(-60deg); /* Opera, Chrome, and Safari */
}
</style>
You can try this approach:
CSS
#hexagon-circle {
position: relative;
margin: 1em auto;
width: 10em;
height: 17.32em;
border-radius: 1em/.5em;
background: red;
transition: opacity .5s;
cursor: pointer;}
#hexagon-circle:before {
position: absolute;
width: inherit;
height: inherit;
border-radius: inherit;
background: inherit;
content: '';
-webkit-transform: rotate(60deg); /* Chrome, Opera 15+, Safari 3.1+ */
-ms-transform: rotate(60deg); /* IE 9 */
transform: rotate(60deg);} /* Firefox 16+, IE 10+, Opera */
#hexagon-circle:after {
position: absolute;
width: inherit;
height: inherit;
border-radius: inherit;
background: inherit;
content: '';
-webkit-transform: rotate(-60deg); /* Chrome, Opera 15+, Safari 3.1+ */
-ms-transform: rotate(-60deg); /* IE 9 */
transform: rotate(-60deg);} /* Firefox 16+, IE 10+, Opera */
DEMO
http://jsfiddle.net/yR7zt/4/
With your current code, using the triangle top and bottom, you can modify them slightly to give it a curved look. Add a width of 4px to #hexagon-circle:before and #hexagon-circle:after and reduce border-left and border-right by 2px each.
Js Fiddle here
#hexagon-circle {
width: 100px;
height: 55px;
background: red;
position: relative;
border-radius: 10px;
}
#hexagon-circle:before {
content: "";
position: absolute;
top: -25px;
left: 0;
width: 4px;
height: 0;
border-left: 48px solid transparent;
border-right: 48px solid transparent;
border-bottom: 29px solid red;
border-radius: 10px;
}
#hexagon-circle:after {
content: "";
position: absolute;
bottom: -25px;
left: 0;
width: 4px;
height: 0;
border-left: 48px solid transparent;
border-right: 48px solid transparent;
border-top: 29px solid red;
border-radius: 10px;
}
It's not a true curve as it creates a straight line, however it gives the impression it might be curved when viewed in the context of the shape.

4 rounded points star shape

I am trying to get this star as pixel perfect as possible in CSS, here's what I tried so far, but it's a 5 angled star, and I want to have it only 4 points also how can I make the corners more rounded?
#star-five {
margin: 50px 0;
position: relative;
display: block;
color: red;
width: 0px;
height: 0px;
border-right: 100px solid transparent;
border-bottom: 70px solid red;
border-left: 100px solid transparent;
-moz-transform: rotate(35deg);
-webkit-transform: rotate(35deg);
-ms-transform: rotate(35deg);
-o-transform: rotate(35deg);
}
#star-five:before {
border-bottom: 80px solid red;
border-left: 30px solid transparent;
border-right: 30px solid transparent;
position: absolute;
height: 0;
width: 0;
top: -45px;
left: -65px;
display: block;
content: '';
-webkit-transform: rotate(-35deg);
-moz-transform: rotate(-35deg);
-ms-transform: rotate(-35deg);
-o-transform: rotate(-35deg);
}
#star-five:after {
position: absolute;
display: block;
color: red;
top: 3px;
left: -105px;
width: 0px;
height: 0px;
border-right: 100px solid transparent;
border-bottom: 70px solid red;
border-left: 100px solid transparent;
-webkit-transform: rotate(-70deg);
-moz-transform: rotate(-70deg);
-ms-transform: rotate(-70deg);
-o-transform: rotate(-70deg);
content: '';
}
<div id="star-five"></div>
Maybe you could use a gradient on the Black Four Pointed Star Unicode char:
✦
It has some compatibility issues (mostly caused by text-fill-color) but depending on your requirements it could get the job done.
.four-point-star::after,
.four-point-star::before {
position: absolute;
top: 0;
left: 0;
content: "\2726";
font-size: 12rem;
}
.four-point-star::after { /* The foreground star */
background: linear-gradient(135deg, rgba(255,191,183,1) 20%, rgba(243,44,117,1) 70%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
.four-point-star::before { /* The star shadow */
color: transparent;
text-shadow: 2px 3px 10px rgba(242, 96, 85, 1);
}
/* Demo styling */
body {
background: #fbd629;
padding: 0 2rem;
}
.four-point-star {
position: relative;
}
<span class="four-point-star"></span>
Clearly, for this kind of shape, and inline SVG would be the simplest and the most crossbrowser solution (and with a responsive pixel perfect output).
Here is a simple inline svg code to make a four point star filled with a gradient:
svg{
display:block; margin:0 auto;
width:30%; height:auto;
}
/* For the demo */ body{background: url('https://farm8.staticflickr.com/7187/6895047173_d4b1a0d798.jpg');background-size:cover;}
<svg viewbox="0 0 10 10">
<defs>
<linearGradient id="starGrad">
<stop offset="0%" stop-color="rgb(153,218,255)" />
<stop offset="100%" stop-color="rgb(0,128,128)"/>
</linearGradient>
</defs>
<path fill="url(#starGrad)" d="M5 1 Q5.8 4.2 9 5 Q5.8 5.8 5 9 Q4.2 5.8 1 5 Q4.2 4.2 5 1z" />
</svg>
The four points are made with the path element and using quadratic bezier curves. The star is filled with an SVG linear gradient.
You can get four point star using two rotated and skewed rectangles.
body {
/* just styles for demo */
background-color: #fdd700;
}
.four-point-star {
width: 100px;
height: 100px;
position: relative;
margin-top: 100px;
margin-left: 100px;
}
.four-point-star:before,
.four-point-star:after {
content: "";
position: absolute;
background-color: #fa5b88;
display: block;
left: 0;
width: 141.4213%; /* 100% * √2 */
top: 0;
bottom: 0;
border-radius: 5%;
transform: rotate(66.66deg) skewX(45deg);
}
/* the same but +90deg to rotate */
.four-point-star:after {
transform: rotate(156.66deg) skew(45deg);
}
<div class="four-point-star"></div>
I would suggest an SVG. If you didn't want another http request for the svg file, you could include the svg code in the 'content' attribute:
content: url("data:image/svg+xml; utf8, <svg.. code here</svg>");
.star-4-point {
background: url("data:image/svg+xml; utf8,<svg version='1.1' id='Layer_1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' x='0px' y='0px' width='50px' height='50px' viewBox='0 0 50 50' style='enable-background:new 0 0 50 50;' xml:space='preserve'><path d='M25,50c0,0,1.325-8.413,8.957-16.043C41.587,26.325,50,25,50,25l0,0c0,0-8.413-1.325-16.043-8.957C26.325,8.413,25,0,25,0 l0,0c0,0-1.325,8.413-8.957,16.043C8.413,23.675,0,25,0,25l0,0c0,0,8.413,1.325,16.043,8.957C23.675,41.588,25,50,25,50'/></svg>");
height: 50px;
width: 50px;
}
<div class="star-4-point"></div>

White border on overlap CSS

Can this be created using CSS :
I have tried using PNG images :
.x {
position:relative;
top: 100px;
left: 0px;
height: 120px;
width: 300px;
display: block;
}
.y {
position:relative;
top: -20px;
left: 0px;
height: 120px;
width: 300px;
display: block;
transform: rotate(60deg);
}
.z {
position:relative;
top: -140px;
left: 0px;
height: 120px;
width: 300px;
display: block;
transform:rotate(-60deg)
}
<img class="x" src="http://i.stack.imgur.com/Qf8Ot.png">
<img class="y" src="http://i.stack.imgur.com/Qf8Ot.png">
<img class="z" src="http://i.stack.imgur.com/Qf8Ot.png">
But I wanted overlap to be white as the first image. Any clues? Thank you very much.
Create ellipses using border-radius.
Add box-shadow to them :
#a, #a:before, #a:after {
height:80px;
width: 300px;
background: transparent;
border-radius: 50%;
border: 5px solid black;
transform: rotate(30deg);
}
#a {
position: relative;
top:100px;
}
#a:before, #a:after {
position: absolute;
content: "";
box-shadow:inset 0 0 0 4px white, 0 0 0 4px white;
}
#a:before {
transform: rotate(60deg);
}
#a:after {
transform: rotate(120deg);
}
<div id="a"></div>
You should use box-shadow. Make the color of shadow white.
Use inset shadow also, it will make shadow inside the image.
box-shadow :inset 0 0 5px #FFF, 0 0 5px #FFF ;
use -webkit-, -moz- , -o- according to your browser requirments.

Shape resembling a compass pointer or inner part of a Safari logo

I am trying to make the below shape using only CSS. I know that achieving this shape using an image or SVG would be a lot easier but I am trying to achieve it with CSS for a proof of concept.
The below is the code that I have tried so far. It creates a diamond shape by using transform: rotate(45deg) but the diagonals are of the same length whereas the shape that I need has one very long diagonal and another very short.
.separator{
background: #555;
top: 40px;
padding-top: 0px;
margin: 0px 40px;
height: 100px;
width: 100px;
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
transform: rotate(45deg);
}
Fiddle Demo
Is it possible to create the shape that I need using CSS?
Note: A similar question was asked earlier and was closed/deleted as "too broad" as it did not show any coding attempt. Posting a new question and self answering it based on this meta discussion. Please feel free to chip in with alternate solutions (or) edit the question to make it more useful for future readers.
For a needle resting on its tip
Yes, it is possible to create that shape using only CSS. You have to rotate the shape along both the Y-axis and the Z-axis to achieve it.
Rotating it along the Z-axis by 45 degrees will produce a diamond shape (as indicated in the question) and rotating it along the Y-axis by close to (but less than) 90 degrees will make only a part of the shape visible from the front and thereby would give it the appearance of having shorter diagonal lines (resembling a compass pointer).
Additionally adding a linear-gradient for the background and a inset box-shadow will help to achieve a shape that is a lot closer to the shape shown in question.
body {
background: #333;
font-family: Calibri;
font-size: 18px;
}
div {
height: 200px;
width: 150px;
display: inline-block;
vertical-align: middle;
color: white;
padding-top: 40px;
}
.separator {
background: #555;
top: 40px;
padding-top: 0px;
height: 160px;
width: 160px;
background-image: linear-gradient(-45deg, #555 0%, #555 40%, #444 50%, #333 97%);
box-shadow: inset 6px 6px 22px 8px #272727;
transform: rotateY(87deg) rotate(45deg);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
<div>
Some lengthy paragraph content which wraps around when it exceeds the width
</div>
<div class='separator'></div>
<div>
Some lengthy paragraph content which wraps around when it exceeds the width
</div>
For a needle resting on its base
For a needle that is resting on its base, the rotation should be along the X-axis and Z-axis instead of along Y-axis and Z-axis for the needle resting on its tip. Below is a sample snippet.
body {
background: #AAA;
font-family: Calibri;
font-size: 18px;
}
div {
height: 200px;
width: 150px;
display: inline-block;
vertical-align: middle;
color: white;
padding-top: 40px;
margin: 40px;
}
.separator {
background: #555;
top: 40px;
padding-top: 0px;
height: 160px;
width: 160px;
background-image: linear-gradient(-45deg, #555 0%, #555 40%, #444 50%, #333 97%);
box-shadow: inset 6px 6px 22px 8px #272727;
transform: rotateX(87deg) rotate(45deg);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
<div class='separator'></div>
Compass Pointer created using above method:
Here is a sample compass pointer (inspired in part by the Safari logo) created purely using CSS. The pointer or the needle inside is created using the method explained above.
.container {
position: relative;
height: 152px;
width: 152px;
padding: 10px;
border-radius: 50%;
background: radial-gradient(circle at 50% 50%, white 58%, #999 70%, #EEE 80%);
border: 1px solid #AAA;
}
.dial {
height: 150px;
width: 150px;
border-radius: 50%;
background: linear-gradient(#1ad4fd, #1d65f0 100%);
border: 1px solid #999;
position: relative;
animation: rotatedial 2s 6 alternate forwards;
}
.dial:after {
content: '';
position: absolute;
top: 25px;
left: 25px;
height: 100px;
width: 100px;
background-image: linear-gradient(-45deg, white 0%, white 47%, red 50%);
box-shadow: inset 0px 6px 22px 0px #CCC, inset -6px -6px 22px 0px #AAA;
transform: rotateY(85deg) rotate(45deg);
}
.dial:before {
content: '';
position: absolute;
top: 72px;
left: 70px;
height: 8px;
width: 8px;
background: radial-gradient(circle at 50% 50%, white 30%, grey 100%);
border: 1px solid #999;
border-radius: 50%;
z-index: 2;
}
.hands,
.hands-small {
position: absolute;
height: 150px;
width: 150px;
top: 11.25px;
left: 11px;
z-index: 0;
}
.hands:before,
.hands:after,
.hands .hand:before,
.hands .hand:after {
content: '';
position: absolute;
top: 0;
left: 74.5px;
width: 1px;
height: 12px;
background: #EEE;
border-radius: 4px;
box-shadow: 0px 138px #EEE;
transform-origin: 50% 75px;
}
.hands-small:before,
.hands-small:after,
.hands-small .hand-small:before,
.hands-small .hand-small:after {
content: '';
position: absolute;
top: 0;
left: 74.5px;
width: 1px;
height: 7px;
background: #EEE;
border-radius: 4px;
box-shadow: 0px 143px #EEE;
transform-origin: 50% 75px;
}
.hands:before {
transform: rotate(-45deg);
}
.hands:after {
transform: rotate(0deg);
}
.hand:before {
transform: rotate(45deg);
}
.hand:after {
transform: rotate(90deg);
}
.hands-small:before {
transform: rotate(-22.5deg);
}
.hands-small:after {
transform: rotate(22.5deg);
}
.hand-small:before {
transform: rotate(67.5deg);
}
.hand-small:after {
transform: rotate(112.5deg);
}
#keyframes rotatedial {
0% {
transform: rotate(35deg);
}
100% {
transform: rotate(15deg);
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
<div class="container">
<div class="dial"></div>
<div class="hands">
<div class="hand"></div>
</div>
<div class="hands-small">
<div class="hand-small"></div>
</div>
</div>
If you stumbled on this page looking for a SVG implementation, have a look at the below snippet:
.separator {
position: relative;
width: 12px;
}
svg {
position: absolute;
top: 0px;
left: 0px;
height: 100%;
width: 100%;
}
path {
fill: url(#MyGradient);
}
path#shade {
stroke: #2E2E2E;
stroke-width: 3;
}
/* Just for the demo to style the divs and position */
body {
background: #333;
font-family: Calibri;
font-size: 18px;
}
.container {
display: flex;
}
.container > .content {
flex: 1;
flex-grow: 1;
color: white;
margin: 20px;
}
<div class='container'>
<div class='content'>Some lengthy paragraph content which wraps around when it exceeds the width.Some lengthy paragraph content which wraps around when it exceeds the width.Some lengthy paragraph content which wraps around when it exceeds the width.</div>
<div class='separator'>
<svg viewBox='0 0 10 200' preserveAspectRatio='none'>
<defs>
<linearGradient id="MyGradient" x1=' 50% ' y1='0% ' x2='50% ' y2='100% '>
<stop offset="0%" stop-color="#333" />
<stop offset="100%" stop-color="#555" />
</linearGradient>
</defs>
<path d='M0,100 5,0 10,100 z' id='shade' />
<path d='M0,100 5,0 10,100 5,200 z ' />
</svg>
</div>
<div class='content '>Some lengthy paragraph content which wraps around when it exceeds the width.Some lengthy paragraph content which wraps around when it exceeds the width.Some lengthy paragraph content which wraps around when it exceeds the width.</div>
</div>

Draw an X in CSS

I've got a div that looks like a orange square
I'd like to draw a white X in this div somehow so that it looks more like
Anyway to do this in CSS or is it going to be easier to just draw this in Photoshop and use the image as the div background? The div code just looks like
div {
height: 100px;
width: 100px;
background-color: #FA6900;
border-radius: 5px;
}
You want an entity known as a cross mark:
http://www.fileformat.info/info/unicode/char/274c/index.htm
The code for it is ❌ and it displays like ❌
If you want a perfectly centered cross mark, like this:
try the following CSS:
div {
height: 100px;
width: 100px;
background-color: #FA6900;
border-radius: 5px;
position: relative;
}
div:after {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
content: "\274c"; /* use the hex value here... */
font-size: 50px;
color: #FFF;
line-height: 100px;
text-align: center;
}
See Demo Fiddle
Cross-Browser Issue
The cross-mark entity does not display with Safari or Chrome. However, the same entity displays well in Firefox, IE and Opera.
It is safe to use the smaller but similarly shaped multiplication sign entity, × which displays as ×.
single element solution:
body{
background:blue;
}
div{
width:40px;
height:40px;
background-color:red;
position:relative;
border-radius:6px;
box-shadow:2px 2px 4px 0 white;
}
div:before,div:after{
content:'';
position:absolute;
width:36px;
height:4px;
background-color:white;
border-radius:2px;
top:16px;
box-shadow:0 0 2px 0 #ccc;
}
div:before{
-webkit-transform:rotate(45deg);
-moz-transform:rotate(45deg);
transform:rotate(45deg);
left:2px;
}
div:after{
-webkit-transform:rotate(-45deg);
-moz-transform:rotate(-45deg);
transform:rotate(-45deg);
right:2px;
}
<div></div>
Yet another pure CSS solution (i.e. without the use of images, characters or additional fonts), based on #Bansoa is the answer's answer .
I've simplified it and added a bit of Flexbox magic to make it responsive.
Cross in this example automatically scales to any square container, and to change the thickness of its lines one have just to tune height: 4px; (to make a cross truly responsive, you may want to set the height in percents or other relative units).
div {
position: relative;
height: 150px; /* this can be anything */
width: 150px; /* ...but maintain 1:1 aspect ratio */
display: flex;
flex-direction: column;
justify-content: center;
}
div::before,
div::after {
position: absolute;
content: '';
width: 100%;
height: 4px; /* cross thickness */
background-color: black;
}
div::before {
transform: rotate(45deg);
}
div::after {
transform: rotate(-45deg);
}
<div></div>
You can make a pretty nice X with CSS gradients:
demo: https://codepen.io/JasonWoof/pen/rZyRKR
code:
<span class="close-x"></span>
<style>
.close-x {
display: inline-block;
width: 20px;
height: 20px;
border: 7px solid #f56b00;
background:
linear-gradient(45deg, rgba(0,0,0,0) 0%,rgba(0,0,0,0) 43%,#fff 45%,#fff 55%,rgba(0,0,0,0) 57%,rgba(0,0,0,0) 100%),
linear-gradient(135deg, #f56b00 0%,#f56b00 43%,#fff 45%,#fff 55%,#f56b00 57%,#f56b00 100%);
}
</style>
Yet another attempt... this one uses ×. A lot of the examples on this page only show for me as a box, but × works
HTML
<div class="close"></div>
CSS
.close {
height: 100px;
width: 100px;
background-color: #FA6900;
border-radius: 5px;
}
.close:after {
position:relative;
content:"\d7";
font-size:177px;
color:white;
font-weight:bold;
top:-53px;
left:-2px
}
JSFIDDLE
You could just put the letter X in the HTML inside the div and then style it with css.
See JSFiddle: http://jsfiddle.net/uSwbN/
HTML:
<div id="orangeBox">
<span id="x">X</span>
</div>
CSS:
#orangeBox {
background: #f90;
color: #fff;
font-family: 'Helvetica', 'Arial', sans-serif;
font-size: 2em;
font-weight: bold;
text-align: center;
width: 40px;
height: 40px;
border-radius: 5px;
}
You can use the CSS property "content":
div {
height: 100px;
width: 100px;
background-color: #FA6900;
border-radius: 5px;
}
div:after {
content: "X";
font-size: 2em;
color: #FFF;
}
Like this:
http://jsfiddle.net/HKtFV/
#x{
width: 20px;
height: 20px;
background-color:orange;
position:relative;
border-radius:2px;
}
#x::after,#x::before{
position:absolute;
top:9px;
left:0px;
content:'';
display:block;
width:20px;
height:2px;
background-color:red;
}
#x::after{
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-ms-transform: rotate(45deg);
-o-transform: rotate(45deg);
transform: rotate(45deg);
}
#x::before{
-webkit-transform: rotate(-45deg);
-moz-transform: rotate(-45deg);
-ms-transform: rotate(-45deg);
-o-transform: rotate(-45deg);
transform: rotate(-45deg);
}
<div id=x>
</div>
I love this question! You could easily adapt my code below to be a white × on an orange square:
Demo fiddle here
Here is the SCSS (which could easily be converted to CSS):
$pFontSize: 18px;
p {
font-size: $pFontSize;
}
span{
font-weight: bold;
}
.x-overlay,
.x-emoji-overlay {
position: relative;
}
.x-overlay,
.x-emoji-overlay {
&:after {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
color: red;
text-align: center;
}
}
.x-overlay:after {
content: '\d7';
font-size: 3 * $pFontSize;
line-height: $pFontSize;
opacity: 0.7;
}
.x-emoji-overlay:after {
content: "\274c";
padding: 3px;
font-size: 1.5 * $pFontSize;
line-height: $pFontSize;
opacity: 0.5;
}
.strike {
position: relative;
display: inline-block;
}
.strike::before {
content: '';
border-bottom: 2px solid red;
width: 110%;
position: absolute;
left: -2px;
top: 46%;
}
.crossed-out {
/*inspired by https://www.tjvantoll.com/2013/09/12/building-custom-text-strikethroughs-with-css/*/
position: relative;
display: inline-block;
&::before,
&::after {
content: '';
width: 110%;
position: absolute;
left: -2px;
top: 45%;
opacity: 0.7;
}
&::before {
border-bottom: 2px solid red;
-webkit-transform: skewY(-20deg);
transform: skewY(-20deg);
}
&::after {
border-bottom: 2px solid red;
-webkit-transform: skewY(20deg);
transform: skewY(20deg);
}
}
You could do this by styling an "x"
text-align: center;
font-size: 120px;
line-height: 100px;
color: white;
font-family: monospace;
http://jsfiddle.net/Ncvyj/1/
Here is a single div and dynamic size version without using pseudo element.
body {
display: flex;
gap: 30px;
}
.x {
--color: #444;
--l: 5px; /* line-width */
width: 50px;
height: 50px;
background: linear-gradient(to top right, transparent calc(50% - var(--l) / 2), var(--color) calc(50% - var(--l) / 2) calc(50% + var(--l) / 2), transparent calc(50% + var(--l) / 2)),
linear-gradient(to bottom right, transparent calc(50% - var(--l) / 2), var(--color) calc(50% - var(--l) / 2) calc(50% + var(--l) / 2), transparent calc(50% + var(--l) / 2));
--clip-path: polygon(var(--l) 0%, calc(100% - var(--l)) 0%, 100% var(--l), 100% calc(100% - var(--l)), calc(100% - var(--l)) 100%, var(--l) 100%, 0% calc(100% - var(--l)), 0% var(--l));
-webkit-clip-path: var(--clip-path);
clip-path: var(--clip-path);
}
<div class="x"></div>
<div class="x" style="--l: 10px;"></div>
<div class="x" style="--l: 15px; --color: red"></div>
<div class="x" style="--l: 15px; --color: dodgerblue; width: 100px; height: 100px;"></div>
HTML
<div class="close-orange"></div>
CSS
.close-orange {
height: 100px;
width: 100px;
background-color: #FA6900;
border-radius: 5px;
}
.close-orange:before,.close-orange:after{
content:'';
position:absolute;
width: 50px;
height: 4px;
background-color:white;
border-radius:2px;
top: 55px;
}
.close-orange:before{
-webkit-transform:rotate(45deg);
-moz-transform:rotate(45deg);
transform:rotate(45deg);
left: 32.5px;
}
.close-orange:after{
-webkit-transform:rotate(-45deg);
-moz-transform:rotate(-45deg);
transform:rotate(-45deg);
left: 32.5px;
}
https://jsfiddle.net/cooperwebdesign/dw4xd289/
A modern answer with good browser support.
<span>×</span>
This technically puts the multiplication symbol there, but no one will really notice (found some websites that have a popup box and most use this for the x button).
If you need more control you can style it with color opacity etc...
example (index.html)
<span class="x-button">×</span>
styles.css
span.x-button {
color:gray;
opacity:0.7;
font-size:1.5em;
}
Result (first example)
<span>&times</span>
Result (2nd example)
span {
color:gray;
opacity:0.7;
font-size:1.5em;
}
<span class="x-button">×</span>
Note: you can highlight this unlike other solutions, but this may not be desirable depending on the application. You can solve this in pure css too, just add
user-select:none;
-webkit-user-select:none;
This is an adaptable version of the amazing solution provided by #Gildas.Tambo elsewhere in this page.
Simply change the values of the variables at the top to change the size of the "X".
Credit for the solution itself goes to Gildas. All I've done is given it adaptable math.
:root {
/* Width and height of the box containing the "X" */
--BUTTON_W: 40px;
/* This is the length of either of the 2 lines which form the "X", as a
percentage of the width of the button. */
--CLOSE_X_W: 95%;
/* Thickness of the lines of the "X" */
--CLOSE_X_THICKNESS: 4px;
}
body{
background:blue;
}
div{
width: var(--BUTTON_W);
height: var(--BUTTON_W);
background-color:red;
position: relative;
border-radius: 6px;
box-shadow: 2px 2px 4px 0 white;
}
/* The "X" in the button. "before" and "after" each represent one of the two lines of the "X" */
div:before,div:after{
content: '';
position: absolute;
width: var(--CLOSE_X_W);
height: var(--CLOSE_X_THICKNESS);
background-color:white;
border-radius: 2px;
top: calc(50% - var(--CLOSE_X_THICKNESS) / 2);
box-shadow: 0 0 2px 0 #ccc;
}
/* One line of the "X" */
div:before{
-webkit-transform:rotate(45deg);
-moz-transform: rotate(45deg);
transform: rotate(45deg);
left: calc((100% - var(--CLOSE_X_W)) / 2);
}
/* The other line of the "X" */
div:after{
-webkit-transform:rotate(-45deg);
-moz-transform: rotate(-45deg);
transform: rotate(-45deg);
right: calc((100% - var(--CLOSE_X_W)) / 2);
}
<div></div>
Check & and Cross:
<span class='act-html-check'></span>
<span class='act-html-cross'><span class='act-html-cross'></span></span>
<style type="text/css">
span.act-html-check {
display: inline-block;
width: 12px;
height: 18px;
border: solid limegreen;
border-width: 0 5px 5px 0;
transform: rotate( 45deg);
}
span.act-html-cross {
display: inline-block;
width: 10px;
height: 10px;
border: solid red;
border-width: 0 5px 5px 0;
transform: rotate( 45deg);
position: relative;
}
span.act-html-cross > span { {
transform: rotate( -180deg);
position: absolute;
left: 9px;
top: 9px;
}
</style>