2016-03-01 89 views
-2

我是新來的網絡編程,我試圖改變使用CSS的PHP頁面的字體,但是當我使用網上的東西它不工作,但在任何地方它顯示相同的東西這樣做, 這是CSS腳本:CSS更改字體錯誤

body { 
    font-family: 'Roboto Condensed', sans-serif; 
} 
h1, h2, h3, h4, h5, h6 { 
    font-family: 'Amatic SC', cursive; 
} 

這是PHP的一個:

<!DOCTYPE HTML> 
<html> 
<head> 

<link href='http://fonts.googleapis.com/css?family=Amatic+SC:400,700|Roboto+Condensed:400,300' rel='stylesheet' type='text/css'> 

</head> 
</html> 

<?php 

echo "<h1>Hi guys</h1>"; 

?> 
+0

的可能的複製(http://stackoverflow.com/questions/12144000/using-custom-fonts-using -css) –

+0

我已經嘗試過,但那並不奏效,每個人都告訴我試試這個。 –

+0

檢查我的更新! –

回答

0

做到這一點的方法:

@font-face { 
    font-family: 'myFont'; /*a name to be used later*/ 
    src: url('http://domain.com/fonts/font.ttf'); /*URL to font*/ 
} 

然後,您可以添加自定義字體:

.myClass{ 
    font-family: 'myFont'; 
} 

EDT:你是你的字體到body標籤,但你沒有你的HTML裏面的body標籤,你的代碼更改爲這:

<!DOCTYPE HTML> 
<html> 
<head> 

<link href='http://fonts.googleapis.com/css?family=Amatic+SC:400,700|Roboto+Condensed:400,300' rel='stylesheet' type='text/css'> 

</head> 
<body> 

<?php 
echo "<h1>Hi guys</h1>"; 
?> 
</body> 
</html> 
+0

試過但沒有工作。 –

+0

嘗試把你的PHP內的身體標籤! –

0

如果您將css內聯到不是最佳實踐的php文件中。相反,創建一個單獨的CSS表格,並使用上面的方法在PHP文件中調用它。

此鏈接可以幫助你:?使用自定義的字體使用CSS] http://www.w3schools.com/css/css_howto.asp

<head> 
<link rel="stylesheet" type="text/css" href="mystyle.css"> 
</head>