tags:

views:

565

answers:

10

I've seen a lot of codes for this but it appears non of them work very well or at all. I've used pictures for rounded corners but I need the code so that it will round the border of a <table>. The only solutions I've found for this problem are to have images In the cells around the border. Anything else I can try?

+16  A: 

Try:

selector {
    -moz-border-radius: 3px;
    -webkit-border-radius: 3px;
    border-radius: 3px;
}

This will work in Firefox, Safari, Chrome and any other CSS3-compatible browser. It may be easier to make a separate class for this - there are 3 statements which are needed for full compatibility.

Also, try here (cssjuice.com) for some more techniques using images.

I'm not completely sure whether this will work with a table, but if you're in complete control - don't use a <table> for layout. Please.

(Note - I think its fine to use the table tag for tabular data, just not where DIVs should be used.)

Update: to apply to one corner only:

-moz-border-radius-topleft: 3px;
/* ... */
-webkit-border-top-left-radius: 3px;

Continue for topright or top-right.

Lucas Jones
There's no simple IE8 solution is there?
JoshBerke
I'm not sure about IE8 to be honest - I use Firefox ;)
Lucas Jones
The table could actually be containing *tabular* information. There is still very large semantic value in the **proper** use of tables.
Ian Elliott
A specific app I have in mind targets IE8, would love to get rid of the extra images or the crazy styles I have for doing various rounded corners.
JoshBerke
About your note.. Of course you *can* use tables whenever you want for whatever you want.. It just depends how far you want to adhere to "guidelines" and "standards" - using tables will work, it just depends on what side of the semantics fence you sit on and whether you really care about "hacky" code.. I'm not saying it's either right or wrong, it just depends on your outlook on standards compliance.. Think about other software companies - Google, for instance, use some very hacky code in some of their web apps.. So it really depends on your outlook on the whole debate.
Perspx
This is a CSS code that its in the present time for "beta" and only works in Mozzila, with IE7 doesn't work. But with IE8 i haven't tested yet.
Fábio Antunes
I went to the cssjuice.com and found the code and it worked right away. Thanks.
Tony C
It's not about using them whenever you want for whatever you want, it's about using them **properly** when displaying **tabular** information. For instance, if I have a list of records to display from a database it is **proper** to display them in a **table**. Tables aren't designed for layouts, but they **are** designed for displaying tabular information, using them for such is proper semantics.
Ian Elliott
As I said.. I wasn't saying either or was right - I'm not going to start another of those arguments.. But it depends what you're doing.. Sometimes you need to break the rules for what you want to do.
Perspx
@Ian, If you reread my answer, you'll find that I do happen to agree with you ;)
Lucas Jones
Then you're defending two sides of an incorrect argument. Semantically, it is proper to use tables for tabular data. 'Breaking the rules', while can sometimes be helpful, is against semantics. There is a right and wrong when defining strict semantics, whether or not the wrong can be justified is another story.
Ian Elliott
@person-b, I understand you're on my side. I'm simply trying to clarify with Perspex.
Ian Elliott
@KGTM: The "-moz-" rules apply to all Gecko browsers. This includes Firefox. The "-webkit-" rules apply to Webkit browsers. This includes Chrome and Safari, along with many others. It's not really *beta* for the normal rules - browsers just haven't got round to implementing them. (See spec here - http://kent.w3.org/TR/2005/WD-css3-background-20050216/#the-border-radius) Also, IE is terrible for standards. Go figure why they didn't implement this one.
Lucas Jones
That's my point - using tables purely for tabular data depends on whether you want to go down the whole semantics road or not. Neither way is "right" or "wrong" because it depends on whether you hold semantics as something important, and whether it's important in what you're doing. That was all I was saying; personally, I agree with semantics, but I was just making the point that it's rather subjective as to what you think of the whole semantics debate.
Perspx
slightly off topic: Reminds me of a statement of Douglas Crockford in "The State of AJAX", http://video.yahoo.com/watch/1382941/4760685 "They are doing realistic human forms ...in real time... on cheap computers ... now look at it from the point of view of a web designer, what do you see? Oh look, rounded corners... we are so far behind the state of the art in the web, we don't even see the state of the art"
VolkerK
(My personal opinion) I'm not particularly bothered about semantics, but tables are just so inflexible and hard to work with.
Lucas Jones
If it's not completely ugly to let IE have square borders, why not just do that? Let the good browsers have the pretty stuff.
Nosredna
+1  A: 

The only way to have support for all browsers is to use image backgrounds on the anchor tags, usually combined with an image on it's container tag as well.

For instance with HTML like this:

<ul>
 <li><a href="">something</a></li>
<ul>

I would place one image on the anchor tag, and one on the li, so that the element can be variable width and still have rounded corners.

There are CSS3 features and JS solutions that may also work, but are not completely cross browser compatible.

Ian Elliott
+2  A: 

Try the CSS 3 selectors:

.element {
border-radius:5px
}

For Safari, Google Chrome (Webkit) and Mozilla use the following two selectors (although Mozilla supports the CSS 3 selector (not sure if the other one does):

.element {
-webkit-border-radius:5px;
-moz-border-radius:5px;
}
Gav
+1  A: 

You can round them through CSS but only for supported browsers.

Your other non-image options are script-based like jQuery Corners or a similar script.

Both of these methods have caveats (IE support, visitors with JavaScript disabled, etc.). If you're set on using them, I would focus on getting them to work with CSS in the browsers that support it and just make sure that it looks acceptable without them in IE.

John Sheehan
The jQuery Corners is a great non-image implementation even supporting anti-aliasing in IE. For fun I took a peek at the generated DOM after the "tweak" is run in IE... Ouch! Their sample page is rounded corner heavy for sure, but I'd say that about 85%+ of the final markup was DIV's and styles added to support IE. ;-)
scunliffe
A: 

If you don't have to work with all browsers, consider using border-radius. See http://www.css3.info/preview/rounded-border/ for more information. Newer Mozilla and Webkit-based browsers support either this tag or moz-border-radius and -webkit-border-radius.

Bob
A: 

Here is a way that isn't browser dependent (that I know of, it works on the popular browsers.) It doesn't use a table, so you'll have to put the table in the most deeply nested div and it is lengthy and heavy, but it works. The images referred to in the code below are the rounded corners you draw yourself. The radius of the corner is 44px.

This is a variation on: http://www.webcredible.co.uk/user-friendly-resources/css/css-round-corners-boxes.shtml

<div class="tl">
    <div class="tr">
        <div class="bl">
            <div class="br">
                <div class="t">
                    <div class="b">
                        <div class="l">
                            <div class="r">
                                <div>Do or do not, there is no try</div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

.tl
{
    font-family: Verdana, Arial;
    font-size: 16px;
    position: relative;
    left: 30px; 
}

.tl, .tr, .bl, .br
{
    width: 655px;
    height: 250px;
}

.t
{
    width: 567px;
    height: 250px;    
    margin: 0 0 0 44px;
}

.b
{
    width: 567px;
    height: 250px;    
}

.l
{
    width: 655px;
    height: 162px;    
    margin: 44px 0 0 -44px; 
}

.r
{
    width: 655px;
    height: 162px; 
}

.bl
{
    background: url(/images/front/rcbla.png) 0 100% no-repeat;
}

.br
{
    background: url(/images/front/rcbra.png) 100% 100% no-repeat;
}

.tl
{
    background: url(/images/front/rctla.png) 0 0 no-repeat;
}

.tr
{
    background: url(/images/front/rctra.png) 100% 0 no-repeat;
} 

.t
{
    background: url(/images/front/adot.png) 0 0 repeat-x;
}

.b
{
    background: url(/images/front/adot.png) 0 100% repeat-x;
}

.l
{
    background: url(/images/front/adot.png) 0 0 repeat-y;
}

.r
{
    background: url(/images/front/adot.png) 100% 0 repeat-y;
}
Steve
That is very heavy. Wouldn't it just be easier to use a table?
Tony C
A: 

I'm assuming that rounded corner CSS above wouldn't work in IE6. Something you may want to keep in mind.

Three stacked divs with background images is the easiest approach.

<div class="top">&nbsp;</div>
<div class="mid"> <!-- content --> </div>
<div class="bottom">&nbsp;</div>

The background for your div with id mid would be vertically tiled through CSS. Works in IE6.

A: 

I tend to go with the border-radius option person-b covered earlier.

If I absolutely have to support IE (i.e. it's a fundamental part of the design and not just a little enhancement), I've had some success with dd_Roundies, which makes use of VML to get the job done.

Olly Hodgson
A: 

You're all awesome! I'm picking up enough perspectives on this issue to help me fully understand what I'm doing. This site rules. Thanks for all the help!

+1  A: 

Check out www.easyimg.com, simple solution that does not require css hacks or hours in photoshop.