drawing navigation arrow shape using css - html

I'm trying to draw a navigation arrow using css only, I wrote this code
<span class="outer">
<span class="inner"></span>
</span>
with the style
.outer {
width: 40px;
height: 40px;
border: 2px solid #000;
border-radius: 30px;
display: block;
position: relative;
}
.inner {
width: 0px;
height: 0px;
border-style: solid;
border-width: 10px 15px 10px 0;
border-color: transparent #000 transparent transparent;
position: absolute;
right: 35%;
top: 24%;
}
but i want the inner triangle be like this <, not as play button. i shared my code on JSFiddle

You could use a pseudo element to get this sort of shape.
The only drawback being you would need to know the top and left values; they aren't relative to the size of .inner.
.outer {
width: 40px;
height: 40px;
border: 2px solid #000;
border-radius: 30px;
display: block;
position: relative;
}
.inner {
width: 0px;
height: 0px;
border-style: solid;
border-width: 10px 15px 10px 0;
border-color: transparent #000 transparent transparent;
position: absolute;
right: 35%;
top: 24%;
}
.inner:after{
content:'';
width: 0px;
height: 0px;
border-style: solid;
border-width: 10px 15px 10px 0;
border-color: transparent #FFF transparent transparent;
position: absolute;
left: 5px;
top: -10px;
}
<span class="outer">
<span class="inner"></span>
</span>
This simply places the same sized arrow on top of .inner, but nudged over a few pixels. Increase the left style to make the arrow 'thicker'.

Related

Add CSS Arrow to Top Left of Div

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/

How can I make an speech box with an right angle triangle (CSS)

I am trying to make a div look a little like a speech box with a triangle at the top left, currently I have this:
.bubble
{
position: relative;
width: 240px;
height: 120px;
padding: 12px;
background: brown;
-webkit-border-radius: 0px;
-moz-border-radius: 0px;
border-radius: 0px;
margin-left: 30px;
margin-top: 30px;
}
.bubble:after
{
content: '';
position: absolute;
border-style: solid;
border-width: 17px 23px 17px 0;
border-color: transparent brown;
display: block;
width: 0;
z-index: 1;
left: -23px;
top: 0px;
}
<div class="bubble"></div>
And I am looking to have it like:
.bubble
{
position: relative;
width: 240px;
height: 120px;
padding: 12px;
background: brown;
-webkit-border-radius: 0px;
-moz-border-radius: 0px;
border-radius: 0px;
margin-left: 30px;
margin-top: 30px;
}
.bubble:after
{
content: '';
position: absolute;
border-style: solid;
border-width: 0px 23px 17px 0;
border-color: transparent brown;
display: block;
width: 0;
z-index: 1;
left: -23px;
top: 0px;
}
<div class="bubble"></div>
Here try this one, i removed the border-top in your style, so it goes like this, border-width: 0px 23px 17px 0;. Let me know if this is what youre aiming for.
EDIT: By the way if you want to make some adjustments to that triangle you can adjust the border-right and border-bottom to make it look like what you've shown in your image.

How to connect the box-shadow of two divs?

