speakerman
06-25-2010, 08:01 AM
Hi there,
I am new to this forum and I just starded to learn CSS. I am struggling with the following and would appreciate every help very much. I learned that the id selector is more specific than the tag selector. Therefore, the style applied to an id selector should overwrite the style of a tag selector. I tried that in the following code but it does not work. In the div bottom tag, only the p tag is overwritten by the div style. The h1 and body style is not affected. Why?? Thanks a lot!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
body {
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
font-size: 100%;
color: #666;
}
h1 {
font-family: Tahoma, Geneva, sans-serif;
font-size: 1.2em;
color: #600;
}
p {
font-size: 0.9em;
font-family: "Courier New", Courier, monospace;
}
#bottom {
font-family: Tahoma, Geneva, sans-serif;
color: #FFF;
background-color: #999;
}
-->
</style>
</head>
<body>
<h1>This is an H1 outside of the div bottom tag. Therefore, the h1 style should apply.</h1>
This is just text without a paragraph and outside of the div tag. Therefore, the body style should apply.
<p>This is a paragraph outside of the div bottom tag. Therefore the p style should apply.</p>
<div id="bottom">
<h1>This is an H1 inside the div bottom tag. Therefore the div bottom style should apply.
</h1>
This is just text without a paragraph but in the div tag. Therefore, the div bottom style should apply.
<p>This is a paragraph inside the div bottom tag. Therefore, the div bottom style should apply. Apparently, only the p tag inside the div tag is overwritten by the div tag. I thought the div tag is always more specific than a p h1 or body tag. </p>
</div>
</body>
</html>
I am new to this forum and I just starded to learn CSS. I am struggling with the following and would appreciate every help very much. I learned that the id selector is more specific than the tag selector. Therefore, the style applied to an id selector should overwrite the style of a tag selector. I tried that in the following code but it does not work. In the div bottom tag, only the p tag is overwritten by the div style. The h1 and body style is not affected. Why?? Thanks a lot!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
body {
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
font-size: 100%;
color: #666;
}
h1 {
font-family: Tahoma, Geneva, sans-serif;
font-size: 1.2em;
color: #600;
}
p {
font-size: 0.9em;
font-family: "Courier New", Courier, monospace;
}
#bottom {
font-family: Tahoma, Geneva, sans-serif;
color: #FFF;
background-color: #999;
}
-->
</style>
</head>
<body>
<h1>This is an H1 outside of the div bottom tag. Therefore, the h1 style should apply.</h1>
This is just text without a paragraph and outside of the div tag. Therefore, the body style should apply.
<p>This is a paragraph outside of the div bottom tag. Therefore the p style should apply.</p>
<div id="bottom">
<h1>This is an H1 inside the div bottom tag. Therefore the div bottom style should apply.
</h1>
This is just text without a paragraph but in the div tag. Therefore, the div bottom style should apply.
<p>This is a paragraph inside the div bottom tag. Therefore, the div bottom style should apply. Apparently, only the p tag inside the div tag is overwritten by the div tag. I thought the div tag is always more specific than a p h1 or body tag. </p>
</div>
</body>
</html>