How would i create the below using pure CSS (no images, no tables, no javascript)?
+10
A:
HTML:
<div class="box">
<h2>Div Title</h2>
<p>Div content.</p>
</div>
and the CSS:
.box {border:2px solid #0094ff;}
.box h2 {background:#0094ff;color:white;padding:10px;}
.box p {color:#333;padding:10px;}
Use CSS3 for border radius
.box {
-moz-border-radius-topright:5px;
-moz-border-radius-topleft:5px;
-webkit-border-top-right-radius:5px;
-webkit-border-top-left-radius:5px;
border-top-left-radius:5px;
border-top-right-radius:5px;
}
The above code will work in firefox, safari, chrome, opera (10.5 +) etc
Now with bonus demo
wiifm
2010-03-31 10:09:17
No, Opera (and IE 9, some day) don’t support `-moz-` or `-webkit-` prefixes.
toscho
2010-03-31 10:24:28
Cheers added extra CSS classes to support opera, reference http://dev.opera.com/articles/view/css3-border-background-boxshadow/
wiifm
2010-03-31 10:31:13
is it possible to add a gradient color for `.box h2` background?
n002213f
2010-03-31 10:54:52
Sure is, just change the background CSS style from {background:#0094ff;} to {background:#0094ff url('/pat/to/image.png') repeat-x scroll 0 0;}
wiifm
2010-03-31 19:06:42
+1
A:
What you want is not possible unless you dont really care about support in internet explorer.
Fabian
2010-03-31 10:10:50
+2
A:
HTML:
<div class="myDiv">
<h2>Div Title</h2>
<p>Div content.</p>
</div>
CSS:
.myDiv {
border:2px solid #0094ff;
-webkit-border-top-left-radius:6px;
-webkit-border-top-right-radius:6px;
-moz-border-radius-topleft:6px;
-moz-border-radius-topright:6px;
border-top-left-radius:6px;
border-top-right-radius:6px;
width:300px;
font-size:12pt; /* or whatever */
}
.myDiv h2 {
padding:4px;
color:#fff;
margin:0;
background-color:#0094ff;
font-size:12pt; /* or whatever */
}
.myDiv p {
padding:4px;
}
Demo.
RegDwight
2010-03-31 10:15:02
A:
As Fabian said, you cannot do exactly what you want within Internet Explorer. If you still decide you want to create that without any images/javascript, I strongly suggest that you use some conditional statements - a surprising number of people still use Internet Explorer and I'm a little worried how that sort of solution would render in IE!
Best of luck - this was a really great question!
Greg Hluska
2010-03-31 16:06:18