2013-10-09 35 views
0

嗨我在web开发相对较新,我试图让这个工作的类。目标是使用嵌入式CSS类来制作粗体和斜体的字体。到目前为止,我有这个:我是新的与嵌入式css类不与字体样式和字体重量工作的HTML问题

<!DOCTYPE html><!--Chapter 3 ex 4, a demonstration of class--> 
<html lang="en"><!--opens html and sets language to english--> 
<head><!--opens head--> 
<title>Chapter 3 ex 4</title><!--sets the title of the page--> 
<style><!--opens embedded style--> 
.new 
{ 
font-weight: bold;<!--creates a class new--> 
font-style: italic; <!--that is both bold and italic--> 
} 
</style> <!--closes embedded style--> 
<meta charset="utf-8"> 
</head> <!--Closes head--> 
<body> 
<p class="new">Test of new class</p> 
</body> 
</html> 

问题是文本没有受到“新”类的影响。我发现,如果我从标签中删除lang =“en”,字体文本变为粗体。任何人有任何想法我可以做什么来解决这个问题?

回答

1

CSS中的注释是用/* your comment */而不是HTML样式注释完成的。你的CSS是无效的。

<!--opens embedded style--> 
<style> 
.new 
{ 
font-weight: bold; /* creates a class new */ 
font-style: italic; /* that is both bold and italic */ 
} 
</style> <!--closes embedded style--> 
+0

非常感谢。这本书没有很好地解释这一点。 – user2863558

+0

没问题。欢迎来到SO – Cfreak

1

您正在使用妄加评论在您的嵌入式样式表:

.new 
{  
font-weight: bold;/*creates a class new*/ 
font-style: italic; /*that is both bold and italic*/ 
} 
0

如果您删除所有<!-- html comments --><style>标签工作平稳之内。

刚刚用我的浏览器进行了测试。