This question already has answers here:
draw diagonal lines in div background with CSS
(13 answers)
Closed 8 years ago.
I need to draw in my div diagonal line. It should look like this:
My HTML:
<div style="height: 28px; width: 28px; border: 1px solid rgb(219,225,230);background-color:white;" >
</div>
Is it possible to do it only with CSS?
You can achieve the desired effect by using just one single div. Check the DEMO.
div{
border:1px solid gray;
width:28px;
height:28px;
position:relative;
}
div:after{
content:"";
position:absolute;
border-top:1px solid red;
width:40px;
transform: rotate(45deg);
transform-origin: 0% 0%;
}
Note: please add the vendor prefix for older browsers i.e. -moz, -webkit.
Using CSS transform property you can achieve this. Look at the following HTML and CSS.
HTML
<div style="border: 1px solid #000; width:100px; height:100px;">
<div id="hr" style="border-top:1px solid #ff00ff; height:100px; margin-left:-140px;"></div>
</div>
CSS
#hr {
-moz-transform: rotate(45deg);
-o-transform: rotate(45deg);
-webkit-transform: rotate(45deg);
-ms-transform: rotate(45deg);
transform: rotate(45deg);
}
DEMO
You could also use two elements and theirs borders like that :
The HTML :
<div class="top-left">
<div class="cross-a"></div>
<div class="cross-b"></div>
</div>
The CSS :
.top-left {
position: absolute;
top: 0;
left: 0;
height: 28px;
width: 28px;
border-top: solid 2px #fff;
border-left: solid 2px #fff;
}
.cross-a, .cross-b {
position:absolute;
width:0;
height:0;
}
.cross-a {
top: -2px;
left: -2px;
border-top: 28px solid transparent;
border-right: 28px solid #000;
}
.cross-b {
top: 0px;
left: 0px;
border-top: 26px solid transparent;
border-right: 26px solid #FFFFFF;
}
The fiddle : http://jsfiddle.net/9yK6q/7/
You could use a hr element or a other element and rotate it.
Here is a demo: http://jsfiddle.net/9HXTe/
div, hr {
-moz-transform: rotate(7.5deg);
-o-transform: rotate(7.5deg);
-webkit-transform: rotate(7.5deg);
-ms-transform: rotate(7.5deg);
transform: rotate(7.5deg);
}
Related
I am creating a web application and I need to add a ui wizard to that only using html, js, and css. It was achievable. But here need to change the shapes of the steps as in the attached image. In addition to the image I need to remove the gap between each steps. For that I need some css support. So anyone have an idea to create this ui using pure css & html?
#flowBoxes {
margin:auto;
padding:20px;
min-width:700px;
}
#flowBoxes div {
display:inline-block;
position:relative;
height:25px;
line-height:25px;
padding:0 20px;
border:1px solid #ccc;
margin-right:-4px;
background-color:white;
}
#flowBoxes div.right:after{
content:'';
border-top:1px solid #ccc;
border-right:1px solid #ccc;
width:18px;
height:18px;
position:absolute;
right:0;
top:-1px;
background-color:white;
z-index:150;
-webkit-transform: translate(10px,4px) rotate(45deg);
-moz-transform: translate(10px,4px) rotate(45deg);
-ms-transform: translate(10px,4px) rotate(45deg);
-o-transform: translate(10px,4px) rotate(20deg);
transform: translate(10px,4px) rotate(45deg);
}
#flowBoxes div.left:before{
content:'';
width:18px;
height:18px;
position:absolute;
left:0;
top:-1px;
background-color:white;
z-index:50;
-webkit-transform: translate(-10px,4px) rotate(45deg);
-moz-transform: translate(-10px,4px) rotate(45deg);
-ms-transform: translate(-10px,4px) rotate(45deg);
-o-transform: translate(-10px,4px) rotate(20deg);
transform: translate(-10px,4px) rotate(45deg);
}
#flowBoxes .active{
background-color:green;
color:white;
}
#flowBoxes div.active:after{
background-color:green;
}
<div id="flowBoxes">
<div class="right">Step 1</div>
<div class="left right active">Step 2</div>
<div class="left right">Step 3</div>
<div class="left right">Step 4</div>
<div class="left">Step 5</div>
</div>
I think this is what you are looking for.
I am adding this as another answer because the first answer was really simple and can help others too..
Page Navigation Wizzard UI
I've made changes to that code and here you have the updated snippet.
I hope this is simple to understand.
Please change color as per ur needs.
ul {
display: flex;
}
.arrow-pointer {
list-style: none;
display: flex;
align-items: center;
justify-content: center;
margin-right: 25px;
}
.arrow-pointer {
width: 250px;
height: 50px;
background: gray;
position: relative;
}
.arrow-pointer:not(:first-child):after {
content: '';
position: absolute;
left: 0; bottom: 0; width: 0; height: 0;
border-left: 25px solid white;
border-top: 25px solid transparent;
border-bottom: 25px solid transparent;
}
.arrow-pointer:not(:last-child):before {
content: '';
position: absolute;
right: -25px;
bottom: 0;
width: 0;
height: 0;
border-left: 25px solid gray;
border-top: 25px solid transparent;
border-bottom: 25px solid transparent;
}
<!DOCTYPE html>
<html>
<body>
<h1>The ul element</h1>
<ul>
<li class="arrow-pointer">Step 1</li>
<li class="arrow-pointer">Step 2</li>
<li class="arrow-pointer">Step 3</li>
</ul>
</body>
</html>
Iam trying to make a double hexagon border around my image. Here is my fiddle, which didnt come far:
https://jsfiddle.net/qeh8wdsd/
code:
<div class="hex">
<div class="hex inner">
<div class="hex inner2">
<img src="http://www.jqueryscript.net/images/Simplest-Responsive-jQuery-Image-Lightbox-Plugin-simple-lightbox.jpg"/>
</div>
</div>
</div>
.hex {
margin-top: 70px;
width: 208px;
height: 120px;
background: #000;
position: relative;
}
.hex:before, .hex:after {
content:"";
border-left: 104px solid transparent;
border-right: 104px solid transparent;
position: absolute;
}
.hex:before {
top: -59px;
border-bottom: 60px solid #000;
}
.hex:after {
bottom: -59px;
border-top: 60px solid #000;
}
.hex.inner {
background-color:blue;
-webkit-transform: scale(.8, .8);
-moz-transform: scale(.8, .8);
transform: scale(.8, .8);
z-index:1;
}
.hex.inner:before {
border-bottom: 60px solid blue;
}
.hex.inner:after {
border-top: 60px solid blue;
}
.hex.inner2 {
background-color:red;
-webkit-transform: scale(.8, .8);
-moz-transform: scale(.8, .8);
transform: scale(.8, .8);
z-index:2;
}
.hex.inner2:before {
border-bottom: 60px solid red;
}
.hex.inner2:after {
border-top: 60px solid red;
}
so i want the image to be where the red hexagon is, basically the image should be inside and "clipped" to a hexagon and then i want a blue and a black border around it which is about 2px each. And the second issue is that i want to make it responsive. Hope anyone can help me achieve this.
The CSS property of clip-path should be able to provide you with the functionality you are looking for natively, particularly the polygon option.
You can define custom shapes for clipping, including a hexagon, and provides a high level of customization.
Here's a link for more info on this: css-tricks clip-path
This question already has answers here:
Responsive CSS triangle with percents width
(7 answers)
Closed 8 years ago.
I need to create grid with a down arrow. See the image below:
The problem is that the div has a variable width because of .col-xs-3. How can I give the arrow (:after element) the appropriate width so that it will still be responsive?
My CSS:
.grid-arrow::after {
content: " ";
display: block;
width: 0;
height: 0;
border-top: 47px solid transparent;
border-bottom: 47px solid transparent;
border-left: 40px solid rgb(173, 173, 173);
position: absolute;
/* top: 50%; */
margin-top: -37px;
/* margin-left: 1px; */
left: 50%;
z-index: 3;
-webkit-transform: rotate(90deg);
-ms-transform: rotate(90deg);
transform: rotate(90deg);
}
My HTML:
<div class="col-xs-3 advantage grid-arrow">
<div>
Some text
</div>
</div>
As pointed out by #ochi, there is already a solution that might work for you.
Bringing it back to your code, it would be something like this:
HTML:
<div class="col-xs-3 advantage grid-arrow">
<div>
Some text.
</div>
</div>
CSS:
.grid-arrow {
position: relative;
text-align: center;
background-color: red;
line-height: 2em;
border-top:300px solid #fff;
top:-300px;
}
.grid-arrow::after {
content: "";
position: absolute;
left: 0;
background-color: red;
padding-bottom: 50%;
width:57.7%;
z-index:-1;
-webkit-transform-origin:0 0;
-ms-transform-origin:0 0;
transform-origin:0 0;
-webkit-transform: rotate(-30deg) skewX(30deg);;
-ms-transform: rotate(-30deg) skewX(30deg);
transform: rotate(-30deg) skewX(30deg);
}
See JsFiddle.
I have created a skewed div using following css
#outer-left{
-ms-transform: skew(-30deg,0deg); /* IE 9 */
-webkit-transform:skew(-30deg,0deg); /* Chrome, Safari, Opera */
transform: skew(-30deg,0deg);
background:#333333;
width:200px;
z-index:20;
border-bottom:3px solid #2E8DEF;
padding:10px 30px 10px 75px;
font-size:20px;
color:#2E8DEF;
position:relative;
left:-50px;
}
#outer-left:after{
content:"";
display:inline-block;
position:absolute;
width:20px;
height:100%;
background:#2E8DEF;
float:right;
right:0px;
top:0px;
z-index:10;
}
#inner-left{
-ms-transform: skew(30deg,0deg); /* IE 9 */
-webkit-transform: skew(30deg,0deg); /* Chrome, Safari, Opera */
transform: skew(30deg,0deg);
display:inline-block;
}
And used two divs i.e. outer div to skew border and div and inner div to cancel the skew effect for text.
But I have achieved same effect using only one div in div3
Look at fiddle: http://jsfiddle.net/5a7rhh0L/
IF I do the same as in div 3 with more text it gets distorted.
But not so in case of div2 with more text using 2 divs.
I am completely aware of what is happening here. I want to know if DIV2 can be achieved using only one div i.e. <div id="inner-div">Context<br>Hello</div> and now without using two divs i.e. inner and outer one.
I believe this is what you want:
http://jsfiddle.net/5a7rhh0L/3/
CSS:
#a {
position: relative;
width: 120px;
padding: 10px 20px;
font-size: 20px;
position: relative;
color: #2E8DEF;
background: #333333;
border-bottom: 3px solid #2E8DEF;
}
#a:after {
content: " ";
position: absolute;
display: block;
width: 100%;
height: 100%;
top: 0;
left: 0;
z-index: -1;
background: #333333;
border-bottom: 3px solid #2E8DEF;
border-right: 20px solid #2E8DEF;
transform-origin: bottom left;
-ms-transform: skew(-30deg, 0deg);
-webkit-transform: skew(-30deg, 0deg);
transform: skew(-30deg, 0deg);
}
I want create one circle with CSS that cut off one piece (like pizza :D) but I don't know about it. please guide me how to create one circle like pizza that one piece cut off.
this is my code :
HTML:
<div class="state"></div>
CSS:
.state {
position: absolute;
height: 44px;
width: 44px;
right: 5px;
top: 0;
border: 3px solid transparent;
border-radius: 25px;
z-index: 1;
border-color: #82ba00
}
I want create this image :
Using the link RJo provided and the demo in one of the answers I came up with this:
<div class="arc-wrapper">
<div class="arc arc_start"></div>
<div class="arc arc_end"></div>
</div>
.arc-wrapper {
position:relative;
margin:20px;
}
.arc {
position:absolute;
top:0;
left:0;
width: 100px;
height: 100px;
border-radius:100%;
border:1px solid;
border: 10px solid;
border-color: #82ba00;
}
.arc_start {
border-color:#82ba00 transparent;
-webkit-transform: rotate(-65deg);
-moz-transform: rotate(-65deg);
-ms-transform: rotate(-65deg);
-o-transform: rotate(-65deg);
transform: rotate(-65deg);
}
.arc_end {
border-color: transparent #82ba00 #82ba00 #82ba00;
-webkit-transform: rotate(-110deg);
-moz-transform: rotate(-110deg);
-ms-transform: rotate(-110deg);
-o-transform: rotate(-110deg);
transform: rotate(-110deg);
}
You can change the size and direction of the gap by changing the rotate(deg) values.
Demo: http://jsfiddle.net/mmetsalu/JmruQ/
Here is the solution.
Working Fiddle
Inspiration from magnifying glass shape from this LINK
EDIT: This is a adjustable arc too. So you can increase or decrease size of the circle only by making one change to this line in the CSS
font-size: 15em; /* This controls the size. */
CSS
#pie {
font-size: 15em;
/* This controls the size. */
display: inline-block;
width: 0.5em;
height: 0.5em;
border: 0.05em solid #00cc00;
position: relative;
border-radius: 0.35em;
}
#pie::before {
content:"";
display: inline-block;
position: absolute;
right: 0.33em;
bottom: 0em;
border-width: 0;
background: white;
width: 0.22em;
height: 0.12em;
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-ms-transform: rotate(45deg);
-o-transform: rotate(45deg);
}
HTML
<div id="pie"><div>
EDIT 2:
Here is a fiddle of a Canvas based solution. Personally i feel you should use this method.
FIDDLE
Code borrowed from Tharindulucky
See this fiddle: http://jsfiddle.net/avrahamcool/vqu5d/
HTML:
<div id="circle"></div>
CSS:
#circle {
width: 50px;
height: 50px;
border-radius: 50%;
border: 10px solid green;
border-bottom-color: transparent;
transform:rotate(30deg);
}
You can easily do it by using HTML5 Canvas element.
First write the code for cavas. (Just like a div.)
<canvas id="myCanvas" width="200" height="100" style="border: 1px solid black;"></canvas>
And then write the script for it
<script>
var d=document.getElementById("myCanvas");
var dtx=d.getContext("2d");
dtx.beginPath();
dtx.arc(95,50,40,0,1.8*Math.PI);
dtx.lineWidth = 5;
dtx.stroke();
</script>
It will produce what you want. Have fun!
For more advanced reference, http://www.html5canvastutorials.com/tutorials/html5-canvas-circles/