문제

간단히 말해서 글로벌 스타일 시트가 있습니다.

a { font-family: Arial; }

특정 링크에 다른 글꼴 제품군을 사용하고 싶습니다.

<a href="..." style="font-family: Helvetica;">...</a>

또는

<span style="font-family: Helvetica;"><a href="...">...</a></span>

그러나 아무것도 작동하지 않습니다. 이 작업을 수행하는 쉬운 방법이 있습니까?

추신 : 나는 동적으로 (PHP를 통해) 다른 글꼴을 다른 링크에 할당하므로 특수 클래스를 만드는 것은 옵션이 아닙니다.

도움이 되었습니까?

해결책

Unless you have a specific font named Helvetica, you should realise that on some platforms (such as Windows, via FontSubstitutes), Helvetica is aliased to Arial. That might be the source of the problem. Try another font and see.

다른 팁

Your first attempt

  <a href="..." style="font-family: Helvetica;">...</a>

should have worked. Agree that you're probably missing a font. Inline styles have precedence over any other styles beside a user-defined style sheet. Here's the order of priorities for style definitions:

  1. User defined style
  2. Embedded or inline style sheet
  3. Internal style sheet
  4. External style sheet
  5. Browser default style

Within a style sheet the priorities are as follows:

  1. Anything marked !important
  2. id

  3. .class
  4. element

In addition, you have the rule of greater specificity: div a overrides a.

Here's a good article with more detail on the subject.

@Kip's suggestion is your best bet.

What you've written should work, unless the problem is what Chris pointed out,

When you get a pair of fonts for which this works correctly, you might consider that a better way of doing this would be to declare a class for the special links that somehow reminds yourself of why they need a separate font (maybe because you want them to be especially noticed?)

a { font-family: Arial; }
a .noticed { font-family: Helvetica; }

Then in HTML:

<a class="noticed" href="...">...</a>

Changing the font by creating a span tag around the link, or adding inline style to the link just smacks of the old days of <font> tags.

element styles override global styles, so Chris Jester-Young is probably right and you don't actually have a Helvetica font; try a different font e.g. Courier or Times New Roman that you're certain exists

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top