I am trying to create a speech bubble using two divs, one is a triangle and the other is a rectangle.
This is the code:
#box {
width: 200px;
height: 80px;
background-color: #ccc;
position: relative;
left: 300px;
top: 180px;
padding: 5px;
border-radius: 10px;
-moz-box-shadow: 0 0 5px #333;
-webkit-box-shadow: 0 0 5px #333;
box-shadow: 0 0 5px #333;
}
#tri {
position: absolute;
top: -15px;
left: 40px;
width: 0;
height: 0;
border-left: 10px solid transparent;
border-right: 10px solid transparent;
border-bottom: 15px solid #ccc;
float: left;
margin: 2px 5px 0px 0px;
-moz-box-shadow: 0 0 5px #333;
-webkit-box-shadow: 0 0 5px #333;
box-shadow: 0 0 5px #333;
}
<div id="box">
<div id="tri"></div>
Some text
</div>
This problem is that something happens at the point where the triangle connects to the box. The shadow doesn't go around the triangle. Is it possible to fix this so that the shadow goes around the box and continues around the triangle?
Using that technique, you wont be able to place a shadow on the triangle shape.
We can create the triangle with an :after pseudo-element and create the boxes main shadow with a :before pseudo-element.
The Triangle
The triangle looks like a diamond and the background of the box overlaps the diamond to make it look like a triangle:
This: becomes this:
The z-index: -1 places both pseudo-elements underneath their parents background.
The main shadow
The main shadow needs to be placed on a pseudo-element so that it can be overlapped by the triangle background, whilst at the same time, the triangles bottom half is overlapped by the elements background. This image shows the layers:
Full Example
#box {
width: 200px;
height: 80px;
background: #CCC;
position: relative;
left: 300px;
top: 180px;
padding: 5px;
border-radius: 10px;
}
#box:before,
#box:after {
content: '';
position: absolute;
box-shadow: 0 0 5px #333;
z-index: -1;
}
#box:before {
height: 100%;
width: 100%;
left: 0;
top: 0;
border-radius: 10px;
}
#box:after {
background: #CCC;
height: 20px;
width: 20px;
top: -10px;
left: 50%;
margin-left: -5px;
transform: rotate(45deg);
z-index: -1;
}
<div id="box">
Some text
</div>
Use this
DEMO
.arrow_box {
position: relative;
top:150px;
background: #88b7d5;
border: 4px solid #c2e1f5;
width:200px;
height:80px;
}
.arrow_box:after, .arrow_box:before {
bottom: 100%;
left: 20%;
border: solid transparent;
content: " ";
height: 0;
width: 0;
position: absolute;
pointer-events: none;
}
.arrow_box:after {
border-color: rgba(136, 183, 213, 0);
border-bottom-color: #88b7d5;
border-width: 30px;
margin-left: -30px;
}
.arrow_box:before {
border-color: rgba(194, 225, 245, 0);
border-bottom-color: #c2e1f5;
border-width: 36px;
margin-left: -36px;
}
No, there's no way to apply a shadow to that triangle. The shadow applies to a div, and divs are square. You could use an image or svg instead.
Or you could try this. Remove the shadow from the triangle and add this code.
#tri:after {
content:'';
position:absolute;
border-left: 10px solid transparent;
border-right: 10px solid transparent;
border-bottom: 15px solid rgba(0,0,0,.25);
width: 0;
height: 0;
top: -2px;
right: -10px;
z-index: -1;
}
I know it is not the same but, it's something.
try this
<div id="box">
<div class="mask"></div>
<div id="tri"></div>
.mask{
background-color:#ccc;
width:100%;
height:100%;
position:absolute;
top:0;
left:0;
}

How can I create div with a pointed top with CSS

I've see a lot of threads remotely related that basically suggest CSS triangles in the ::after or ::before pseudos, but none have really panned out. I'm throwing this out to see if anyone has any ideas.
I'm looking to create a div with a pointed or pitched top that still maintains a uniform border and box-shadow with the rest of the div.
See link for an image of what I'm trying to create:
If you dont want to use a image you could do something like this. But working with an image is lot easier in this case.
body {
background-color: #CCC;
}
.wrapper {
}
.outer {
width: 0;
height: 0;
border-style: solid;
border-width: 0 205px 32px 205px;
border-color: transparent transparent #ffffff transparent;
position: absolute;
}
.inner {
width: 0;
height: 0;
border-style: solid;
border-width: 0 200px 32px 200px;
border-color: transparent transparent #ea2225 transparent;
margin-left: -200px;
margin-top: 5px;
position: absolute;
}
.fix {
background-color: #FFF;
height: 10px;
width: 410px;
position: absolute;
margin-top: 32px;
}
.red {
width: 396px;
height: 300px;
background-color: #ea2225;
margin-top: 37px;
position: absolute;
border-left: 7px solid #FFF;
border-right: 7px solid #FFF;
border-bottom: 6px solid #FFF;
-webkit-box-shadow: 3px 5px 5px 0px rgba(48,48,48,1);
-moz-box-shadow: 3px 5px 5px 0px rgba(48,48,48,1);
box-shadow: 3px 5px 5px 0px rgba(48,48,48,1);
}
<div class="wrapper">
<div class="fix"></div>
<div class="outer">
<div class="inner">
</div>
</div>
</div>
<div class="red"></div>
See http://jsfiddle.net/0csqog8s/
this should get you started:
Update
This is an updated fiddle which is much better presented.
.first {
display: inline-block;
width: 3em;
height: 3em
}
.second {
position: relative;
display: inline-block;
width: 3em;
height: 3em
}
.third {
position: absolute;
display: inline-block;
width: 0;
height: 0;
line-height: 0;
border: 1.5em solid transparent;
margin-top: -1em;
border-bottom: 1em solid #007BFF;
left: 0em;
top: 0em
}
.forth {
position: absolute;
display: inline-block;
width: 0;
height: 0;
line-height: 0;
border: 1.5em solid #007BFF;
border-bottom: 1.5em solid #007BFF;
left: 0em;
top: 1.5em
}
<span class="first"><span class="second"><i class="third"></i><i class="forth"></i></span></span>

<hr> line with a arrow in between pointing down

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>