What is CSS ?

Resources and Magazine

Setting Fonts with CSS

Setting Fonts with CSS

In HTML, if you want to change the used in an element you would use the element.  This could make your code very messy if you had the same that you want to use multiple  times, but not make the the same on the whole page. Also, if you wanted to make a  bold, italic, or underlined you would need to use the correct element to do so. If needing to make some text that was red, size 12, bold, underlined, and italic the code you use may look something like this in HTML.

This is a test

With CSS, we can do the same thing. In addition to these options, CSS allows us more  control over the that is on the site. CSS will also make it easier for us to change the in the future if we choose to use a different theme for the site we are coding for, and make it easier to read and follow.

p { : italic bold 12px arial;
 color: red;
 text-decoration: underline;
}

The CSS above will do the same as the HTML code that we looked at. By using the attribute, we have told CSS to make all paragraph elements use the Arial , make the text 12 pixels tall, make the bold, and italic. We use the color attribute to change the color of the text, and the text-decoration to underline the text. Now if we wanted to change the color of the text, or the size we can do it in one place instead of having to manually edit each element.

There are some additional attributes we can set using the attribute. Above we used the generic attribute to set a variety of settings. If we did not want to make the array of changes that we did we can use other attributes, like -family. Below are the different attributes, what they do, and what values can be assigned to them.

The attribute allows you to declare multiple settings in one attribute. This is a short hand way of setting the values.

-Family

The family sets the type of that is going to be used. This is similar to the HTML  face attribute for the element. The family attribute allows you to set a roup of fonts that the site should use if the user has them installed. You can use any that you would like, but it is best to use fonts that most people will have, like Arial, Times New Roman, or Courier. You could also use a generic family, like sans-serif. A generic  will use the default for that family. Here is an example of the family attribute.

-family: courier, arial, sans-serif;

In the example, the browser will try to use the Courier first if the user has it, if not then it will try to use Arial. If the user does not have any of those fonts, then the browser will use the default for the sans-serif family of fonts. It is always best to use a generic at the end of a family attribute, this allows you a little more control over how the text will look.

Size

size attribute does as it names suggests. It changes the size of the . There are some built in sizes that this attribute can use. Those are:

  • xx-small
  • x-small
  • small
  • medium
  • large
  • x-large
  • xx-large
  • smaller
  • larger
  • length

Along with these you can also declare what size of you want to use, such as 12px. This will make the 12 pixels high. You can use pixels (px), points (pt), percentage of the parent size (%), and ems (em) as measurements for the size of the .

Size Adjust

This adjusted the size for an element based on the ’s aspect value. The aspect value is the ratio of the ’s lowercase x size in relationship with the size. To use this attribute you would just put in the aspect value. Here is an example:

h2 { -size-adjust: 0.58 }

Stretch

The stretch attribute stretches or condenses the horizontally only. Below is a  of options that can be used with the attribute.

  • wider
  • narrower
  • ultra-condensed
  • extra-condensed
  • condensed
  • semi-condensed
  • semi-expanded
  • expanded
  • extra-expanded
  • ultra-expanded

Style

style only has three options that can be used with it. These set the style of the  that is being used. The values that can be used are italic, oblique, and normal. Normal  is the default value, and does not make any changes to the text. Italic, will make the  italic, and oblique looks similar to italic.

Variant

This attribute only has two values. One value is normal and it is the default value, the other is small-caps. The small-caps value makes all lowercase letters look like their uppercase versions, but the same height as the lowercase letters. Below is an example of how the small-caps value looks.

This is an example of the small-caps value

-Weight

The -weight attribute sets how bold text is on the site. You can use the values bold, bolder, lighter, and normal. You may also use any hundred value between 100 and 900.

Tags: ,

List

can be very useful to a website. By using some CSS, you can create a nice frequently asked questions page for your site, or even a menu for your site. Let us look at some of the additional controls that CSS gives us with .

-Style

-style is the shorthand way of setting all the attributes for a .

-Style-Image

The -style-image allows you to use your own image as the bullet in a . To use this attribute you have to define where the image is located at. Below is an example of what the attribute would look like.

-style-image: url(’list_dot.gif’)

-Style-Position

This attribute defines where the bullets will be displayed. The best way I can describe how this attribute works is to imagine a line when you create a . This attribute determines what side of the line the bullets at on. If you set the attribute value to inside, then the bullets are on the right of the line. The only other value that can be set is outside, and this sets the bullets on the left side of the line.

-Style-Type

-style-type attribute allows you to change the style of the bullets in your to some of the additional bullet styles that are “built” into CSS. There are multiple values that you can use. Below is a of each one.

  • None
  • Disc
  • Circle
  • Square
  • Decimal
  • Decimal-Leading-zero
  • Lower-Roman
  • Upper-Roman
  • Lower-Alpha
  • Upper-Alpha
  • Lower-Greek
  • Lower-Latin
  • Upper-Latin
  • Hebrew
  • Armenian
  • Georgian
  • CJK-Ideographic
  • Hiragana
  • Katakana
  • Hiragana-Iroha
  • Katakana-iroha
Tags:

Media Types

Media Types

With CSS, you can also control how your website looks on other media. Most sites only have a style sheet that controls the way the site looks on a monitor, since that is where most of the people who visit the site will see it, but there are other media that you can control also.

Aural

With Aural you can configure your site to work with speech applications. This is for those visitors who may have issues with the visual layout of a site. With the aural style sheet you can control the volume of the speech application, what is actual read on the site, and the speed that the text is read.

Braille

A braille style sheet is used for braille tactile feedback devices.

Embossed

Similar to braille, embossed controls the styles on printers that can print in braille.

Handheld

This is a that will become more popular as portable devices start connecting to the world wide web more often. Handheld is designed to control the look of your site on portable, monochrome, and small screen devices. These devices are similar to most smart cell phones.

Print

The print will allow you to control how your site looks on paper. Most sites have a print button on them, and then the site will use a different style sheet that will make the site look better on paper.

Projection

If you ever have a site that you would like to use in a presentation, then you would use the projection .

Screen

Screen is the most used . This is the type that controls how the site looks on a computer screen.

TTY

This is used for fixed-pitch character grid devices, like a teletype or terminals. These devices are designed to input or output one character at a time.

TV

The TV , is used on larger monitors or televisions.

There are a few different ways to declare what to use. You can create different sheets for each , then include them in your header like this.

< rel=”stylesheet” type=”text/css” href=”css/print_style.css”  media=”print” >
< rel=”stylesheet” type=”text/css” href=”css/screen_style.css” media=”screen” >
< rel=”stylesheet” type=”text/css” href=”css/handheld_style.css”  media=”handheld” >
< rel=”stylesheet” type=”text/css” href=”css/print_style.css”  media=”print” >
< rel=”stylesheet” type=”text/css” href=”css/screen_style.css”  media=”screen” >
< rel=”stylesheet” type=”text/css” href=”css/handheld_style.css” media=”handheld” >

Also, each can be declared inside a single style sheet. When needing to switch to a different , just use @media followed by the , ie @media print.

The last way to declare a is within the style element of the page. This works just like declaring the inside the style sheet, just use @media followed by the
.

code-sucks.com
 

Tags: ,