2011-08-08 37 views
5

我正在使用this service在我的CSS中創建@font-face規則。我所做的是創建了兩個規則,一個是正常重量字體,另一個是粗體重版本。像這樣:如果在CSS中使用備用字體,是否可以使用觸發器?

@font-face 
{ 
    font-family: 'CenturyGothicRegular'; 
    src: url('/static/fonts/gothic_2-webfont.eot'); 
    src: url('/static/fonts/gothic_2-webfont.eot?#iefix') format('embedded-opentype'), 
      url('/static/fonts/gothic_2-webfont.woff') format('woff'), 
      url('/static/fonts/gothic_2-webfont.ttf') format('truetype'), 
      url('/static/fonts/gothic_2-webfont.svg#CenturyGothicRegular') format('svg'); 
    font-weight: normal; 
    font-style: normal; 
} 
... and another for 'CenturyGothicBold' 

我遂作出上述整體的字體爲我的網站的默認回宋體,像這樣:

body 
{ 
    font-family: "CenturyGothicRegular", Verdana; 
    font-size: 14px; 
} 

並取得了一點規則<strong>使,而不是使體重正常大膽的版本(這似乎只是舒展它),大膽重量的版本將被使用:

strong 
{ 
    font-weight: normal; 
    font-family: 'CenturyGothicBold'; 
} 

一個問題,我可以預見這裏要說的是,如果字體已默認爲宋體,黑體將不是b電子禮物。

有沒有一種方法可以爲<strong>指定一組新規則,只有在字體默認爲Verdana時才適用?

回答

2

沒有必要找到觸發器來查看是否使用了倒退字體。

您需要做的是使用相同的姓氏在@font-face規則中設置font-weight。所以,你現在會叫它CenturyGothic

@font-face { 
    font-family: 'CenturyGothic'; /* this used to be CenturyGothicRegular */ 
    src: url('/static/fonts/gothic_2-webfont.eot'); 
    src: url('/static/fonts/gothic_2-webfont.eot?#iefix') format('embedded-opentype'), 
     url('/static/fonts/gothic_2-webfont.woff') format('woff'), 
     url('/static/fonts/gothic_2-webfont.ttf') format('truetype'), 
     url('/static/fonts/gothic_2-webfont.svg#CenturyGothicRegular') format('svg'); 
    font-weight: normal; 
    font-style: normal; 
} 

@font-face { 
    font-family: 'CenturyGothic'; /* this used to be CenturyGothicBold but the urls still need to point to the files they were pointing at */ 
    src: url('/static/fonts/gothic_2-webfont.eot'); 
    src: url('/static/fonts/gothic_2-webfont.eot?#iefix') format('embedded-opentype'), 
     url('/static/fonts/gothic_2-webfont.woff') format('woff'), 
     url('/static/fonts/gothic_2-webfont.ttf') format('truetype'), 
     url('/static/fonts/gothic_2-webfont.svg#CenturyGothicRegular') format('svg'); 
    font-weight: bold; 
} 

body{ 
    font-family: "CenturyGothic", Verdana; 
    font-size: 14px; 
} 

strong{ 
    font-weight: bold; 
} 

這兩個字體結合成一個font-family允許它像任何其他font-family即當你把它bold它會顯示的字體等的粗體版本。

+0

@marty將無法正常工作:讓我知道這是否需要更多解釋。 – tw16

+0

看起來不錯,給我一個機會來實現這個,我會回到你身邊:) – Marty

+0

兩個字。 http://29.media.tumblr.com/tumblr_lopyvvDXoi1qm5hblo1_500.jpg – Joonas

0

使用font-weight只能用相同font-family當你有幾個weight,喜光,超輕,凝聚大膽的,大膽的黛米等

相關問題