I'm trying to create this as below and couldn't finish it.
I can only manage to create a rounded corners on left but not slanted right.
(source: kerrydeaf.com)
#talkbubble
{
width: 100px;
height: 35px;
background: #FFCC05;
position: relative;
-moz-border-radius:8px 0 0 8px;
-webkit-border-radius:8px 0 0 8px;
border-radius:8px 0 0 8px;
margin-right:50px;
}
Or here is
http://jsfiddle.net/alma/USezL/23/
i think this is what u are looking for http://css-tricks.com/snippets/css/css-triangle/
http://jsfiddle.net/zQKhb/
#talkbubble
{
width: 100px;
height: 36px;
background: #FFCC05;
position: relative;
-moz-border-radius:8px 0 0 8px;
-webkit-border-radius:8px 0 0 8px;
border-radius:8px 0 0 8px;
margin-right:50px;
}
#talkbubble:before
{
content:"";
display:block;
position: absolute;
right: -36px;
top:0;
width: 0;
height: 0;
border: 18px solid transparent;
border-color: transparent transparent #FFCC05 #FFCC05;
}
You were missing some crucial points in your triangle on the right. First of all, by default a :before element is display: inline, so to create the effect you were seeking you needed display: block instead.
Second, the right: 120px was moving it 120 pixels away from the right side of its original position. That is, it was being pushed to the left, out of view. Instead, you needed a negative right position (move to the right) of 100% (the width of the speech bubble). That way, it'd end up to the right of it.
Third, not sure what shape you were going for but it was almost everything but a triangle ;).
I went for this instead:
#talkbubble:before
{
content:" ";
display: block;
position: relative;
right: -100%;
width: 0;
height: 0;
border-left: 0 solid transparent;
border-right: 20px solid transparent;
border-bottom: 35px solid #FFCC05;
}
The first part is for the positioning, the second part is creating the actual triangle (see http://css-tricks.com/snippets/css/css-triangle/).
In the jsfiddle I made the triangle blue so you can see exactly where it is. Change the border-right width to make the angle bigger. http://jsfiddle.net/USezL/31/
Related
How can I design this triangular corner marked with yellow color on top side of the inside div?
Make a triangle then position that by position: absolute. more explanation in code:
.box {
width: 200px;
height: 200px;
background-color: white;
border: 12px solid #aaa;
}
.triangle-left {
width: 0; /* this five code lines for making a triangle */
height: 0;
border-top: 8px solid transparent;
border-right: 8px solid white;
border-bottom: 8px solid transparent;
position: absolute; /* this three code line for positioning of triangle */
top: 60px;
left: 10px;
}
<div class="box"></div>
<div class="triangle-left"></div>
See this for how making a triangle: https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_shapes_triangle-left
try this one!
anything you want is here,
but first try to make a container then copy the code! https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_shapes_triangle-left
Hey I have a triangle in CSS created like so:
.triangleup {
width: 0;
height: 0;
border-style: solid;
border-width: 0 7.5px 10px 7.5px;
border-color: transparent transparent #58BE23 transparent;
display: inline-block;
}
<h1>Here is a triangle<i class="triangleup"></i></h1>
I would like to change the y position of the triangle and move it up so the top of the triangle aligns with the top of the text. How would I go about doing this?
Try This:
.triangleup {
vertical-align: top;<----------Added
//More code.........
}
.triangleup {
width: 0;
height: 0;
border-style: solid;
border-width: 0 7.5px 10px 7.5px;
border-color: transparent transparent #58BE23 transparent;
display: inline-block;
vertical-align: top;
}
<h1>Here is a triangle<i class="triangleup"></i></h1>
There are 2 ways you could do this, i.e. align triangle at top so that it level-up with remaining texts,
1st - By changing the position of .triangleup to position:relative and using top as negative value,
.triangleup {
width: 0;
height: 0;
border-style: solid;
border-width: 0 7.5px 10px 7.5px;
border-color: transparent transparent #58BE23 transparent;
display: inline-block;
position:relative; /*Add this*/
top:-22px; /*Add this*/
}
<h1>Here is a triangle<i class="triangleup"></i></h1>
2nd - By changing the position of .triangleup to position:absolute and top:0, here you even need to change position of h1 to relative.
position:absolute - The element is removed from the normal document
flow; no space is created for the element in the page layout. Instead,
it is positioned relative to its closest positioned ancestor if any;
otherwise, it is placed relative to the initial containing block.
h1{
position:relative;
}
.triangleup {
width: 0;
height: 0;
border-style: solid;
border-width: 0 7.5px 10px 7.5px;
border-color: transparent transparent #58BE23 transparent;
display: inline-block;
position:absolute;
top:0;
}
<h1>Here is a triangle<i class="triangleup"></i></h1>
You could try putting some margin on the bottom of the triangle
.triangleup {
margin-bottom: 10px;
}
margin-left:50px;
margin-top:50px;
This is used to set the position of the top left corner point of the triangle.
margin-bottom:10px;
This code in css will fix the issue
.triangleup {
position:absolute;
width: 0;
height: 0;
border-style: solid;
border-width: 0 7.5px 10px 7.5px;
border-color: transparent transparent #58BE23 transparent;
display: inline-block;
top:0px;
}
h1{
background-color:blue;
position:relative;
}
<h1>Here is a triangle<i class="triangleup"></i></h1>
Make your h1 element position:relative and traingleup class position:absolute.
Now it works.
Hope it help.
Other answers here give you some possibilities that will work with the specific example you've given, but may require adjusting the numbers a bit depending on your real-life font size and font family.
A more abstract solution that will give you roughly the correct alignment no matter the font is to use the CSS property meant specifically for this purpose: vertical-align: text-top.
Simply setting that property will automatically align the bottom of your triangle to the top of your text.
If you want to align the top of the triangle, you can then do what others have suggested and add relative positioning to the vertical alignment. Since your triangle is 10 pixels tall, you can use top: 10px (in conjunction with position: relative) to push the triangle down so its top will then align with the top of the text.
Final styles would look like this:
.triangleup {
width: 0;
height: 0;
border-style: solid;
border-width: 0 7.5px 10px 7.5px;
border-color: transparent transparent #58BE23 transparent;
display: inline-block;
vertical-align: text-top;
position: relative;
top: 10px;
}
Whether that gets the triangle to sit close enough to where you want it to or not will be the deciding factor on if you go this route or one of the routes others have presented. This method is, I think, more flexible at the expense of being slightly less precise.
You can align it with applying position. So the code will be:
.triangleup {
border-color: transparent transparent #58be23;
border-style: solid;
border-width: 0 7.5px 10px;
display: inline-block;
height: 0;
position: relative;
top: -3px;
width: 0;
}
https://jsfiddle.net/rijokpaul/hjx7q4kj/2/
I have a link which is a box like the SO 'Ask Question' button but I want the right of it to point like an arrow.
This http://jsfiddle.net/U4zXS/1/ is what I have so far. I have the right side rounded but I need it to be in a point like an arrow.
<a class="arrow_link" href="{$base_url}signup">GET STARTED WITH OUR <span class="purple">FREE TRIAL</span></a>
.arrow_link{
float: left;
background-color: $color-orange;
border-radius: 0 25px 25px 0;
padding: 4px 15px 6px 8px;
margin-top: -5px;
font-weight: bold;
color: $color-white;
}
a{
text-decoration: none;
}
You can try with the borders triangle method:
.arrow_link::after {
content: "";
display: block;
position: absolute;
top: 0;
left: 100%;
border-style: solid;
border-color: transparent #F78E1E;
border-width: 15px 0 15px 15px;
width: 0;
height: 0;
}
Notice that you'll also have to add position: relative to the .arrow_link itself.
Here's the updated fiddle: FIDDLE
You can use the CSS :after psuedo-element as followed:
.arrow_link { position: relative; }
.arrow_link:after {
content: '';
display: block;
border: 10px solid transparent;
border-left-color: red;
top: 0;
right: -20px;
}
This will append a psuedo-element to your a, which will show the arrow using the border trick as explained very well on CSS Tricks.
You can use a pseudo element to make the triangle at the end of the element. Here is some more info about pseudo elements that should help you get started with them.
Here is the changed css:
.arrow_link{
float: left;
background-color: $color-orange;
padding: 4px 15px 6px 8px;
margin-top: -5px;
font-weight: bold;
color: $color-white;
position: relative;
}
.arrow_link:after {
content: "";
display: block;
position: absolute;
border-left: 15px solid #f78e1e;
border-top: 15px solid transparent;
border-bottom: 15px solid transparent;
left: 100%;
top: 0;
}
Finally, a fiddle: Demo
The only problem you will have is due to your element not having a fixed height, won't be a problem if your element doesn't change. CSS triangles are not the most flexible thing to use but they do the trick.
Have a look at this http://jsfiddle.net/WW32n/1/ and some references here http://nicolasgallagher.com/pure-css-speech-bubbles/demo/
<p class="triangle-isosceles right">The entire appearance is created only with CSS.</p>
and the css
.triangle-isosceles {
position:relative;
padding:15px;
margin:1em 0 3em;
color:#000;
background:#f3961c; /* default background for browsers without gradient support */
/* css3 */
background:-webkit-gradient(linear, 0 0, 0 100%, from(#f9d835), to(#f3961c));
background:-moz-linear-gradient(#f9d835, #f3961c);
background:-o-linear-gradient(#f9d835, #f3961c);
background:linear-gradient(#f9d835, #f3961c);
-webkit-border-radius:10px;
-moz-border-radius:10px;
border-radius:10px;
}
/* creates triangle */
.triangle-isosceles:after {
content:"";
position:absolute;
bottom:-15px; /* value = - border-top-width - border-bottom-width */
left:50px; /* controls horizontal position */
border-width:15px 15px 0; /* vary these values to change the angle of the vertex */
border-style:solid;
border-color:#f3961c transparent;
/* reduce the damage in FF3.0 */
display:block;
width:0;
}
This question already has answers here:
How do CSS triangles work?
(23 answers)
Creating a transparent arrow above image in CSS3
(2 answers)
Closed 9 years ago.
Respected stackoverflowers,
How do i create a triangle element with the background pattern?
For example i need the div like this :
But my state is like this :
All examples with triangle elements use borders which cant have an img in that ....
This is my subsection class which needs the coolarrow:
<div class="subsection"><span>Ryan Gosling, Mr Landlord</span></div>
.subsection {
.box-shadow (0, -1px, 1px, 0, rgba(0, 0, 0, 0.3));
background: url('/assets/pattern-lorem.png'); // The inner part of the slider have the pattern
display: block;
clear: both;
float: left;
width: 100%;
padding-top: 15px;
padding-bottom: 15px;
display: none;
}
.subsection {
position:relative;
}
.subsection:before {
content:'';
position:absolute;
top:0;
left:0;
height:20px;
width:0;
border-left:20px solid white;
border-bottom:16px solid transparent;
}
.subsection:after {
content:'';
position:absolute;
top:36px;
left:0;
bottom:0;
width:0;
border-left:20px solid white;
border-top:16px solid transparent;
}
And im getting :
Which is fine ...how can i bring the arrow on the top in the required form ? ... and overlaying the cases div ? ...
Thanks.
If you don't care for cross browser compatibility, you can use a pseudo-element that you rotate by 45 degrees and attach the styles to it. The only thing you need additionally would be the background, rotated (back) by 45deg to attach to the pseudo element:
div.coolarrow:before {
content: '';
position: absolute;
z-index: -1;
top: -24.7px;
left: 10px;
background-color: #bada55;
width: 50px;
height: 50px;
background: url(url/to/your/45deg/rotated/background.gif);
box-shadow: inset 0 0 10px #000000;
transform: rotate(45deg);
}
Here's a short fiddle to illustrate (without background):
Fiddle
To work this out for other cases but 90degree arrows, you need to skew the rect additionaly. And I don't really know what then happens with the background image...
Put the image as a background for a div, and just put negative values for the margin to make it overlay on the bar. Example (although estimated, in no way do I claim this to work) would be margin-left: -20px; margin-top: -20px; and have it after the line.
Alternatively go with #Py's answer, and you can use this CSS for the arrow, and do the same negative margins to make it line up.
#triangle-up { width: 0; height: 0; border-left: 50px solid transparent; border-right: 50px solid transparent; border-bottom: 100px solid red; margin-left: -20px; margin-top: -20px; }
go on http://apps.eky.hk/css-triangle-generator/ and generate it :D
OR
#triangle {
width: 0;
height: 0;
border-bottom: 120px solid green;
border-left: 60px solid transparent;
border-right: 60px solid transparent;
}
I want to create an upward and downward facing arrow with css like the following: http://apps.eky.hk/css-triangle-generator/
However, instead of a solid color, I want to set it up so the inside is white and there is just a border around the triangle. (So the triangle would be multi-colored, one color on the inside and a different colored border).
Is this possible, and if so, how can it be done?
To create triangles with only CSS we use a zero width/height element with borders:
.arrow-up {
width : 0;
height : 0;
border-left : 50px solid transparent;
border-right : 50px solid transparent;
border-bottom : 50px solid black;
}
Since we are using borders to create the arrow, we can't just give it a border, but we can overlay one arrow on top of a slightly larger arrow to make the appearance of a border:
HTML --
<div class="top"></div>
<div class="bottom"></div>
CSS --
.top {
position : absolute;
top : 6px;
left : 10px;
width : 0;
height : 0;
z-index : 100;
border-left : 50px solid transparent;
border-right : 50px solid transparent;
border-bottom : 50px solid black;
}
.bottom {
position : absolute;
width : 0;
height : 0;
z-index : 99;
border-left : 60px solid transparent;
border-right : 60px solid transparent;
border-bottom : 60px solid red;
}
Here is a demo: http://jsfiddle.net/jasper/qnmpb/1/
Update
You can then put both of the triangle DIV elements inside a container and move that container however you want:
HTML --
<div id="container">
<div class="top"></div>
<div class="bottom"></div>
</div>
CSS --
#container {
position : relative;
top : 25px;
left : 25px;
}
Here is a demo: http://jsfiddle.net/jasper/qnmpb/3/
EDIT (2014):
I just came back to this answer and noticed that separate HTML elements are not necessary to create your double-triangle. You can use pseudo-elements, :before and :after. I.e. replace the .top selector with something like .my-element-that-needs-a-triangle:before and the .bottom selector with something like .my-element-that-needs-a-triangle:after.
I think you could get a good idea of what to do by checking out this tutorial on pure css thought bubbles. It's doing what you're looking for.
http://www.sitepoint.com/pure-css3-speech-bubbles/
Depending on how you're using it, you can make a triangle, with a border and even box shadow, without the triangle border hack, using CSS transform: rotate(). See my answer here: https://stackoverflow.com/a/8867645/918414
If you want to create a triangle with borders (or box shadow look-alike) in pure CSS, you should use pseudo-elements :before and :after.
In my example, I added display:inline-block; to the element .arrow-dropdown to be able to create some kind of dropdown menu with a drop shadow. It is followed by .arrow-only which is a a basic triangle with a red border.
body {
margin: 10px;
background: #1670c4;
}
.text {
display: inline-block;
font-size: 15px;
color: #fff;
text-shadow: 1px 1px 2px rgba(0,0,0,0.4);
cursor: default;
}
.arrow-dropdown {
display: inline-block;
position: relative;
vertical-align: middle;
margin: 1px 0 0 8px;
width: 8px;
height: 7px;
}
.arrow-dropdown:after {
content: '';
position: absolute;
border-style: solid;
border-width: 7px 4px 0;
border-color: #fff transparent transparent transparent;
display: block;
width: 0;
z-index: 1;
}
.arrow-dropdown:before {
content: '';
position: absolute;
border-style: solid;
border-width: 8px 5px 0;
border-color: rgba(0,0,0,0.3) transparent transparent transparent;
display: block;
width: 0;
z-index: 0;
}
.arrow-only {
position: relative;
vertical-align: middle;
margin: 10px 0 0 8px;
width: 8px;
height: 7px;
}
.arrow-only:after {
content: '';
position: absolute;
border-style: solid;
border-width: 12px 9px 0;
border-color: #fff transparent transparent transparent;
display: block;
width: 0;
z-index: 1;
}
.arrow-only:before {
content: '';
position: absolute;
border-style: solid;
border-width: 15px 11px 0;
border-color: #f00 transparent transparent transparent;
display: block;
width: 0;
z-index: 0;
margin:-1px 0 0 -2px;
}
<div class="text">
Dropdown text
</div><div class="arrow-dropdown"></div>
<div class="arrow-only"></div>