How to make a right pointed arrow using css - css

I'm creating some custom shapes using CSS I want to draw an arrow whose pointer is on the right side and is aligned left to the div I actually made an arrow which pointer was to the left but I'm having difficulty in making an arrow whose pointer is on right side.
Here's a picture of how I want it
arrow
Here's my html code
<div class="arrow">
<img style="width:70%" src="https://i.imgsafe.org/a842cd10d7.png" class="img-responsive">
</div>
css
.arrow {
position: relative;
}
.arrow::after {
position: absolute;
content: '';
width: 0;
height: 0;
left: 0;
border-style: solid;
border-width: 18px 30px 18px 0;
border-color: transparent #fff transparent transparent;
bottom: 45px;
}
FIDDLE

You just needed to swap the left/right values of your border rules to make the arrow face the opposite direction.
Change this:
border-width: 18px 30px 18px 0;
border-color: transparent #fff transparent transparent;
To this:
border-width: 18px 0 18px 30px;
border-color: transparent transparent transparent #fff;
And then to match your example image, I changed the 30px side to also be 18px, forming an equilateral triangle.
.arrow {
position: relative;
}
.arrow::after {
position: absolute;
content: '';
width: 0;
height: 0;
left: 0;
border-style: solid;
border-width: 18px 0 18px 18px;
border-color: transparent transparent transparent #fff;
bottom: 45px;
}
<div class="arrow">
<img style="width:70%" src="https://i.imgsafe.org/a842cd10d7.png" class="img-responsive">
</div>

Take a look here I did it (and made arrow in red so it will be easier to see):
.arrow {
position: relative;
padding: 20px;
}
.arrow::after {
position: absolute;
z-index: 200;
content: '';
width: 0;
height: 0;
left: 20px;
border-style: solid;
border-width: 22px 0 22px 17px;
border-color: transparent transparent transparent red;
bottom: 62px;
}

Related

Get Bootstrap 4 Vertical pills :after to line up with pills

So I have some vertical pills which have an :after class to create a triangle at the end of the pill as so :
.nav-link.active :after {
position: absolute;
right: -20px;
content: '';
width: 0;
height: 0;
border-style: solid;
border-width: 21px 0 21px 20px;
border-color: transparent transparent transparent #bbcfd8;
}
The problem I have come across is that the triangle will not align with the pills themselves. I have created a codepen with the example I am using :
https://codepen.io/anon/pen/XBjOKR
Any help would be appreciated.
Add top:0 in this style and position: relative; on nav-link
.nav-link.active :after {
position: absolute;
top: 0;
right: -20px;
content: '';
width: 0;
height: 0;
border-style: solid;
border-width: 21px 0 21px 20px;
border-color: transparent transparent transparent #bbcfd8;
}
.nav-pills .nav-link {
position: relative;
}
See updated codepen

button shape with transparency and only dotted border

Is it able to create a button with transparent background and a dotted border, with a custom shape?
I'm able now to do this with a background color, but when I try to to fill the inner without any color, nothing works as expected.
body{
background: #999
}
button {
height: 50px;
width: 250px;
border: dotted 1px #FFF;
border-bottom: none;
background: none;
position: relative;
}
button:after,
button:before {
content: '';
display: block;
position: absolute;
top: 100%;
width: 0;
height: 0;
border-style: solid;
}
button:after {
border-color: #fff transparent transparent transparent;
border-width: 1px 125px 0 0;
right: 1px
}
button:before {
border-color: transparent transparent #fff transparent;
border-width: 0 125px 1px 0;
left: 0
}
<body>
<button></button>
</body>
I am not so sure about a button, but you can certainly create shapes out of divs.
What you are looking for is a play with borders to create shapes.
#triangle{
width: 0;
height: 0;
border-left: 30px solid transparent;
border-right: 30px solid transparent;
border-bottom: 40px solid green;
}
<div id="triangle"></div>
As you can see, I created a triangle with just the borders, the trick is to understand the borders of a div. They are not straight, their ends are wedge shaped.
I think this is a good starting point for you.

CSS Triangle inside a triangle?

I am trying to create a border like effect for the triangle. I have tried giving it a border, box shadow, neither works. Then if you do put another triangle div inside of it the outer triangle just becomes larger.
#triangle {
border-style: solid;
border-width: 25px 50px 25px 0;
border-color: transparent #000 transparent transparent;
}
Try using a pseudo-element like :after.
Here you go!
#triangle {
border-style: solid;
border-width: 25px 50px 25px 0;
border-color: transparent #000 transparent transparent;
width: 0;
position: relative;
}
#triangle:after {
content: ' ';
position: absolute;
border-style: solid;
border-width: 13px 25px 13px 0;
border-color: transparent red transparent transparent;
width: 0;
top: -13px;
left: 17px;
}
<div id="triangle">
</div>

