5

I want to make the following shape using divs and border radius, with fall back to square corners for old browsers. No images please.

I am having a bit of trouble making the bottom corner next to the title (highlighted with the red box). I don't want a lot of unnecessary divs, it has to be as simple and semantic as possible. alt text http://img715.imageshack.us/img715/4214/bradiuswut.gif

<div class="container">
   <div class="header">Title</div>
   <div class="body">Content</div>
</div>

.container{width: 660px; background: #fff;}
.container .header{float: left; width: 110px; background: #333; border-radius: 5px 5px 0 0;}
.container .body{clear: left; width: 660px; background: #333; border-radius: 0 0 5px 5px;}

Any ideas?

EDIT 1:

I did it like this: http://jsfiddle.net/a93Rb/16/

<div class="container">
    <div class="header"></div>
    <div class="headerspacer">
       <div class="headercorner"></div>
    </div>
    <div class="body"></div>
</div>

.container{width: 660px; background: #fff;}
.container .header{float: left; width: 110px; height: 30px; background: #333; border-radius: 10px 10px 0 0;}  
.container .headerspacer{float: left; position: relative; width: 550px; height: 30px; background: #333;} 
    .container .headerspacer .headercorner{ position: absolute; width: 550px; height: 30px; background: #fff; border-radius: 0 0 0 10px;} 
.container .body{clear: left; width: 660px; height: 100px; background: #333; border-radius: 0 0 10px 10px;}

EDIT 2:

I am going to use this method: http://jsfiddle.net/a93Rb/13/

I also found a method of using an image which will not appear if the browser does not support rounded corners. It is much more semantic, and the whole point of using border-radius is to negate unnecessary markup. I think I will actually use this method, but I won't accept it as an answer as I stated that I do not want images.

<div class="container">
    <div class="header"></div>
    <div class="body"></div>
</div> 

.container{width: 660px; background: #fff;}
.container .header{float: left; width: 110px; height: 30px; background: #333; border-radius: 10px 10px 0 0;}                                  
.container .header:after{content: url(http://img24.imageshack.us/img24/1112/corner0.gif); display: block; margin: 20px 0 0 110px;}
.container .body{clear: left; width: 660px; height: 100px; background: #333; border-radius: 0 0 10px 10px;}
theorise
  • 7,245
  • 14
  • 46
  • 65
  • 1
    white rounded div above (with proper z-index)? If you can tolerate one extra div. – alxx Dec 07 '10 at 11:28
  • @alxx I could tolerate an extra div, not too sure how a white rounded div will fix the problem though! – theorise Dec 07 '10 at 11:29
  • float:left; of the .header, border-radius on bottom left & white background? – danjah Dec 07 '10 at 11:34
  • @Danjah the problem is the background of the container div is white, so if the div right of the header is white too, you will not see it! :( This is puzzling me. – theorise Dec 07 '10 at 11:37
  • 1
    it just needs dark background underneath, so there will be two extra divs. – alxx Dec 07 '10 at 11:46
  • @alxx that worked, thanks man. Add it as an answer so I can accept it. Two divs sucks, but it seems like the only option. – theorise Dec 07 '10 at 11:50
  • @danixd, I got a Pure CSS solution for you, check my answer – Starx Dec 07 '10 at 12:20
  • @danixd, it think this was an excellent question, this istuation is quite particular, I think this made the answers sort of clumsy (many divs etc etc). I'll be posting if I find any "better" solution or alternative. – Trufa Dec 07 '10 at 12:45

9 Answers9

4

Here is your pure CSS solution http://jsfiddle.net/Starx/a93Rb/, only compatible with FF for now. You can make it compatible for the remaining browsers.

Starx
  • 77,474
  • 47
  • 185
  • 261
4

As many suggested before, dark div with white div inside and border-radius on bottom-left corner. Example here.

The code is rough and should be rewritten, but it works. And you should synchronize div background color with page color.

  • I changed border-radius to -moz-border-radius, it almost works, but .corner div renders one pixel higher than it should in Firefox. – alxx Dec 07 '10 at 12:04
  • I was doing just that, you beat me to it +1!! great result, I gave it a lot of though and cant see any way with less `
    `right?
    – Trufa Dec 07 '10 at 12:05
  • @alexx that must be becouse of the border, the border (unlike the outline) has a width (ocupies space) I dont know if that whats you ment! – Trufa Dec 07 '10 at 12:06
3

I'm coming late to the party, but I love a challenge and here is my solution:

demo

http://jsfiddle.net/mtTLu/

Features:

  1. No extra markup
  2. Falls back to straight corners
  3. No images
  4. Webkit and Firefox ready.

However, it's terrible css code. If I ever encountered someone who made this to avoid one div of unsemantic code, I'd punch him in the face.

But, I think it fits your constraints.

methodofaction
  • 70,885
  • 21
  • 151
  • 164
2

My idea was white rounded div with dark background under bottom left corner. (I can't get it to work myself, so it would be great to see result :) )

alxx
  • 9,897
  • 4
  • 26
  • 41
  • @danixd I'm sorry @alexx but IMHO I think you should accpt Klaster_1 answer, It is basically the same principle but Klaster has a working example that looks very promising! – Trufa Dec 07 '10 at 12:03
  • @Akinator alxx posted the answer in a comment much earlier, which is why I accepted the answer, even without a jsfiddle example. – theorise Dec 07 '10 at 12:49
  • @danixd fair enough, I'm not on anybody's side :) but if the answers were identical, I would agree with you, but this is not the case. I think Klaster's answer is the most complete and will help more to future comers to this site, to them it won't matter who answered first, rather, which is the most helpful. But of course, this is MY opinion, I'll leave it up to you, @alexx was definitely quick. – Trufa Dec 07 '10 at 12:53
1

Here is my solution.

I'm sure it is not the best but I did it for leaning purposes I thought it might help someone out!

The "final" result is this:

alt text

You can see it working here.

The code goes like this:

HTML

<div id="big">

</div>
<div id="other">

</div>
<div id="small">

</div>


<div id="cont">

</div>

The CSS

#big{
    background-color:#aaa;
    float:left;
    border: 1px solid red;    
    -webkit-border-top-left-radius: 15px;
    -webkit-border-top-right-radius: 15px;
    -moz-border-radius-topleft: 15px;
    -moz-border-radius-topright: 15px;
    border-top-left-radius: 15px;
    border-top-right-radius: 15px;
    height: 50px;
    width: 100px;
}

#cont{
    background-color:#aaa;
    float:bottom;
    margin-top:51px;
    border: 1px solid red;    
    -webkit-border-bottom-right-radius: 15px;
    -webkit-border-bottom-left-radius: 15px;
    -moz-border-radius-bottomright: 15px;
    -moz-border-radius-bottomleft: 15px;
    border-bottom-right-radius: 15px;
    border-bottom-left-radius: 15px;
    height: 250px;
    width: 300px;
}

#small{
    float:left;
    margin:25px 0 0 -27px;
    border: 1px solid red;    
    -webkit-border-bottom-left-radius: 15px;
    -moz-border-radius-bottomleft: 15px;
    border-bottom-left-radius: 15px;
    height: 25px;
    width: 25px;
    background-color:#fff;
}

#other{
    z-index:-1;
    float:left;
    margin:25px 0 0 -1px;
    border: 1px solid red;
    height: 25px;
    width: 25px;
    background-color:#aaa;
}

Hope it helps, good luck!

Trufa
  • 39,971
  • 43
  • 126
  • 190
  • Tried to make it as compatible as possible but could only test it Chrome, to be honest, no idea how it degrades! – Trufa Dec 07 '10 at 12:48
  • Degrades like this on IE6. Maybe it is JFiddle's fault ;) http://img843.imageshack.us/img843/5411/screenshot20101207at125.png – theorise Dec 07 '10 at 12:54
  • 1
    @danixd That is not a degradation, that's a freaking mayhem! I'll test and try to improve it! – Trufa Dec 07 '10 at 13:15
1

I also found a method of using an image which will not appear if the browser does not support rounded corners. It is much more semantic, and the whole point of using border-radius is to negate unnecessary markup. I think I will actually use this method, but I won't accept it as an answer as I stated that I do not want images. But here it is: http://jsfiddle.net/a93Rb/13/

<div class="container">
    <div class="header"></div>
    <div class="body"></div>
</div> 

.container{width: 660px; background: #fff;}
.container .header{float: left; width: 110px; height: 30px; background: #333; border-radius: 10px 10px 0 0;}                                  
.container .header:after{content: url(http://img24.imageshack.us/img24/1112/corner0.gif); display: block; margin: 20px 0 0 110px;}
.container .body{clear: left; width: 660px; height: 100px; background: #333; border-radius: 0 0 10px 10px;}
theorise
  • 7,245
  • 14
  • 46
  • 65
1

Your question was "the most semantic way". There is nothing semantic about the containers/layout divs of the container. Semantic web means helping others understand different content, such as a table should be a table a list should be a list etc.

On that note you have not marked up elements correctly, be careful of using div tags in replacement of there true meaning.

<div class="whatever_label">
   <h2>Title</h2> <!-- or lower level heading: h3,h4 etc. -->
   <span></span>
   <p>Content</p>
</div>

/* Container of module */
.whatever_label{
}
/* Heading Tab */
.whatever_label h2{
}
/* Radius: Heading Tab */
.whatever_label span{
}
/* Content */
.whatever_label p{
}

A good tip for working out whether a html document is using good semantics, is to turn off css styling in your browser and if it is still logical, it will tend to be semantic.

Edit, this appears to be the cleanest way i could come up with, hope it helps:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Box Demo</title>
<style type="text/css">

/* :: Reset default browser stylings.
-------------------------------------------------------------------------------------------------------------------- */
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, cite, dfn, ins, kbd, q, code, samp, del, em, var, strong, pre,/* sub, sup,*/
a, abbr, acronym, address, big, font, img, s, 
small, strike, tt, 
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td {margin: 0; padding: 0; border: 0; outline: 0; font-weight: normal; font-style: normal; font-size: 100%; vertical-align: baseline;}
body {color: black; background: white;}
ol, ul {list-style: none;}
table{border-collapse: collapse;}

/* Container of module */
.box{
  width:600px;
}
/* Heading Tab */
.box h2{
  float:left;
  font-size:1.0em;
  color:white;
  background: #333;
  height:10px;
  padding:15px 20px 25px 20px;
  margin:0;
  -moz-border-radius: 10px 10px 0 0;
  border-radius: 10px 10px 0 0;
}
.box div.radius{
  background: #333;
  float: left;
  height: 25px;
  margin: 25px 0px 0px 0px;
  width: 20px;
}
/* Radius: Heading Tab */
.box span{
  background-color: white;
  -moz-border-radius:0 0 0 10px;
  border-radius: 0 0 0 10px;
  float: left;
  height: 25px;
  margin: 0;
  width: 20px;
}
/* Content */
.box p{
  display:block;
  clear:both;
  color:white;
  background: #333;
  width:560px;
  padding:20px;
  margin:0;
}

</style>

</head>
<body style="margin:20px;">
<div class="box">
   <h2>Whatever title</h2> <!-- or lower level heading: h3,h4 etc. -->
   <div class="radius"><span></span></div>
   <p>Nullam fermentum nibh eget lectus cursus elementum. Vestibulum congue elementum erat, 
    at adipiscing libero blandit sed. Aliquam erat volutpat. Duis feugiat blandit sagittis. 
    Praesent interdum fringilla rutrum. Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
    Nunc dui nulla, sodales et posuere nec, varius quis nisl. Cras mauris ipsum, commodo sit amet 
    sollicitudin ut, rutrum eget erat. Nullam aliquam, massa et sagittis suscipit, massa erat 
    adipiscing turpis, et luctus metus velit quis ante. Maecenas elementum tristique euismod. 
    Phasellus iaculis arcu eget libero tempor accumsan. Vestibulum at turpis ac dui venenatis condimentum.
    Duis tristique neque at nisi feugiat ac congue nibh luctus. Proin non elit et sapien feugiat dictum nec at diam.
    Quisque quis feugiat velit. Mauris id tortor id ligula vulputate dictum ac vitae elit. 
    Maecenas congue tincidunt leo, ut lobortis mi tempor sit amet. Vestibulum condimentum euismod neque. 
    Vivamus ullamcorper odio ut lacus ullamcorper id pellentesque orci euismod. Ut vitae arcu nulla.
    </p>
</div>
</body>
</html>
Pete
  • 11
  • 2
  • I know what semantic means. I was under the impression you knew that too. Anyway what I mean was, the less (useless) divs I use, the better the semantics. I.e. not using two blank divs just to create the curved edge. – theorise Dec 07 '10 at 15:53
  • using these instead of a heading tag

    and

    Title
    Content
    , i dont think you do know what semantic web is. It wasnt meant to be a personal attack. Just to show you that it can be done by using the tags shown above instead of divs, which is what you wanted ?
    – Pete Dec 07 '10 at 16:00
0

You should also consider using dl element.

This HTML:

<dl>
    <dt>..</dt>
    <dd>..</dd>
</dl> 

will have more pure semantics than nested divs, but is probably more awkward with only one "title-content" block.

At last h(1-6) elements will have more semantics than div class="header"

Flack
  • 5,862
  • 2
  • 23
  • 27
-1

Pete's was the best answer, he was right, the other solutions aren't 'semantic' at all. Its an important distinction and from the way you asked the question, really the most important element of it. Semantic doesn't mean 'simple' it means that the right tags should be used to most closely represent what they contain or describe but without resorting to visual description since that is totally mutable. Same for classes and ids. The div tag, while useful, is probably one of the least semantic tags there is and should be used sparingly.

Jesse
  • 386
  • 2
  • 8