I am trying to draw a line with a small arrow pointing down as in the image attached.
I was able to get it working on fiddle using before and after psuedo tags ( with help from Stack overflow).
<hr class="line">
http://jsfiddle.net/4eL39sm1/6/
But I now need it in a div tag like this
<div class="hr"></div>
I have edited my css accordingly
div.hr{
width:70%;
}
div.hr:after {
content:'';
position: absolute;
border-style: solid;
border-width: 15px 15px 0;
border-color: #FFFFFF transparent;
display: block;
width: 0;
z-index: 1;
top: 8px;
left: 45%;
}
div.hr:before {
content:'';
position: absolute;
border-style: solid;
border-width: 15px 15px 0;
border-color: #7F7F7F transparent;
display: block;
width: 0;
z-index: 1;
top: 9px;
left: 45%;
}
I made these 2 observations:
The arrow part looks a solid triangle.
The arrow (triangle was mispalced was up in the top). I removed the top value form css and it aligned well but it still looks like a triangle.
Is there a way I can fix this?
Thanks.
You can modify to this:
div.hr {
width:70%;
height: 1px;
background: #7F7F7F;
}
div.hr:after {
content:'';
position: absolute;
border-style: solid;
border-width: 15px 15px 0;
border-color: #FFFFFF transparent;
display: block;
width: 0;
z-index: 1;
top: 8px;
left: 35%;
}
div.hr:before {
content:'';
position: absolute;
border-style: solid;
border-width: 15px 15px 0;
border-color: #7F7F7F transparent;
display: block;
width: 0;
z-index: 1;
top: 9px;
left: 35%;
}
<div class="hr"></div>
As you can see you don't have to remove top from pseudo-elements. The only thing you have to add is height: 1px and background color same as the second triangle.
Also if you wan to use it inside another element for example and align to center you can use this:
div.hr {
width:70%;
height: 1px;
background: #7F7F7F;
position: relative;
margin: 0 auto;
}
div.hr:after {
content:'';
position: absolute;
border-style: solid;
border-width: 15px 15px 0;
border-color: #FFFFFF transparent;
display: block;
width: 0;
z-index: 1;
left: 50%;
}
div.hr:before {
content:'';
position: absolute;
border-style: solid;
border-width: 15px 15px 0;
border-color: #7F7F7F transparent;
display: block;
width: 0;
z-index: 1;
left: 50%;
}
<div>
<div class="hr"></div>
</div>
p.s. By the way i was the person who answered in your first post :)
After conversation with #user3861559 i created an approach for his situation. Instead of pseudo-elements I use nested divs with the same result:
div.hr {
width:70%;
height: 1px;
background: #7F7F7F;
}
div.after {
position: absolute;
border-style: solid;
border-width: 15px 15px 0;
border-color: #FFFFFF transparent;
display: block;
width: 0;
z-index: 1;
top: 8px;
left: 35%;
}
div.before {
position: absolute;
border-style: solid;
border-width: 15px 15px 0;
border-color: #7F7F7F transparent;
display: block;
width: 0;
z-index: 1;
top: 9px;
left: 35%;
}
<div class="hr">
<div class="before"></div>
<div class="after"></div>
</div>
Related
I have a wizard with divs with two arrows with this html
.container {
padding: 10px 20px;
display: flex;
}
div.arrow {
width: 261.5px;
height: 50px;
background-color: #d3d3d3;
position: relative;
margin-right: 30px;
text-align: center;
line-height: 50px;
}
.current {
filter: drop-shadow(2px 3px 7px grey);
}
div.arrow::after {
content: "";
position: absolute;
top: 0;
border: 0 solid #d3d3d3;
border-width: 25px 10px;
width: 0;
height: 0;
left: 100%;
border-color: transparent transparent transparent #d3d3d3;
}
div.arrow::before {
content: "";
position: absolute;
top: 0;
border: 0 solid #d3d3d3;
border-width: 25px 10px;
width: 0;
height: 0;
left: -20px;
border-left-color: transparent;
}
<div class="container">
<div class="arrow">Previous status</div>
<div class="arrow current">Current status</div>
</div>
I have a class called "current" where I applied a drop-shadow effect. It works fine but IE doesn't support it and I can't find a solution for solving this issue. Any help to solve this problem? I can't edit the existing css...
Here a codepen: https://codepen.io/andy_888/pen/bGdKxjv
Thank you
I have tried to tweak the CSS from
http://jsfiddle.net/wn7JN/ to place an arrow in a <div> in the top left corner (see image below), but I can't seem to figure out how :before and :after in CSS work. Every time I update the bottom and left parameters I am left with a black arrow in the top left corner - I think the proper rotation is transform: rotate(220deg) but that is really a guess.
Edit: Is it possible to do this same CSS trick with an rgba color such as rgba(255, 123, 172, 0.25)? When I test it out the transparency becomes an issue with the border overlap.
Any help would be greatly appreciated.
.bubble {
position: relative;
width: 400px;
height: 250px;
padding: 0px;
background: #FFFFFF;
border: #000 solid 1px;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
border-radius: 10px;
}
.bubble:after {
content: "";
position: absolute;
bottom: -25px;
left: 175px;
border-style: solid;
border-width: 25px 25px 0;
border-color: #FFFFFF transparent;
display: block;
width: 0;
z-index: 1;
}
.bubble:before {
content: "";
position: absolute;
top: 250px;
left: 174px;
border-style: solid;
border-width: 26px 26px 0;
border-color: #000 transparent;
display: block;
width: 0;
z-index: 0;
}
<div class="bubble"> </div>
Try like this. Added a working copy.
.bubble {
position: relative;
background:#cbe8f0;
height: 100px;
width:170px;
margin-left:30px;
border-radius:2px;
}
.bubble:after{
content:'';
position:absolute;
border:10px solid transparent;
border-top:10px solid #cbe8f0;
top:0px;
left:-10px;
}
<div class="bubble"> </div>
You can ty this solution too based on the jsfiddle.
.bubble:after
{
content: "";
position: absolute;
top:0px;
left: -21px;
border-style: solid;
border-width: 24px 0px 0px 28px;
border-color: #FFFFFF transparent;
display: block;
width: 0;
z-index: 1;
}
.bubble:before
{
content: "";
position: absolute;
top:-1px;
left:-23px;
border-style: solid;
border-width:20px 0px 0px 23px;
border-color: #000 transparent;
display: block;
width: 0;
z-index: 0;
}
http://jsfiddle.net/wn7JN/1295/
So, here's your bubble code:
.bubble {
position: relative;
width: 400px;
height: 250px;
padding: 0px;
background: #FFFFFF;
border: #000 solid 1px;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
border-radius: 10px;
}
Add this line to the bottom of that: margin-left:25px; This allows there to be room to the side of your bubble for the arrow to even show up. Otherwise, it's there, but you can't see it.
for your bubble:after, change the bottom: -25px to top: 21px and change left: 175px to left: -37px, and add transform: rotate(90deg); to the bottom.
for your bubble:before, change the top: 250px to top: 20px and change left: 174px to left: -39px, and add transform: rotate(90deg); to the bottom.
You will wind up with something like this:
1
Final fiddle: http://jsfiddle.net/eq6mhbwy/
Below is code for downward arrow. I am trying to make it to upward but no success till now.
Can anyone help me with this?
.line {
width: 70%;
}
.line:after {
content: '';
position: absolute;
border-style: solid;
border-width: 7px 7px 0;
border-color: #FFFFFF transparent;
display: block;
width: 0;
z-index: 1;
top: 8px;
left: 45%;
}
.line:before {
content: '';
position: absolute;
border-style: solid;
border-width: 7px 7px 0;
border-color: #7F7F7F transparent;
display: block;
width: 0;
z-index: 1;
top: 9px;
left: 45%;
}
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<hr class="line">
</body>
</html>
I just wanted to show the upward arrow between the hr tag.
https://www.w3schools.com/code/tryit.asp?filename=FG5LJQ77HPXS
There it is, you should just play a little bit with border-width and then correct the topand left position
Arrow Up
.up {
width: 70%;
}
.up:after {
content: '';
position: absolute;
border-style: solid;
border-width: 0px 7px 7px 7px;
border-color: white transparent;
display: block;
width: 0;
z-index: 1;
top: 3px;
left: 45%;
}
.up:before {
content: '';
position: absolute;
border-style: solid;
border-width: 0px 7px 7px 7px;
border-color: #7F7F7F transparent;
display: block;
width: 0;
z-index: 1;
top: 2px;
left: 45%;
}
<div class="up"></div>
Arrow Left
.up {
width: 70%;
}
.up:after {
content: '';
position: absolute;
border-style: solid;
border-width: 7px 7px 7px 0px;
border-color: transparent white;
display: block;
width: 0;
z-index: 1;
top: 3px;
left: 45%;
}
.up:before {
content: '';
position: absolute;
border-style: solid;
border-width: 7px 7px 7px 0px;
border-color: transparent #7F7F7F;
display: block;
width: 0;
z-index: 1;
top: 3px;
left: 44.8%;
}
<div class="up"></div>
Arrow Right
.up {
width: 70%;
}
.up:after {
content: '';
position: absolute;
border-style: solid;
border-width: 7px 0px 7px 7px;
border-color: transparent white;
display: block;
width: 0;
z-index: 1;
top: 3px;
left: 45%;
}
.up:before {
content: '';
position: absolute;
border-style: solid;
border-width: 7px 0px 7px 7px;
border-color: transparent #7F7F7F;
display: block;
width: 0;
z-index: 1;
top: 3px;
left: 45.1%;
}
<div class="up"></div>
Arrow Down
.up {
width: 70%;
}
.up:after {
content: '';
position: absolute;
border-style: solid;
border-width: 7px 7px 0px 7px;
border-color: white transparent;
display: block;
width: 0;
z-index: 1;
top: 3px;
left: 45%;
}
.up:before {
content: '';
position: absolute;
border-style: solid;
border-width: 7px 7px 0px 7px;
border-color: #7F7F7F transparent;
display: block;
width: 0;
z-index: 1;
top: 4px;
left: 45%;
}
<div class="up"></div>
Working solution
.line {
width: 70%;
}
.line:after {
content: '';
position: absolute;
border-style: solid;
border-width: 0px 7px 7px 7px;
border-color: #FFFFFF transparent;
display: block;
width: 0;
z-index: 1;
top: 3px;
left: 45%;
}
.line:before {
content: '';
position: absolute;
border-style: solid;
border-width: 0px 7px 7px 7px;
border-color: #7F7F7F transparent;
display: block;
width: 0;
z-index: 1;
top: 2px;
left: 45%;
}
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<hr class="line">
</body>
</html>
To have the up arrow use this code
.line {
width:70%;
}
.line:after {
content:'';
position: absolute;
border-style: solid;
border-width: 0px 7px 7px 7px;
border-color: #FFFFFF transparent;
display: block;
width: 0;
z-index: 1;
top: 2px;
left: 45%;
}
.line:before {
content:'';
position: absolute;
border-style: solid;
border-width: 0px 7px 7px 7px;
border-color: #7F7F7F transparent;
display: block;
width: 0;
z-index: 1;
top: 1px;
left: 45%;
}
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<hr class="line">
</body>
</html>
tried with your code, and finally i did it..try my code..!
<!DOCTYPE html>
<html>
<head>
<style>
.line {
width:70%;
}
.line::before {
border-color: #7f7f7f transparent;
border-style: solid;
border-width: 0 7px 7px;
content: "";
display: block;
left: 45%;
position: absolute;
top: 2px;
width: 0;
z-index: 1;
}
.line::after {
border-color: #ffffff transparent;
border-style: solid;
border-width: 0 7px 7px;
content: "";
display: block;
left: 45%;
position: absolute;
top: 3px;
width: 0;
z-index: 1;
}
</style>
</head>
<body>
<hr class="line">
</body>
</html>
Do you mean it like that?
.line {
position: relative;
width: 70%;
}
.line:after {
content:'';
position: absolute;
border-style: solid;
border-width: 0px 7px 7px 7px;
border-color: #FFFFFF transparent;
display: block;
width: 0;
z-index: 1;
top: -6px;
left: 45%;
}
.line:before {
content:'';
position: absolute;
border-style: solid;
border-width: 0px 7px 7px 7px;
border-color: #7F7F7F transparent;
display: block;
width: 0;
z-index: 1;
top: -7px;
left: 45%;
}
First we make an upward arrow by changing the :after and :before 's border-width from 0 7px 7px to 7px 7px 0. Then we updated the top position so it will fit in the hr element :)
.line {
width:70%;
}
.line:after {
content:'';
position: absolute;
border-style: solid;
border-width: 0 7px 7px;
border-color: #FFFFFF transparent;
display: block;
width: 0;
z-index: 1;
top: 3px;
left: 45%;
}
.line:before {
content:'';
position: absolute;
border-style: solid;
border-width: 0 7px 7px;
border-color: #7F7F7F transparent;
display: block;
width: 0;
z-index: 1;
top: 2px;
left: 45%;
}
<hr class="line">
Right, I ran into a bit of a problem and not to sure if this can be solved another way.
I need to move the content: "F"; and center it onto the border I have in the top left corner. Now is this possible without creating another element?
HTML:
<div class="userBoxF"></div>
CSS:
.userBoxF {
width: 200px;
height: 200px;
background: #eee;
border: 1px solid;
border-radius: 10px;
position: relative;
overflow: hidden;
}
.userBoxF:after {
content: "F";
position: absolute;
top: 0;
left: 0;
width: 0;
height: 0;
border: 40px solid #F385FF;
border-right-color: transparent;
border-bottom-color: transparent;
font-size: 30px;
}
The only way I can think to do it is to create the corner as a completely separate element so I can put the text "F" into a span (or something) and move it that way.
Demo Here
Note: Nothing here will change size, width and height for both the box and corner will always be the same.
Here is what I want, using the solution i found but would rather not use.
HTML:
<div class="userBoxF">
<div class="corner"><span>F</span></div>
</div>
CSS:
.userBoxF {
width: 200px;
height: 200px;
background: #eee;
border: 1px solid;
border-radius: 10px;
position: relative;
overflow: hidden;
}
.userBoxF .corner {
position: absolute;
top: 0;
left: 0;
width: 0;
height: 0;
border: 40px solid #F385FF;
border-right-color: transparent;
border-bottom-color: transparent;
font-size: 30px;
}
.userBoxF .corner span {
display: block;
position: absolute;
top: -30px;
left: -20px;
}
Here is a demo of the solution I came up with but I would rather not create anymore elements.
My Solution
You can use :before wit :after together.
I removed the span:
<div class="userBoxF">
</div>
And changed the CSS blocks to this:
.userBoxF:before {
position: absolute;
top: 0;
left: 0;
width: 0;
height: 0;
border: 40px solid #F385FF;
border-right-color: transparent;
border-bottom-color: transparent;
content: "";
}
.userBoxF:after {
display: block;
position: absolute;
top: 10px;
left: 14px;
content: "F";
font-size: 30px;
}
And here's the updated fiddle
EDIT: Here's an added bonus!
You can jack the "F" from the class, if you want it to be more versatile, if you use CSS's attr inside content. Example:
<div class="userBox" data-l="F">
</div>
And:
.userBox:after {
display: block;
position: absolute;
top: 10px;
left: 14px;
content: "" attr(data-l);
font-size: 30px;
}
And another fiddle
Arguably the "F" is actual content as it's not a styling option...it actually denotes something and, perhaps should be read by a screenreader (for instance) then a span with a gradient (TL - BR) mightbe more appropriate.
JSFiddle Demo
HTML
<div class="userBoxF">
<span class="section-letter">F</span>
</div>
CSS
.userBoxF {
width: 200px;
height: 200px;
background: #eee;
border: 1px solid;
border-radius: 10px;
position: relative;
overflow: hidden;
}
.section-letter {
position: absolute;
top: 0;
left: 0;
width:2em;
height:2em;
line-height: 1em;
text-align: left;
padding:0.25em 0 0 0.25em;
font-size: 30px;
background: linear-gradient(135deg, pink 0%, pink 50%, transparent 50%, transparent 100%);
}
Simply use another :psuedo:
Demo Fiddle
.userBoxF {
width: 200px;
height: 200px;
background: #eee;
border: 1px solid;
border-radius: 10px;
position: relative;
overflow: hidden;
}
.userBoxF:before,.userBoxF:after{
position: absolute;
top: 0;
left: 0;
}
.userBoxF:before {
content:"";
border: 40px solid #F385FF;
border-right-color: transparent;
border-bottom-color: transparent;
}
.userBoxF:after {
content:attr(data-l);
top: 10px;
left: 10px;
font-size: 30px;
}
From a single pseudo, you can use a gradient as background : DEMO
.userBoxF {
width: 200px;
height: 200px;
background: #eee;
border: 1px solid;
border-radius: 10px;
position: relative;
overflow: hidden;
}
.userBoxF:after {
content:"F";
position: absolute;
top: 0;
left: 0;
text-indent:20px;
line-height:60px;
width:80px;
height:80px;
background:linear-gradient(to bottom right, #F385FF 51%, transparent 49%);
font-size: 30px;
}
background-image as gradient can be just an image like in old days :
DEMO:
I have the following CSS that creates a blue speech bubble (JS fiddle: http://jsfiddle.net/C5N2c/:
<div class="bubble">Content</div>
.bubble
{
cursor: pointer;
position: absolute;
left:30px;
width: 200px;
height: 50px;
padding: 0px;
background: blue;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
border-radius: 10px;
border: blue solid 6px;
}
.bubble:after
{
content: '';
position: absolute;
border-style: solid;
border-width: 0 10px 10px;
border-color: blue transparent;
display: block;
width: 0;
z-index: 1;
top: -10px;
left: 26px;
}
.bubble:before
{
content: '';
position: absolute;
border-style: solid;
border-width: 0 15px 15px;
border-color: blue transparent;
display: block;
width: 0;
z-index: 0;
top: -21px;
left: 21px;
}
I want to add a 1px red border around the edge of this bubble, including the small speech arrow. How can I do this? It needs to be IE8 compliant.
Take a look a this Fiddle, though I havent been able to test in IE8..
The CSS:
.bubble
{
cursor: pointer;
position: absolute;
left:30px;
width: 200px;
height: 50px;
padding: 0px;
background: blue;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
border-radius: 10px;
border: red solid 1px;
z-index:2;
}
.bubble:after
{
content: '';
position: absolute;
border-style: solid;
border-width: 0 9px 9px;
border-color: blue transparent;
display: block;
width: 0;
z-index: 1;
top: -9px;
left: 26px;
}
.bubble:before
{
content: '';
position: absolute;
border-style: solid;
border-width: 0 11px 12px;
border-color: red transparent;
display: block;
width: 0;
z-index: 0;
top: -12px;
left: 24px;
}
See working version on jsFidde
I did it sometime ago, you can just change the colours, It's not tested on IE, I am currently on OSX and it's a mess trying to view it on IE xD
html:
<div class="dialog">
<div class="triangleOutline">
<div class="triangle"></div>
</div>
<div class="dialogBox">
Hello!<br>
I'm a full CSS fancy dialog box :D
</div>
</div>
css:
body{
font-size: 100%;
font-family: "Arimo";
background: #eee;
}
.triangle,
.triangleOutline{
position:relative;
width: 0;
height: 0;
border: solid transparent;
border-width: 7px;
border-bottom-color: #aaf;
}
.triangleOutline{left: 15px;}
.triangle{
top: -6px; /* outline's width - 1 */
left: -7px; /* outline's width */
border-bottom-color: white;
}
.dialogBox{
background: white;
border: 1px solid #aaf;
padding: 0.75em;
border-radius: 3px;
min-height: 1.5em;
line-height: 1.5em;
}
Just change the colors as you like, I guess you are not using THOSE colors right? XD
Try this code:
.bubble
{
cursor: pointer;
position: absolute;
left:30px;
width: 200px;
height: 50px;
padding: 0px;
background: blue;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
border-radius: 10px;
border: blue solid 6px;
box-shadow: 0 0 0 1px red;
}
.bubble:after
{
content: '';
position: absolute;
border-style: solid;
border-width: 0 15px 15px;
border-color: blue transparent;
display: block;
width: 0;
z-index: 0;
top: -19px;
left: 21px;
}
.bubble:before
{
content: '';
position: absolute;
border-style: solid;
border-width: 0 15px 15px;
border-color: red transparent;
display: block;
width: 0;
z-index: 0;
top: -21px;
left: 21px;
}
See this jsfiddle.