How to create border bottom with 2 different color?

I need to create border bottom with two different color like below picture
How do I create the CSS?
You can use css pseudo classes i.e :after or :before.
h3 {
margin: 0;
padding-bottom: 7px;
position: relative;
border-bottom: 2px solid #ccc;
}
h3:before {
position: absolute;
background: brown;
height: 2px;
content: '';
width: 50px;
bottom: -2px;
left: 0;
}
<h3>Last Recent Post</h3>
And you can use css gradient as well:
h3 {
margin: 0;
padding-bottom: 7px;
position: relative;
}
h3:before {
position: absolute;
background: linear-gradient(to right, brown 50px, #ccc 50px);
height: 2px;
content: '';
bottom: 0;
right: 0;
left: 0;
}
<h3>Last Recent Post</h3>
The problem with the accepted solution is the bottom border has a fixed width of 50px; , hence it does not respect the length of the text. The more efficient solution would be the following:
<h2>
<span>Text length doesn't matter</span>
</h2>
CSS
h2 {
border-bottom-width: 1px;
border-bottom-style: solid;
border-bottom-color: lightgray;
}
span {
border-bottom-width: 3px;
border-bottom-style: solid;
border-bottom-color: brown;
display: inline-block;
margin: 0 0 -2px 0;
padding: 30px 3px;
}
The result will look like the following: JsFiddle link: http://jsfiddle.net/uyzndpvs/
use box-shadow with zero blur
syntax :
box-shadow : x-offset y-offset blur radius color
example : box-shadow 0 0 0 1em red , 0 0 0 2em orange.
this will emulate a border of 1em red border and then a 1em orange border.
Note that orange color has a radius of 2em ( because half of it will be covered by red color)

How can I make a CSS only speech bubble with a border?

I want to make a CSS only speech bubble. So far, I have this...
Example
CSS
div {
position: relative;
background: #fff;
padding: 10px;
font-size: 12px;
text-align: center;
-webkit-border-radius: 20px;
-moz-border-radius: 20px;
border-radius: 20px;
}
div:after {
content: "";
display: block;
width: 0;
height: 0;
position: absolute;
left: 50%;
bottom: -60px;
margin-left: -15px;
border-width: 30px 20px 30px 20px;
border-style: solid;
border-color: #fff transparent transparent transparent;
}
jsFiddle.
...which is almost exactly what I want. However, I want a light border around the whole thing.
Obviously, on the main portion, that is simple as adding border: 1px solid #333 to the div.
However, as the tail of the bubble is a border hack, I can't user a border with it.
I tried setting a box shadow of 0 0 1px #333 but browsers apply the border to the rectangular shape of the element (which I guess is what they should do).
jsFiddle.
My next thoughts were finding a Unicode character that looks like a bubble tail and absolutely positioning it there, with text-shadow for the border and using z-index of the main bubble to hide the top shadow of the text.
What Unicode character would be suitable for this? Should I do something different? Do I need to resort to an image?
I only have to support Mobile Safari. :)
<div>Hello Stack Overflow!<span></span></div>
div span:after {
content: "";
display: block;
width: 0;
height: 0;
position: absolute;
left: 50%;
bottom: -51px;
margin-left: -15px;
border-width: 20px 20px 30px 20px;
border-style: solid;
border-color: #000 transparent transparent transparent;
}
http://jsfiddle.net/QYH5a/
For the Unicode character approach you suggested, the most appropriate would be ▼ U+25BC BLACK DOWN-POINTING TRIANGLE. I don't know whether iOS has glyphs for it.
Here is a similar solution:
http://jsfiddle.net/JyPBD/2/
<div>Hello Stack Overflow!<span></span></div>
body {
background: #ccc;
}
div {
position: relative;
background: #fff;
padding: 10px;
font-size: 12px;
text-align: center;
-webkit-border-radius: 20px;
-moz-border-radius: 20px;
border-radius: 20px;
border: 1px solid #333;
}
div:after {
content: "";
display: block;
width: 0;
height: 0;
position: absolute;
left: 50%;
bottom: -60px;
margin-left: -16px;
border-width: 30px 20px 30px 20px;
border-style: solid;
border-color: green transparent transparent transparent;
}
div span
{
border-color: #FF0000 transparent transparent;
border-style: solid;
border-width: 25px 15px;
bottom: -51px;
margin-left: -65px;
position: absolute;
z-index: 10;
}
You could use the filter property with box-shadow() to do it...
-webkit-filter: drop-shadow(1px 1px 1px #111) drop-shadow(-1px -1px 1px #111);
jsFiddle.

Resources