The problem described is not caused by the code posted, i.e. the cause is in the part of code that was not disclosed. Generally, setting e.g. font-family
on an element affects as such only the text directly in the element, not text wrapped in an inner element. However, if there is no CSS rule (in author, user, or browser style sheets in use) for an inner element, then an inner element inherits font-family
from its parent. But in this case there apparently is a CSS rule that sets font-family
on the a
element.
The fix depends on what other CSS code is used. This does not seem to be a real-life case but just as an exercise, so it’s better to use a different approach, e.g.
<div class="foobar"> Hello world! <a href="www.google.com"> Click here! </a> </div>
with the following CSS code in a linked external style sheet or within a style
element on the page:
.foobar, .foobar a { font-family: 'Times New Roman', Times, serif }
Replace foobar
by a name that reflects the meaning or role of the element, just to make the code more readable to humans.
However, depending on the other CSS code that sets font-family
on the a
element now, you may need to use a more specific selector, or the !important
specifier, or both.