Duncan Palmer
Duncan Palmer

Reputation: 2913

HTML/CSS Rounded Rectangles?

Is it possible to create a rectangle with rounded edges without using an image? For example:

Rounded Edges

Thank you.

Upvotes: 3

Views: 45192

Answers (5)

Vitali Pom
Vitali Pom

Reputation: 602

Make a rectangle clip and place a rectangle with thick and round border over it.

Upvotes: 0

talha2k
talha2k

Reputation: 1

This is a good tutorial to understand rounded border for any div:

http://www.css3.info/preview/rounded-border/

Or you can round a border of a certain div like this:

#div1 {
-moz-border-radius: 15px; //for mozilla support
-webkit-border-radius: 15px; //for chrome support
border-radius: 15px;
}

in a nut shell:

You can combine these as you like. -webkit-... will only be recognized by WebKit browsers (Chrome, Safari), -moz-... will only be recognized by Mozilla-based browsers (Firefox.)

EDIT:

You can only apply border-radius to td, not tr or table. I've gotten around this for rounded corner tables by using these styles:

table { border-collapse: separate; }
td { border: solid 1px #000; }
tr:first-child td:first-child { -webkit-border-top-left-radius: 15px; }
tr:first-child td:last-child { -webkit-border-top-left-radius: 15px; }
tr:last-child td:first-child { -webkit-border-top-left-radius: 15px; }
tr:last-child td:last-child { -webkit-border-top-left-radius: 15px; }

Hope this helps.

Upvotes: 13

Rhys
Rhys

Reputation: 2877

Here are some examples and also browser support info.

border---radius: [ | <%> ] [ | <%> ]?

#example1 {
-moz-border-radius: 15px;
border-radius: 15px;
height: 150px;
Width:150px;
} 

Real World Example: This should show a grey box with rounded corders in most browsers except IE < 7

HTML

<div id="RoundCorners">

</div>

CSS

#RoundCorners
{
   border-radius: 15px;
   moz-border-radius: 15px; //If using Firefox
   background-color: #333;
}

At present Opera (version 10.5 onward), Safari (version 5 onward) and Chrome (version 5 onward) all support the individual border-*-radius properties and the border-radius shorthand property as natively defined in the current W3C Specification (although there are still outstanding bugs on issues such as border style transitions, using percentages for lengths, etc.).

Mozilla Firefox (version 1.0 onward) supports border-radius with the -moz- prefix, although there are some discrepancies between the Mozilla implementation and the current W3C specification (see below).

Update:Recent Firefox nightly versions support border-radius without the -moz- prefix.

Safari and Chrome (and other webkit based browsers) have supported border-radius with the -webkit- prefix since version 3 (no longer needed from version 5 onward), although again with some discrepancies from the current specification (see this article for further details of how older versions of Webkit handle border-radius).

Even Microsoft have promised, and demonstrated in their recent preview release, support for border-radius from Internet Explorer 9 onward (without prefix).

Upvotes: 1

Paul
Paul

Reputation: 141827

Something like this, with your own customizations:

HTML

<div class="outer">
    <div class="top">Settings</div>
    This is some text. It is part of an example of rounded borders in css. It is two lines long by now, I suppose.
</div>

CSS

div.outer{
    -webkit-border-radius: 20px;
    -moz-border-radius: 20px;
    border-radius: 20px;
    overflow: hidden;
    background-color: #333;
    color: #8AF;
    padding: 0px 20px;
}

div.outer .top{
    margin: 0px -20px;
    padding: 0px 20px;
    background-color: #8AF;
    color: #000;
}

JSFiddle Example

Upvotes: 3

Sylvain Cleymans
Sylvain Cleymans

Reputation: 1907

You can use the css property border-radius.

However it is not supported on older browser.

Upvotes: 0

Related Questions