2013-10-09 32 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>標籤工作平穩之內。

剛剛用我的瀏覽器進行了測試。