I have a file (CSS/FontStyle.css) containing this code:
.courier { font-family: courier; }
and my .aspx file has this code:
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Tut1.aspx.cs" Inherits="Rtw.Tut1" %> <asp:Content ID="Content1" ContentPlaceHolderID="StatusLabel" runat="server"> </asp:Content> <asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server"> <link rel="stylesheet" href="CSS/FontStyle.css"/> <h2>Unsigned Vs Signed Integers</h2> //lots of text is below here..
However the font remains in time new roman. I can use other .css files from the same folder find, not sure why this one doesn't work?
thanks in advance.
Simple styling options let you change a web page's font using Cascading Style Sheets. Use CSS to set the font of individual words, specific sentences, headlines, whole paragraphs, and even entire pages of text.
To change font size in HTML, use the CSS font-size property. Set it to the value you want and place it inside a style attribute. Then add this style attribute to an HTML element, like a paragraph, heading, button, or span tag.
Go to Format > Font > Font. + D to open the Font dialog box. Select the font and size you want to use. Select Default, and then select Yes.
Two options there: use @font-face if your font is free of use as a downloadable font or add fallback(s): a second, a third, etc and finally a default family (sans-serif, cursive (*), monospace or serif). The first of the list that exists on the OS of the user will be used.
Try changing
.courier { font-family: courier; }
to
* { font-family: courier; }
The reason is the same as what @koala_dev mentioned. The ".courier" makes it apply only to elements of the class "courier," and from the code that you show none of your content is labeled with that class name, so the font is not being applied.
The *
selector, however, will apply the CSS font-family rule to the text of all elements.
Note that CSS uses a specificity priority, and if you have any other CSS selectors that apply to the same elements, but with a more specific identifier than *
, then any font-family specified in those CSS rules will override the general rule specified by the *
selector.
If you can't find what other CSS rule may be conflicting, then you can use the !important
rule to override other rules (unless those other rules are also using it):
* { font-family: courier !important }
Using !important
is considered bad practice, however, but is useful possibly in your case where the conflicting CSS rule seems to be lost and you just need something that works.
What !important
does is interfere with CSS's usual "cascading" rules for priority. As an example, the h2
element would have the font-family courier in the below exam, even though the usual result would be arial (because of the more specific selector). The more specific selector h2
is overridden by the less specific selector *
because the *
rule has the !important
predicate applied to it.
* { font-family: courier !important } h2 { font-family: arial }
For more info, please read this except and continue reading at the link that follows:
... postscripting your CSS values with !important can be highly abused and make for messy and hard to maintain CSS. The unfortunate typical use case goes like this:
- WHY IS MY FRAGGLE ROCKING CSS NOT WORKING?!?!
- (use !important rule)
- OK, now it's working
Then the next guy comes along and tries to make new changes. He tries to alter some existing CSS rules, but now his changes aren't behaving how they should. He traces the issue back to the !important rules, then has a choice. He can try and remove those and attempt to get things back on track, or add some more of his own to fight them and get his change done. Since he might not know exactly why those !important rules were added in the first place, he might opt for the second option for fear of breaking something somewhere else on the site he's not aware of. And thus the vicious cycle starts.
Continue reading here: http://css-tricks.com/when-using-important-is-the-right-choice/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With