I'm using bootstrap, trying to make a div have a CSS triangle before it.
http://jsfiddle.net/B2XvZ/11/
Here is my non-working code:
.d:before { width: 0px; height: 0px; border-style: solid; border-width: 10px 15px 10px 0; border-color: transparent #dd4397 transparent transparent; }
The way I'd like it to look is for there to be a pink left-pointing triangle right before the text "this", with no gap between it and the div. I've tried to do this by floating the elements also, with no success.
Steps to create a basic triangleborder-top. border-bottom. border-left. border-right.
Definition and UsageThe ::before selector inserts something before the content of each selected element(s). Use the content property to specify the content to insert. Use the ::after selector to insert something after the content.
By setting the width and height to zero on the element, the actual width of the element is going to be the width of the border. Keep in mind that the border edges on an element are 45 degree diagonals to each other. That's why this method works to create a triangle.
You need to specify the content
property.
For positioning, add position:relative
to the parent, and then absolutely position the arrow -15px
to the left.
jsFiddle example
.d { position:relative; } .d:before { content:"\A"; border-style: solid; border-width: 10px 15px 10px 0; border-color: transparent #dd4397 transparent transparent; position: absolute; left: -15px; }
You need content property and some other
.d:before { content: ''; width: 0px; height: 0px; border-style: solid; border-width: 10px 15px 10px 0; border-color: transparent #dd4397 transparent transparent; display: inline-block; vertical-align: middle; margin-right: 5px; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With