I drew a shape by using the border properties in CSS. It looks fine in Chrome, but in Firefox the borders are really ugly:
.shape
{
width: 100px;
height: 50px;
margin: 0 auto;
background-color: #3F7296;
position: relative;
color: #FFF;
line-height: 50px;
font-size: 40px;
}
.b1, .b2
{
position: absolute;
left: 100px;
bottom: 0px;
width: 0px;
height: 0px;
border-style: solid;
border-width: 0px 0px 50px 16px;
border-color: transparent transparent transparent #3F7296;
}
.b2
{
left: -16px;
border-width: 50px 16px 0px 0px;
border-color: transparent #3F7296 transparent transparent;
}
<div class="shape">
<i class="b1"></i>
<i class="b2"></i>
</div>
Fiddle: http://jsfiddle.net/Ly1dz111/
Screenshot from Chrome:
Screenshot from Firefox (Mac OS X)
How can I fix this in Firefox?
This is a known bug in Firefox's handling of diagonal borders, and the workaround is to set a scale transform on the element so that Firefox is forced to run it through an extra graphics step.
In your example, the solution is to set -moz-transform: scale(.9999) on the .b1 and .b2 elements. This forces antialiasing in Firefox.
.shape
{
width: 100px;
height: 50px;
margin: 0 auto;
background-color: #3F7296;
position: relative;
color: #FFF;
line-height: 50px;
font-size: 40px;
}
.b1, .b2
{
position: absolute;
left: 100px;
bottom: 0px;
width: 0px;
height: 0px;
border-style: solid;
border-width: 0px 0px 50px 16px;
border-color: transparent transparent transparent #3F7296;
-moz-transform: scale(.9999)
}
.b2
{
left: -16px;
border-width: 50px 16px 0px 0px;
border-color: transparent #3F7296 transparent transparent;
}
<div class="shape">
<i class="b1"></i>
<i class="b2"></i>
</div>
Related
I am trying to achieve the top right triangle as in the picture shows but when I apply border radius why does it apply borders to all side as I specified only one side radius. Although I applied border-top-right-radius: 5px; instead of border-radius: 0px 5px 0px 0px; I get the same result. Any Help?
HTML:
<div class="pricing-head">
<h3>Rainmarker</h3>
<span>For up to 10 users</span>
<div class="ribon"></div>
</div>
CSS:
.pricing-head {
background-color: #fff;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
padding: 20px;
}
.pricing-head .ribon {
position: absolute;
top: 0;
right: 0;
width: 75px;
height: 75px;
}
.pricing-head .ribon:before {
content: "";
position: absolute;
right: 0;
top: 0;
border-bottom: 70px solid transparent;
border-left: 70px solid transparent;
border-right: 70px solid #ffad6a;
border-radius: 0 5px 0 0;
}
For a rounded top-right border, do:
-webkit-border-top-right-radius: 5px;
-moz-border-radius-topright: 5px;
border-top-right-radius: 5px;
Generator: http://border-radius.com/
To get a top-right triangle, do:
width: 0;
height: 0;
border-style: solid;
border-width: 0 200px 200px 0;
border-color: transparent #009999 transparent transparent;
Generator: http://triangle.designyourcode.io/
To get both the top-right corner triangle and top-right rounded border radius, use a container to the corner with border-radius and overflow:hidden.
.container {
position: relative;
width: 300px;
height: 100px;
-webkit-border-top-right-radius: 5px;
-moz-border-radius-topright: 5px;
border-top-right-radius: 5px;
overflow: hidden;
border: 1px solid gray;
}
.corner {
position: absolute;
top: 0;
right: 0;
width: 0;
height: 0;
border-style: solid;
border-width: 0 100px 100px 0;
border-color: transparent #009999 transparent transparent;
}
.content {
font-family: "Verdana";
font-size: 12pt;
text-align: center;
height: 100px;
line-height: 100px;
}
<div class="container">
<div class="corner"></div>
<div class="content">
Rainmarker
</div>
</div>
OUTPUT
Heres a pen showing what you want: http://codepen.io/anon/pen/VeEKLP
You needed :
border-style: solid;
border-width: 0 200px 200px 0;
border-color: transparent #007bff transparent transparent;
Heres a good resource for making css triangles: http://apps.eky.hk/css-triangle-generator/
I am trying to create a css design like the image attached below. Actually I need to create this style only using CSS without using any images.
I tried get it to work but not sure How to create inner triangle.
This is my HTML -
body {
background: #cdc6e1;
}
.content-box {
background: #28166f;
width: 250px;
height: 100px;
}
.tag {
background: #f8c300;
width: 100px;
height: 0;
padding-left: 10%;
padding-bottom: 10%;
overflow: hidden;
}
.tag:after {
content: "";
display: block;
width: 0;
height: 0;
margin-left: -500px;
border-left: 500px solid transparent;
border-right: 500px solid transparent;
border-bottom: 500px solid #f8c300;
}
<div class="content-box">
<div class="tag">
<h1>1<span>st</span></h1>
</div>
<div class="name">
<h1>First<br>
Place</h1>
</div>
</div>
Hope somebody may help me out to achieve to this custom style.
Thank you.
A basic mockup would be to use some pseudo elements in order to generate this:
.outer {
height: 200px;
width: 400px;
background: purple;
border: 10px solid pink;
position: relative;
text-Align: right;
font-size: 50px;
line-height: 200px;
}
.outer:before,
.outer:after {
height: 0;
width: 0;
position: absolute;
content: "";
border-bottom: 100px solid yellow;
border-right: 70px solid transparent;
border-left: 70px solid transparent;
bottom: 0;
left: 20px;
z-index: 8;
}
.outer:after {
border-bottom: 130px solid blue;
border-right: 90px solid transparent;
border-left: 90px solid transparent;
z-index: 0;
}
.place {
position: absolute;
left: 50px;
color: red;
bottom: -20px;
font-size: 100px;
line-height: initial;
z-index: 10;
text-shadow:
3px 3px 0 white,
/* Simulated effect for Firefox and Opera
and nice enhancement for WebKit */
-1px -1px 0 white,
1px -1px 0 white,
-1px 1px 0 white,
1px 1px 0 white;
}
<div class="outer">First Place
<div class="place">1st</div>
</div>
Note. The text outline property is yet to be implemented in any of the major browsers yet, so it may require a 'larger white text' to be positioned behind to create this text outline in your mockup.
A workaround (as stateed in the comments) would be to 'hack' the text shadow:
text-shadow:
3px 3px 0 white, /* Simulated effect for Firefox and Opera
and nice enhancement for WebKit */
-1px -1px 0 white,
1px -1px 0 white,
-1px 1px 0 white,
1px 1px 0 white;
Text Stroke
Although only available in webkit broswers, you may possibly want to use text-stroke for your 'white border' to the text (unavailable in IE or Firefox)
div {
font-size: 50px;
position: relative;
height: 50px;
width: 50px;
color: black;
}
div:before {
content: "1st";
z-index: -1;
left: 0;
top: 0;
position: absolute;
-webkit-text-fill-color: black;
-webkit-text-stroke: 8px red;
}
html {
background: gray;
}
<div>
1st
</div>
<br/>
<strong>Note</strong> only available in webkit browsers
Create a duplicate triangle and place it behind. Code given below. JSBin: http://jsbin.com/totewinizu/2/
HTML:
.tag {
width: 100px;
display: block;
position: relative;
top: 20px;
border-color: transparent transparent red transparent;
border-style: solid;
border-width: 0px 60px 80px 60px;
height: 0px;
width: 0px;
z-index: 99;
}
.dupe {
position: absolute;
border-color: transparent transparent white transparent;
border-style: solid;
border-width: 0px 60px 80px 60px;
top: 40px;
left: 20px;
z-index: 9;
}
<div class="content-box">
<div class="tag">
<h1>1</h1><span>st</span>
</div>
<div class='tag dupe'>
</div>
<div class="name">
<h1>First<br>
Place</h1>
</div>
</div>
I'm trying to create a tag shape with the css only so that it looks like:
I'm trying following but unable to use the border for the triangle area.
HTML:
Test
CSS:
a{
float: left;
height: 35px;
position:relative;
border: 1px solid red;
border-right: none;
width: 100px;
}
a:before{
content: "";
position: absolute;
top: -1px;
right: -18px;
width: 0;
height: 0;
border-color: white white white red;
border-style: solid;
border-width: 19px 0 18px 18px;
}
JSFiddle:
http://jsfiddle.net/Sac3m/
You could rotate a square instead, although i doubt the results will be great cross-browser
Modified code:
a {
float: left;
height: 35px;
position: relative;
border: 1px solid red;
border-right: none;
width: 100px;
}
a:after {
content: "";
position: absolute;
top: 4px;
right: -13px;
width: 25px;
height: 25px;
border: 1px solid red;
border-left: none;
border-bottom: none;
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
transform: rotate(45deg);
}
<a></a>
(Latest IE, Firefox and Chrome seems OK with it)
Update
If you need IE8 support, you could try to put a white triangle on top of the (original) red triangle:
a {
float: left;
height: 36px;
position: relative;
border: 1px solid red;
border-right: none;
width: 100px;
}
a:before {
content: "";
position: absolute;
top: -1px;
right: -18px;
width: 0;
height: 0;
border-color: white white white red;
border-style: solid;
border-width: 19px 0 19px 19px;
}
a:after {
content: "";
position: absolute;
top: 0;
right: -17px;
width: 0;
height: 0;
border-color: transparent transparent transparent white;
border-style: solid;
border-width: 18px 0 18px 18px;
}
<a></a>
The below code helps to create a tag shape. It works in all major browsers.
#swc {
position: relative;
margin: 0 5px 0 10px;
display: inline-block;
height: 66px;
padding: 0 35px 0 20px;
font-size: 25px;
line-height: 65px;
cursor: pointer;
font-weight: 100;
margin: 20px 25px;
background: #f3f3f3;
transition: background 0.3s;
}
#swc:after {
position: absolute;
content: "";
right: -19px;
width: 1px;
height: 0px;
border-left: 18px solid #f3f3f3;
border-top: 33px solid transparent;
border-bottom: 33px solid transparent;
transition: border 0.3s;
}
#swc:hover {
background: green;
color: #ffffff;
}
#swc:hover:after {
border-left-color: green;
}
<span class="pricetag-right" id="swc">Tag Content!</span>
We had a slightly different implementation of this that produces rounded corners. This uses a rounded square that's turned 45°.
.tag {
display: inline-block;
border-width: 1px;
border-style: solid;
border-color: #c8d7f2 transparent #c8d7f2 #c8d7f2;
border-radius: .25em 0 0 .25em;
padding: 0.1em 0.6em 0.1em 0.3em;
background-color: #e5ecf9;
line-height: 1.2em;
}
.tag:after {
content: "\25CF";
position: absolute;
display: inline-block;
height: 1.2em;
width: 1.17em;
transform: rotate(45deg);
color: white;
text-indent: 0.3em;
line-height: 1em;
text-shadow: 0 0 1px #333;
background-color: #e5ecf9;
border-radius: 0.33em 0.33em 0.33em 1em;
border-width: 1px;
border-style: solid;
border-color: #c8d7f2 #c8d7f2 transparent transparent;
}
<h1 class="tag">my-tag</h1>
A couple things to note:
The square contains a circle punctuation mark. To adjust it you use line-height and text-indent.
The borders on the square need to be set to transparent color with a width of 1px. If you don't, the other borders (the visible ones) taper off where they go from 1px to 0px.
his works pretty well and it's nearly pixel-perfect, but it does render slightly differently across Chrome and Firefox. I tried to make it work with a transparent background, but you need some sort of color to cover up the funkiness where the square meets the tag. It's not quite perfect.
The nice thing about this is that it can be applied as a class and it can be used on H1-H6, or p tags.
Does anyone know how to make edgy corners like in the following below? See how the edge wraps around the corner. I would like to know the term as well (if any). cross browser support (IE8 and up, bonus IE7) is a must. Thanks for any help.
Check out this tutorial. I don't know how crossbrowser compatible it is (as it is CSS3), but it achieves the effect you want.
HTML:
<div>
<h2></h2>
</div>
CSS:
div {
width: 200px;
padding: 50px;
margin: 0 auto;
border: 1px solid #333;
}
h2 {
position: relative;
width: 50%;
height: 50px;
margin: 30px 10px 10px -70px;
background-color: orange;
}
h2:after {
content: ' ';
position: absolute;
width: 0;
height: 0;
left: 0px;
top: 100%;
border-width: 5px 10px;
border-style: solid;
border-color: #666 #666 transparent transparent;
}
JS Fiddle Example
.box{
background: #666;
border: 4px solid #fff;
box-shadow: 0px 0px 20px #000;
width: 200px;
height: 200px;
margin: 40px auto;
position: relative;
}
.ribbon{
background: #FFA500;
position: absolute;
width: 100%;
top: 20px;
left: -20px;
height: 20px;
padding-right: 20px;
}
.ribbon::before{
content: '';
position: absolute;
left: 0px;
top: 20px;
width: 0px;
height: 0px;
border-style: solid;
border-width: 0 16px 10px 0;
border-color: transparent #FFA500 transparent transparent;
z-index: -5;
}
HTML:
<div class="box">
<div class="ribbon"></div>
</div>
(DEMO)
I don't think IE 7/8 support the ::before pseudo-element, so if you want IE compatibility add another element and put ::before styles on it :)
That edgy corner is only a div with a triangle actually, you only need ONE element to do it.
<div id="myCorner"></div>
myCorner will be the div, and myCorner:after will be the triangle.
Check it out : http://jsfiddle.net/Starx/Xp6E7/2/
#myCorner
{
width:100px;
height:70px;
background-color:orange;
-webkit-box-shadow: 0 4px 5px -3px black;
-moz-box-shadow: 0 4px 5px -3px black;
box-shadow: 0 4px 5px -3px black;
position:relative;
}
#myCorner:after
{
content:"";
position:absolute;
left: 0;
top:100%;
width: 0px;
height: 0px;
border-style:solid;
border-width: 5px 10px;
border-color: orange orange transparent transparent;
z-index: -1;
}
Context
I did a pure CSS tooltip with pseudo-element :before and :after for the arrow.
The rendering is different from Chrome 16 to Firefox 9 and 10.
You see what's wrong?
Chrome screenshot
Firefox screenshot
Demo
http://jsfiddle.net/wDff8/ reproduces the same issue.
Code
html:
<span class="tooltip">Déposez votre fichier dans ce dossier</span>
css:
span.tooltip {
display: inline-block;
background: #eee;
margin-left: 20px;
padding: 0 10px;
color: #111;
border-radius: 2px;
border-top: 1px solid #bbb;
border-right: 1px solid #bbb;
border-bottom: 1px solid #bbb;
line-height: 1.5;
position: relative;
}
span.tooltip:before {
content:"";
position: absolute;
width: 0;
height: 0;
border-style: solid;
border-width: 10px;
border-color: transparent #eee transparent transparent;
left: -18px;
top: -1px;
z-index: 1;
}
span.tooltip:after {
content:"";
position: absolute;
width: 0;
height: 0;
border-style: solid;
border-width: 11px;
border-color: transparent #bbb transparent transparent;
left: -21px;
top: -2px;
z-index: 0;
}
body {
font-family: Georgia;
font-size: 12px;
letter-spacing: 1px;
}
May be Instead of transparent you have to write this rgba(238,238,238,0)in your css check this for more
CSS Transparent Border Problem In Firefox 4?
Solution
I juste removed a few pixels, which corrected the rendering on Firefox.
The rendering is not identical but close enough.
Chrome screenshot
Firefox screenshot
Demo
http://jsfiddle.net/wDff8/1/
Modified code
span.tooltip:after {
border-width: 10px;
left: -19px;
top: -1px;
}