Please take a look at http://jsfiddle.net/ghAgQ/
I need the same gradient for arrow, as it is for the rectangle. Any ideas how thats done? Thanks
.rectangle {
background-color: #EEE;
height: 80px;
width: 240px;
border: 1px solid #CCC;
background: white;
cursor: pointer;
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,white), color-stop(37%,#F1F1F1), color-stop(57%,#E1E1E1), color-stop(100%,#F6F6F6));
float: left;
}
.arrow {
border-top: 41px solid transparent;
border-bottom: 41px solid transparent;
border-left: 15px solid #C4C4C4;
float: left;
cursor: pointer;
}
You can do this in a much simpler way, using just an element and a rotated pseudo element (any browser that supports CSS gradients also supports CSS transforms and pseudo-elements) with an angled linear gradient. Also, don't use the old WebKit syntax (see this bit about the history of the syntax).
Working in current versions of Chrome, Opera, Firefox, IE on Windows.
DEMO
HTML is just <div class='rectangle'></div>
Relevant CSS:
.rectangle {
float: left;
position: relative;
height: 80px;
width: 240px;
border: solid 1px #ccc;
border-right: none;
background: #eee linear-gradient(white, #f1f1f1 37%, #e1e1e1 57%, #f6f6f6);
cursor: pointer;
}
.rectangle:after {
position: absolute;
top: 16px; right: -25px;
width: 48px;
height: 47px;
border-left: solid 1px #ccc;
border-top: solid 1px #ccc;
transform: rotate(134deg) skewX(-10deg) skewY(-10deg);
background: #eee linear-gradient(45deg, white, #f1f1f1 37%, #e1e1e1 57%, #f6f6f6);
content: '';
}
Edit January 2013
4 months later, I have a slightly improved solution. This time, the values are computed. The first time I got them using trial and error.
new demo
.shape {
float: left;
position: relative;
border: 1px solid #ccc;
border-right: none;
width: 240px; height: 80px;
background: linear-gradient(white, #f1f1f1 37%, #e1e1e1 57%, #f6f6f6);
cursor: pointer;
}
.shape:after {
position: absolute;
top: 50%; right: 0;
margin: -24px -20px;
border-top: solid 1px #ccc;
border-right: solid 1px #ccc;
width: 40px /* 80px/2 */; height: 47px/* 80px/sqrt(3) */;
transform: rotate(30deg) skewY(30deg); /* create a rhombus */
/* 49.1deg = atan(1.15) = atan(47px/40px) */
background:
linear-gradient(-49.1deg, #f6f6f6, #e1e1e1 43%, #f1f1f1 63%, white);
content: ''
}
<div class='shape'></div>
While the demo above looks really nice in Chrome, any browser support information is missing and it does not work in many browsers. I have spend some time to develop a more cross-browser approach.
HERE'S A SOLUTION FOR ALL MODERN BROWSERS WITH A NICE BUILD FUNCTION USING SASS
.triangle {
/* sample positioning */
width: 160px;
height: 160px;
position: absolute;
top: 30%;
left: 45%;
/*
* deprecated syntax has better browser support
* IE8+
* http://css-tricks.com/almanac/properties/c/clip/
*/
clip: rect(auto, 180px, auto, 100px);
-webkit-transform: rotate(-90deg);
-moz-transform: rotate(-90deg);
-o-transform: rotate(-90deg);
transform: rotate(-90deg);
}
.triangle::after {
content: "";
position: absolute;
top: 10px;
bottom: 10px;
left: 10px;
right: 10px;
/**
* To also support IE 9 we you a background images
* as fallback, created via compass:
* #include background-image(linear-gradient(300deg, green, blue));
*/
background-image: url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4gPHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGRlZnM+PGxpbmVhckdyYWRpZW50IGlkPSJncmFkIiBncmFkaWVudFVuaXRzPSJvYmplY3RCb3VuZGluZ0JveCIgeDE9IjEuMDkxNTA2IiB5MT0iMC44NDE1MDYiIHgyPSItMC4wOTE1MDYiIHkyPSIwLjE1ODQ5NCI+PHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iIzAwODAwMCIvPjxzdG9wIG9mZnNldD0iMTAwJSIgc3RvcC1jb2xvcj0iIzAwMDBmZiIvPjwvbGluZWFyR3JhZGllbnQ+PC9kZWZzPjxyZWN0IHg9IjAiIHk9IjAiIHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiIGZpbGw9InVybCgjZ3JhZCkiIC8+PC9zdmc+IA==');
background-size: 100%;
background-image: -moz-linear-gradient(150deg, green, blue);
background-image: -webkit-linear-gradient(150deg, green, blue);
background-image: linear-gradient(300deg, green, blue);
-webkit-transform: rotate(-45deg);
-moz-transform: rotate(-45deg);
-o-transform: rotate(-45deg);
transform: rotate(-45deg);
}
Currently supports IE 10+, Firefox, Opera, Chroma, Safari
Related
Here is a shadow:
So I need this to be a shadow which appears on button hover. I know its css but I didn't manage to make any blur:
background-image: linear-gradient(-90deg, #CF77F3 0%, #009BFF 47%, #2AC9DB 100%);
border-radius: 100px;
filter: blur(5px);
So, two basic questions:
Is it possible to make this blurred thing with CSS?
If yes, is it possible to make it a button shadow? Or how else can I solve this? One thought was to just make a png with absolute positioning, which is hacky a bit
update
So the final result I want achieve looks something like this:
The shadow repeats button gradient which is
linear-gradient(-90deg, #CF77F3 0%, #009BFF 47%, #2AC9DB 100%);
New answer
I have made an online generator that helps you get a gradient shadow easily: https://css-generators.com/gradient-shadows/
All you have to do is to adjust a few values and get the code:
button {
margin: 50px;
border-radius: 999px;
padding: 10px 30px;
font-size: 25px;
color: #fff;
text-align: center;
line-height: 50px;
border: none;
background: linear-gradient(-90deg, #CF77F3 0%, #009BFF 47%, #2AC9DB 100%);
position: relative;
transform-style: preserve-3d;
}
button::before {
content: "";
position: absolute;
inset: -10px;
background: inherit;
filter: blur(20px);
transform: translate3d(15px,15px,-1px);
border-radius: inherit;
pointer-events: none;
}
<button >
this a button
</button>
More detail: https://css-tricks.com/different-ways-to-get-css-gradient-shadows/
Old answer
What about multiple box-shadow:
.box {
margin:50px;
width:100px;
height:50px;
border-radius:20px;
color:#fff;
text-align:center;
line-height:50px;
box-shadow:
20px 5px 40px #CF77F3,
0px 5px 40px #009BFF,
-20px 5px 40px #2AC9DB;
background-image: linear-gradient(-90deg, #CF77F3 0%, #009BFF 47%, #2AC9DB 100%);
}
<div class="box">
this a button
</div>
You can get this effect in modern browsers using a pseudo element with the same background, and a filter blur applied on it.
To get compatibility with IE, you can set also a pseudo, and to get the blurred borders use an inset shadow. At least in Chrome, there is a small left over of the border that still can be seen.
.test {
margin: 20px;
background-image: linear-gradient(-90deg, #CF77F3 0%, #009BFF 47%, #2AC9DB 100%);;
border-radius: 50px;
display: inline-block;
height: 100px;
width: 200px;
position: relative;
border: solid 4px black;
}
#test1:after {
content: "";
position: absolute;
background-image: inherit;
border-radius: inherit;
width: inherit;
height: inherit;
transform: translate(0px, 20px) scale(1.1);
z-index: -1;
filter: blur(14px);
}
#test2:after {
content: "";
position: absolute;
border-radius: 90px;
width: 250px;
height: 150px;
z-index: -1;
top: 1px;
left: -25px;
background-image: linear-gradient(-90deg, #CF77F3 0%, #009BFF 47%, #2AC9DB 100%);
box-shadow: inset 0px 0px 25px 18px white;
}
<div class="test" id="test1">
</div>
<div class="test" id="test2">
</div>
I need to do a triangular onfocus on button, like on this image
I looked at different examples like this, but the focus zone is rectangular.
Is it possible make triangular onfocus?
You could use clip-path to give a triangular shape to the button and apply the same shape to button::before pseudoelement slightly enlarged to mimic an outline, e.g.
Codepen Demo
Note: working only on browser supporting clip-path
Markup
<button><span>button</span></button>
CSS
button {
position: relative;
border: 0;
padding: 0;
cursor: pointer;
-webkit-clip-path: polygon(0 0, 0 100%, 100% 100%, 100% 50% 100% 0);
clip-path: polygon(0 0, 0 100%, 100% 100%, 100% 50% 100% 0);
}
button span {
position: relative;
z-index: 1;
display: block;
background: linear-gradient(#f4f4f4, #d4d4d4);
padding: 10px 20px;
}
button:focus {
outline: none;
-webkit-clip-path: polygon(0 0, 0 100%, 90% 100%, 100% 50%, 90% 0);
clip-path: polygon(0 0, 0 100%, 90% 100%, 100% 50%, 90% 0);
}
button::before,
button span {
-webkit-clip-path: inherit;
clip-path: inherit;
}
button:focus::before {
content: "";
position: absolute;
height: calc(100% + 4px);
width: calc(100% + 4px);
left: -2px;
top: -2px;
background: rgba(81,153,219, .7);
}
Maybe like this?
Adding an element after the button to provide the triangular shape...
Now it is 45° rotation, you could play by skewing to get another angle.
CodePen Sample
button:hover { border-color: blue; }
button:hover:after { border-color: blue;}
button {
font-size: 14px;
background: none;
border: 1px solid red;
border-right: 0;
position: relative;
height: 44px;
z-index: 1;
background-color: #FFF;
}
button::after {
content: "";
display: block;
position: absolute;
width: 30px; height: 30px;
background: #FFF;
right: -15px;
top: 5px;
transform: rotate(-45deg);
z-index:-1;
border-right: 1px solid Red;
border-bottom: 1px solid Red;
}
You could use the map tag : http://www.w3schools.com/tags/tag_map.asp
But in that case your button must be a picture.
little late,
but you can do for almost every browser with transform and a pseudo.
Eventually add background gradient and shadow : http://codepen.io/gc-nomade/pen/yOjOby
* {
box-sizing: border-box;
}
a {
display: inline-block;
padding: 0.5em 1em;
margin: 0 1.5em 0 0;
text-decoration: none;
color: #177EE5;
border: solid 3px;
border-radius: 5px;
border-right: none;
position: relative;
background: linear-gradient(to right, lightgray, white, lightgray);
box-shadow: 0 0 5px black;
}
a:after {
content: '';
position: absolute;
top: 3px;
bottom: 3px;
right: -.8em;
width: 1.75em;
border-radius: inherit;
border-top: solid;
border-right: solid;
border-color: inherit;
transform: rotate(45deg);
background: linear-gradient(45deg, transparent 45%, lightgray 60%);
box-shadow: 0px -5px 5px -5px black, 5px 0px 5px -5px black
}
arrow
longer arrow
#
you can use this site and make triangular, polygon: The Shapes of CSS - CSS-Tricks
https://css-tricks.com/examples/ShapesOfCSS
make a css class. add that class on focus.
http://www.w3schools.com/jquery/html_addclass.asp
I have created product box that shows product image, when hovered on flips around to show details of a product and this works well. Problem is when this product has ribbon on it and flips, text in the ribbon becomes flipped as well (it's position is correct), I need to somehow extra transform this text so it shows correctly TOP even when flipped. Is it possible?
.ribbon-wrapper-green {
width: 85px;
height: 88px;
overflow: hidden;
position: absolute;
top: -3px;
right: -3px;
z-index: 5;
}
.ribbon-green {
font: bold 15px Sans-Serif;
color: #333;
text-align: center;
text-shadow: rgba(255,255,255,0.5) 0px 1px 0px;
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-ms-transform: rotate(45deg);
-o-transform: rotate(45deg);
position: relative;
padding: 7px 0;
left: -5px;
top: 15px;
width: 120px;
background-color: #BFDC7A;
background-image: -webkit-gradient(linear, left top, left bottom, from(#BFDC7A), to(#8EBF45));
background-image: -webkit-linear-gradient(top, #BFDC7A, #8EBF45);
background-image: -moz-linear-gradient(top, #BFDC7A, #8EBF45);
background-image: -ms-linear-gradient(top, #BFDC7A, #8EBF45);
background-image: -o-linear-gradient(top, #BFDC7A, #8EBF45);
color: #6a6340;
-webkit-box-shadow: 0px 0px 3px rgba(0,0,0,0.3);
-moz-box-shadow: 0px 0px 3px rgba(0,0,0,0.3);
box-shadow: 0px 0px 3px rgba(0,0,0,0.3);
}
.ribbon-green:before, .ribbon-green:after {
content: "";
border-top: 3px solid #6e8900;
border-left: 3px solid transparent;
border-right: 3px solid transparent;
position: absolute;
bottom: -3px;
}
.ribbon-green:before {
left: 0;
}
.ribbon-green:after {
right: 0;
}
.product-box {
width: 292px;
height: 340px;
}
.thumb-wrapper {
height: 100%;
background-color: purple;
}
.product-box img {
width: 100%;
position: absolute;
display: block;
backface-visibility: hidden;
}
.product-box .thumb-detail {
width: 100%;
height: 100%;
position: absolute;
background: blue;
backface-visibility: hidden;
}
.product-box.flip {
perspective: 800px;
}
.product-box.flip .thumb-wrapper {
transition: transform 1s;
transform-style: preserve-3d;
}
.product-box.flip .thumb-detail, .product-box.flip:hover .thumb-wrapper {
transform: rotateY(-180deg);
}
<div class="product-box flip">
<div class="thumb-wrapper">
<div class="ribbon-wrapper-green"><div class="ribbon-green">TOP</div></div>
<img src="#" alt="" title="" height="262" width="262">
<div class="thumb-detail">
</div>
</div>
</div>
Just duplicate the ribbon-wrapper-green and rotate it in the back
.card {
width: 180px;
height: 180px;
position: relative;
-webkit-perspective: 700;
margin: 0px auto;
}
.card:hover .front{
-webkit-transform: rotateY(-180deg);
}
.card:hover .back {
-webkit-transform: rotateY(0deg);
}
.card:hover .face {
-webkit-transition: all 0.3s ease-out;
}
.face {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
-webkit-backface-visibility: hidden;
-webkit-transition: all 0.8s ease-out;
}
.front {
-webkit-transform: rotateY(0deg);
}
.back {
background: #9dcc78;
-webkit-transform: rotateY(180deg);
}
.ribbon-wrapper-green {
width: 85px;
height: 88px;
overflow: hidden;
position: absolute;
top: -3px;
right: -3px;
z-index: 5;
}
.ribbon-green {
font: bold 15px Sans-Serif;
color: #333;
text-align: center;
text-shadow: rgba(255,255,255,0.5) 0px 1px 0px;
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-ms-transform: rotate(45deg);
-o-transform: rotate(45deg);
position: relative;
padding: 7px 0;
left: -5px;
top: 15px;
width: 120px;
background-color: #BFDC7A;
background-image: -webkit-gradient(linear, left top, left bottom, from(#BFDC7A), to(#8EBF45));
background-image: -webkit-linear-gradient(top, #BFDC7A, #8EBF45);
background-image: -moz-linear-gradient(top, #BFDC7A, #8EBF45);
background-image: -ms-linear-gradient(top, #BFDC7A, #8EBF45);
background-image: -o-linear-gradient(top, #BFDC7A, #8EBF45);
color: #6a6340;
-webkit-box-shadow: 0px 0px 3px rgba(0,0,0,0.3);
-moz-box-shadow: 0px 0px 3px rgba(0,0,0,0.3);
box-shadow: 0px 0px 3px rgba(0,0,0,0.3);
}
.ribbon-green:before, .ribbon-green:after {
content: "";
border-top: 3px solid #6e8900;
border-left: 3px solid transparent;
border-right: 3px solid transparent;
position: absolute;
bottom: -3px;
}
.ribbon-green:before {
left: 0;
}
.ribbon-green:after {
right: 0;
}
.back .ribbon-wrapper-green {
top: -4px;
left: -1px;
-webkit-transform: rotateZ(-90deg);
-moz-transform: rotateZ(-90deg);
transform: rotateZ(-90deg);
}
<div class='card'>
<div class='front face'>
<div class="ribbon-wrapper-green"><div class="ribbon-green">TOP</div></div>
<img src='http://placehold.it/180x180'/>
</div>
<div class="back face">
<div class="ribbon-wrapper-green"><div class="ribbon-green">TOP</div></div>
<img src='http://placehold.it/180x180'/>
</div>
</div>
Note: I had initially misunderstood the question and posted a wrong answer. Did not want to delete it and hence have modified the original answer to still solve the problem albeit making it more complex in the process. The best approach is provided in Tambo's answer. You can use this method if you for some reason wish to achieve the effect without duplicating elements.
You can do it by adding the rotateY(-180deg) on the div with class="ribbon-wrapper-green" and positioning it on the other side. The original positioning is right: -3px and on hover, we change it to left: -3px or right: 210px; (box width 292px + offset 3px - width of ribbon container 85px).
After this, the whole ribbon is translated by the required pixels (the complex part) to get positioned on the left side of the screen. Now, even though the position is correct, the ribbon has to be rotated in the reverse direction to make it look properly like a ribbon and so a rotate(-90deg) is added (-90 degrees the element is originally rotated by 45 degree which has to be nullified to come back to a normal position and then we have to rotate another 45 degree in the reverse direction).
Note: The animation/transition effect is not great but I think you can work that out.
.ribbon-wrapper-green {
width: 85px;
height: 88px;
overflow: hidden;
position: absolute;
top: -3px;
right: -3px;
z-index: 5;
}
.ribbon-green {
font: bold 15px Sans-Serif;
color: #333;
text-align: center;
text-shadow: rgba(255, 255, 255, 0.5) 0px 1px 0px;
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-ms-transform: rotate(45deg);
-o-transform: rotate(45deg);
position: relative;
padding: 7px 0;
left: -5px;
top: 15px;
width: 120px;
background-color: #BFDC7A;
background-image: -webkit-gradient(linear, left top, left bottom, from(#BFDC7A), to(#8EBF45));
background-image: -webkit-linear-gradient(top, #BFDC7A, #8EBF45);
background-image: -moz-linear-gradient(top, #BFDC7A, #8EBF45);
background-image: -ms-linear-gradient(top, #BFDC7A, #8EBF45);
background-image: -o-linear-gradient(top, #BFDC7A, #8EBF45);
color: #6a6340;
-webkit-box-shadow: 0px 0px 3px rgba(0, 0, 0, 0.3);
-moz-box-shadow: 0px 0px 3px rgba(0, 0, 0, 0.3);
box-shadow: 0px 0px 3px rgba(0, 0, 0, 0.3);
}
.ribbon-green:before,
.ribbon-green:after {
content: "";
border-top: 3px solid #6e8900;
border-left: 3px solid transparent;
border-right: 3px solid transparent;
position: absolute;
bottom: -3px;
}
.ribbon-green:before {
left: 0;
}
.ribbon-green:after {
right: 0;
}
.product-box {
width: 292px;
height: 340px;
}
.thumb-wrapper {
height: 100%;
background-color: purple;
}
.product-box img {
width: 100%;
position: absolute;
display: block;
backface-visibility: hidden;
}
.product-box .thumb-detail {
width: 100%;
height: 100%;
position: absolute;
background: blue;
backface-visibility: hidden;
}
.product-box.flip {
perspective: 800px;
}
.product-box.flip .thumb-wrapper {
-webkit-transition: -webkit-transform 1s;
transition: transform 1s;
-webkit-transform-style: preserve-3d;
transform-style: preserve-3d;
}
.product-box.flip .thumb-detail,
.product-box.flip:hover .thumb-wrapper {
-webkit-transform: rotateY(-180deg);
transform: rotateY(-180deg);
}
.product-box.flip:hover .thumb-wrapper .ribbon-wrapper-green {
left: -3px;
-webkit-transform: rotateY(-180deg) translate(-212px) rotate(-90deg);
transform: rotateY(-180deg) translate(-212px) rotate(-90deg);
}
<div class="product-box flip">
<div class="thumb-wrapper">
<div class="ribbon-wrapper-green">
<div class="ribbon-green">TOP</div>
</div>
<img src="#" alt="" title="" height="262" width="262">
<div class="thumb-detail">
</div>
</div>
</div>
Is it possible to create two arrows like the photo below with css or I have to use a png or svg?
So far
HTML
a {
position: relative;
display: block;
padding-left: 30px;
line-height: 45px;
height: 45px;
}
a:after,
a:before {
right: 100%;
top: 26px;
border-left: 1px solid black;
content: " ";
height: 30px;
width: 25px;
position: absolute;
pointer-events: none;
left: 7px;
}
a:after {
-webkit-transform: rotate(135deg);
left: -11px;
}
a:before {
-webkit-transform: rotate(45deg);
top: 5px;
}
Next
jsfiddle
I can't figure how to put another pair of borders.
Thanks in advance
With a bit of tinkering of your example, it's possible, but you'd probably be better off using another method to draw it or using an icon or icon font.
Here's the fiddle
Achieved with
transform: skew();
rather than rotate.
It's possible, but I would just use a SVG in this case:
http://jsfiddle.net/6v7Np/
HTML
<div class="arrow_box"></div>
<div class="arrow_box alt"></div>
CSS
.arrow_box {
position: relative;
background: #fff;
top:50px;
left:60px;
}
.arrow_box.alt {
left:80px;
}
.arrow_box:after, .arrow_box:before {
right: 100%;
top: 50%;
border: solid transparent;
content:" ";
height: 0;
width: 0;
position: absolute;
pointer-events: none;
}
.arrow_box:after {
border-color: rgba(255, 255, 255, 0);
border-right-color: #fff;
border-width: 30px;
margin-top: -30px;
}
.arrow_box:before {
border-color: rgba(0, 0, 0, 0);
border-right-color: #000;
border-width: 31px;
margin-top: -31px;
}
With gradients:
a{
position: relative;
padding-left: 40px;
}
a::before{
content: '';
position: absolute;
width: 40px;
height: 40px;
left: 0;
top: 0;
background-image:
linear-gradient(135deg, transparent 0px, transparent 19px, black 20px, transparent 21px),
linear-gradient(45deg, transparent 0px, transparent 19px, black 20px, transparent 21px),
linear-gradient(135deg, transparent 0px, transparent 19px, black 20px, transparent 21px),
linear-gradient(45deg, transparent 0px, transparent 19px, black 20px, transparent 21px);
background-repeat: no-repeat;
background-size: 50% 50%;
background-position: 0% top, 0% bottom, 50% top, 50% bottom;
/* distance ^ ^ */
}
http://jsfiddle.net/E8sRw/
With the help of CSS Triangle tutorial, I learnt to create triangle shapes.
.arrow-down {
width: 0;
height: 0;
border-left: 20px solid transparent;
border-right: 20px solid transparent;
border-top: 20px solid #ccc;
}
I'm trying to add a border to the triangle but I was unable to do it.
what I achieved:
Expected:(trying something similar border with gray)
Check this JSFiddle
Stuck up no where to start this. I tried outline, but none worked(I know it won't work).
Thanks for taking time to read my question.
Any help is appreciated.
Note: I'm trying this in CSS instead of using images.
When the main triangle or arrow is itself created using the CSS borders, it is impossible to add another border to it without using extra elements. The below are a few options.
Option 1: Using a bigger size pseudo-element and positioning it behind the parent to produce a border-effect.
.arrow-down {
position: relative;
width: 0;
height: 0;
border-left: 20px solid transparent;
border-right: 20px solid transparent;
border-top: 20px solid #ccc;
}
.arrow-down:before {
position: absolute;
content: "";
left: -22px;
top: -20px;
height: 0px;
width: 0px;
border-left: 21px solid transparent;
border-right: 21px solid transparent;
border-bottom: 21px solid transparent;
border-top: 21px solid black;
z-index: -1;
}
<div class="arrow-down"></div>
.arrow-down:before {
position: absolute;
content: "";
left: -22px;
top: -20px;
height: 0px;
width: 0px;
border-left: 21px solid transparent;
border-right: 21px solid transparent;
border-bottom: 21px solid transparent;
border-top: 21px solid black;
z-index: -1;
}
Option 2: Rotating the element (which has the border hack to produce the triangle) and then adding a box-shadow to it.
.arrow-down {
width: 0;
height: 0;
margin: 10px;
border-left: 0px solid transparent;
border-right: 30px solid transparent;
border-top: 30px solid #ccc;
-ms-transform: rotate(225deg); /* IE 9 */
-webkit-transform: rotate(225deg); /* Chrome, Safari, Opera */
-moz-transform: rotate(225deg);
transform: rotate(225deg);
box-shadow: 0px -3px 0px -1px #444;
}
<div class="arrow-down"></div>
.arrow-down {
width: 0;
height: 0;
margin: 10px;
border-left: 0px solid transparent;
border-right: 30px solid transparent;
border-top: 30px solid #ccc;
transform: rotate(225deg); /* browser prefixes added in snippet */
box-shadow: 0px -3px 0px -1px #444;
}
Tested in Chrome v24 and Safari v5.1.7. Should work in other CSS3 compatible browsers also.
The following options do not directly answer the question as it doesn't do a border within border but are others way of producing an arrow/triangle with a border.
Option 3: Using linear-gradients on an element, rotating it to produce the triangle and then adding a border to it using the normal border property.
.arrow-down {
width: 30px;
height: 30px;
margin: 10px;
border-left: 2px solid #444;
background: -webkit-linear-gradient(45deg, #ccc 50%, transparent 50%);
background: -moz-linear-gradient(45deg, #ccc 50%, transparent 50%);
background: -o-linear-gradient(45deg, #ccc 50%, transparent 50%);
background: linear-gradient(45deg, #ccc 50%, transparent 50%);
-webkit-transform: rotate(-45deg);
-moz-transform: rotate(-45deg);
transform: rotate(-45deg);
-webkit-backface-visibility:hidden; /** <-- to prevent diagonal line aliasing in chrome **/
}
<div class="arrow-down"></div>
.arrow-down {
width: 30px;
height: 30px;
margin: 10px;
border-left: 2px solid #444;
background: linear-gradient(45deg, #ccc 50%, transparent 50%);
transform: rotate(-45deg);
backface-visibility:hidden;
}
Option 4: Using a rotated pseudo-element (with background as the color of the triangle) to produce the triangle and then adding a normal border to it. The parent element's overflow is set to hidden and the pseudo-element is positioned appropriately so as to display only half of it (creating the illusion of a triangle).
.arrow-down {
position: relative;
height: 50px;
width: 50px;
overflow: hidden;
}
.arrow-down:before {
position: absolute;
content: '';
top: -webkit-calc(100% * -1.414 / 2);
top: calc(100% * -1.414 / 2);
left: 0px;
height: 100%;
width: 100%;
background: #CCC;
border-left: 2px solid #444;
-webkit-transform: rotate(-45deg);
-moz-transform: rotate(-45deg);
transform: rotate(-45deg);
}
<div class="arrow-down"></div>
.arrow-down:before {
position: absolute;
content: '';
top: calc(100% * -1.414 / 2);
left: 0px;
height: 100%;
width: 100%;
background: #CCC;
border-left: 2px solid #444;
transform: rotate(-45deg);
}
Try adding these lines to your CSS:
.arrow-down:before {
content: "";
display: block;
border-left: 26px solid transparent;
border-right: 26px solid transparent;
border-top: 26px solid #0f0;
position: relative;
left: -26px;
top: -20px;
z-index: -1;
}
This will draw a 3px green border.
Check the result here: jsfiddle
Demo: http://jsfiddle.net/3fFM7/
.arrow {
border-bottom: 60px solid transparent;
border-left: 60px solid black;
border-top: 60px solid transparent;
height: 0;
margin-left: 50px;
width: 0;
behavior:url(-ms-transform.htc);
-moz-transform:rotate(90deg);
-webkit-transform:rotate(90deg);
-o-transform:rotate(90deg);
-ms-transform:rotate(90deg);
}
.arrow > div {
border-bottom: 59px solid transparent;
border-left: 59px solid red;
border-top: 59px solid transparent;
left: -60px;
position: relative;
top: -63px;
width: 0;
}
<div class="arrow"><div></div></div>
Play with transform rotate :)
Or:
DEMO: http://jsfiddle.net/tKY25/1/
<div class="triangle-with-shadow"></div>
.triangle-with-shadow {
width: 100px;
height: 100px;
position: relative;
overflow: hidden;
transform: rotate(180deg);
}
.triangle-with-shadow:after {
content: "";
position: absolute;
width: 50px;
height: 50px;
background: #999;
transform: rotate(45deg);
top: 75px;
left: 25px;
box-shadow: 0px -5px 0 0px rgba(0,0,0,100);
}