Forum Moderators: not2easy

Message Too Old, No Replies

Rounded Corners using CSS

         

bizcredit

4:24 am on May 7, 2008 (gmt 0)

10+ Year Member



Can anyone tell me how to make rounded corner using CSS? Is it other techniques available for it?

Xapti

4:33 am on May 7, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



One of the better i've seen is something like this. I have not seen many types, so that doesn't say for too much.

Depending on the size of your corners, you will likely need to tweak some of the values such as padding.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>cta</title>

<style type="text/css" media="screen">
body {margin:1em;}
pre {font-size:76%;background:#eee;border:1px solid #ddd;overflow:auto;min-height:3em;}
h1 {font-size:144%;}
h2 {font-size:114%;}
h1,h2,h3 {font-weight:bold;margin:0.6em 0 0.3em;}

</style>

<style type="text/css">
.cta {overflow:hidden;display:inline-block;}.cta{display:block;}

.cta a,.cta button{float:left;text-decoration:none;border:0;padding:0;cursor:pointer;font:bold 100% arial,sans-serif;overflow:visible;}
.cta button {background:none;} /* IE Bugs if this is on the anchor */

.cta span{display:block;position:relative;}

.cta a:hover{background:none;} /* Fix IE Hover State */

.cta .t{margin-left:20px;background-position:100% 0;}
.cta .t span{position:relative;left:-20px;background-position:0 0;padding:20px 20px 0 20px;}

.cta .b{margin-left:20px;background-position:100% 100%;font-size:0;}
.cta .b span{position:relative;left:-20px;background-position:0 100%;padding:0 0 40px 0;}

/* Color Variations */

.cta a span,.cta button span{background-image:url(navbox.gif);color:#000;}
.cta a:hover span,.cta button:hover span{background-image:url(navbox.gif);}

.cta .blue span{background-image:url(navbox.gif);color:#fff;}
.cta .blue:hover span{background-image:url(navbox.gif);color:#000;}
</style>

</head>
<body>
<h1>Call To Action</h1>
<h2>Examples</h2>
<h3>Anchor</h3>
<p class="cta"><a class="blue" href="#CTA"><span class="t"><span>Heah<br>brr<br>err<br>grrr!</span></span><span class="b"><span> </span></span></a></p>

<p class="cta"><a class="blue" href="#CTA"><span class="t"><span>
content1<br>
content2<br>
content3<br>
<br>
content1<br>
content2<br>
content3<br>
<br>
content1<br>
content2<br>
content3<br>
<br>
content1<br>
content2<br>
content3<br>

</span></span><span class="b"><span> </span></span></a></p>

<h3>Button</h3>
<form action="?">
<div class="cta"><button type="submit"><span class="t"><span>Hello World</span></span><span class="b"><span> </span></span></button></div>
</form>
</body>
</html>

[edited by: Xapti at 4:35 am (utc) on May 7, 2008]

swa66

2:47 pm on May 7, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



CSS3 - when supported has what you seek right out of the box:

[w3.org...]

Till then it'll be working with the browser specific tags and/or do a graceful degradation to square border for all old browsers.
Or use images etc. to fake it.

The best way to get browsers to support it, is to start to use it and not offer the browsers makers the easy route by using images etc to make it work in their old contraptions. If we don;t use it, they'll never bother to make it work properly.

Xapti

5:01 pm on May 7, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I personally disagree about that. I really don't think it would be noticed by browser developpers. It's more what they get to choose for us (while reffering to W3C of course), not the other way around.

It doesn't mean it can't be done though, since pixel perfect design isn't necessary, and who cares if the borders are square instead of rounded? beats having to pump up a whole bunch of nested elements and background images.

My example was also a broad one, that can be used for things more advanced than just rounded corners, specifically custom borders/corners, which is why I included it.

rocknbil

6:38 pm on May 7, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Mine is a solution similar to Xapti's, except I'm using divs for the corners instead of span. My reasoning is a weak attempt at semantics: spans span text, divs are page divisions, the corners don't really fit into any other semantic category.

The concept is simple: float the corners into position, use background-position to position a single image - a circle - as required. For the vertical and horizontal borders, you nest divs in divs and apply borders to once side or the other.

Similar Solution Here [webmasterworld.com]