官术网_书友最值得收藏!

  • Joomla! 1.5 Multimedia
  • Allan Walker
  • 2058字
  • 2021-08-20 16:23:47

Joomla! Templates and Cascading Style Sheets

Before we launch into adjusting our Joomla! CSS font, it is important to include a brief introduction regarding Joomla! Templates.

What is a Joomla! Template?

A Joomla! Template is a set of files which control the presentation of your website content. Templates are packaged with a "formal file structure", meaning that they have certain requirements in order to work with Joomla! Each Template file plays a vital part in producing your final website design, its structure, and your site pages' interactive features.

Joomla! Templates are usually packaged up in a zipped format and installed using the built-in Joomla! upload / unzip feature. They come in all shapes and sizes and are designed in such a way that when they are installed and activated, they will display your Joomla! content with their designated structure and design:

Using templates has a number of benefits, including:

  • A new template can be applied instantly to your website content. This flexibility means a completely different design may be given to your website with little effort.
  • Multiple styles can be applied to your website by using a number of templates. If you are looking to provide different design layouts to different areas of your CMS, then this is an important feature.
  • The template contains all CSS and website styling. This is all self-contained and can include overrides. By going into your "Templates area", you can easily make adjustments to your current template, and include custom changes into this folder, protecting the "Core Joomla! Framework".

An important styling element of a Joomla! Template is the CSS. These .css files contain important layout and style information, which contributes to your Joomla! website design.

Template CSS

Cascading Style Sheets are a web developer's best friend! They provide us with the opportunity to be completely consistent with our site styling, and provide additional layout and design options than plain HTML usage can offer.

Before CSS was used, nearly all of the styling in an HTML document was contained in the HTML code. Color, layout, styling, fonts, among others had to be specifically listed in the code, often repeatedly throughout the HTML document:

<html>
<body>
<p><font size="2" face="Verdana">
This is a paragraph of text.
</font></p>
<p><font size="5" face="Times" color="red">
This is another paragraph.
</font></p>
</body>
</html>

Here text is styled using an older HTML method, where the styling is within the HTML code.

By using a CSS method, it allows us to put most of this styling information into a separate document (.css file). This information can be referenced in the HTML easily, resulting in a more efficient process and considerably simpler HTML code.

The HTML code is as follows:

<html>
<body>
<p>This is a paragraph of text.<p>
</body>
</html>

The CSS code is as follows:

p {
font-family:Helvetica ,Arial,sans-serif;
font-size: 1em;
color: #000000;
text-align: left;
width: 100%;
}

The previous HTML and CSS code shows the styling of a p tag.

CSS information can be embedded into the HTML document, but for a Joomla! Template it is usually included in a separate document. Quite often Joomla! Templates contain multiple CSS files to separate the design elements. When using CSS, a separate stylesheet for a handheld device may be used to accommodate the smaller screen resolution, a custom stylesheet could be used just for the Internet Explorer 6 browser, and so on. Your Joomla! Template can contain coding to tell the browser what stylesheet to load in, depending on what type of appliance the user is viewing your website with.

The Joomla! Template CSS file is usually located in the following directory /templates/yourtemplate/css/template.css. If you are using a pre-built Joomla! Template, you may see multiple CSS files inside the CSS directory. It is important to note that the names of these CSS files may differ between Joomla! Templates, but the template.css file is the standard naming convention for the main CSS file. Certain WYSIWYG editors rely on this naming convention to work correctly.

We could devote a whole book to the complexities of CSS. For this chapter, however, we are just going to highlight the font property, and its available values.

CSS font properties

Let's take a look at the numerous properties we can manipulate the text with when using CSS:

Font family

The font family property is a prioritized list of font names for an element. It is possible (and good practice) to specify more than one font typeface in case the user does not have the font you are specifying loaded on their computer system. In CSS, your browser will use the first font that it recognizes; hence we always list our font families in a priority order:

body {
font-family: Arial,Courier,sans-serif;
line-height: 1.3em;
margin: 0px;
font-size: 12px;
color: #333;
}

In the previous example, the font Arial will be used ahead of the font Courier.

There are two types of font-family values:

  1. Family Name

    The name of the font typeface. For example: Helvetica, Courier, Arial.

  2. Generic Family

    The name of one of the five generic font categories. For example, serif, sans-serif, and so on.

In a Joomla! Template CSS file, the font family is usually applied to the body tag. This specifies a main font to be used for your website body text. If you require additional styling to other Joomla! text elements, then we define those accordingly using further CSS.

body {
font-family: Arial,Helvetica,sans-serif;
}

In the previous example, the browser will look for the font Arial, then Helvetica, and if for some unknown reason the user didn't have those fonts installed on their computer device, then the browser would substitute an available sans-serif font to use.

Where you use font families having more than one word in the name, it is important to surround these font names with double quote marks. While some browsers can read these fonts without the quote marks, problems can occur if the white space in between the words is considered or ignored.

body {
font-family: Arial,"Times New Roman",sans-serif;
}

Note the Times New Roman in quotation marks.

Font size

The font size property in CSS sets the size of your text. Font sizing methods that you can utilize in CSS can either be of absolute (fixed), or relative size.

  1. Absolute:
    • Sets the text to a specific size
    • Absolute sizing is useful if a fixed output or container is known. Using this method you can get the text to sit exactly as you wish into that defined area.
    • Does not allow the user to adjust the text sizing in some browsers. For this reason it is considered poor for accessibility.
  2. Relative:
    • Allows the user to change their text size in all browsers.
    • The font size is based off the default font setting in the browser. The user can change this default value if they wish.
    • Sets a size of the text that is relative to the surrounding elements.

The debate regarding which method to use is as on-going as which font typeface is best for the screen. Specifying in pt or px (absolute methods) has been classified as non-W3C accessible, but allows you to style text in a confined container with more design control. If the layout of your text is important, then you may require this styling method to align your text as you wish.

If text can just spill out on the page and be resized by the user if required, then relative is the preferred and accessible method of managing font size. Relative sizing can be done using em measurement or % (percent).

As a general rule:

1em = 16px = 12pt = 100%
Meet the units

In CSS there are four different units with which we can measure the size of the text as it is displayed in the web browser.

Setting the text size using em

To cater for all browsers and retain accessibility standards on your website, most designers are trying to adopt the em relative text sizing method. This is the preferred text resizing method by the W3C standards.

The way em sizing works is: 1em is equal to the current font size of the element in question. If you have not set a font size in other areas of your CSS, then it will take the user's default browser font size. The default text size in browsers is 16px, and usually a font such as Arial font or Times. This means the default size of 1em = 16px. If you were to set a font size for the body, say 18px, then 1em = 18px.

For general body text, you may see something similar to this Joomla! CSS file:

body {
font-family: Helvetica,Arial,sans-serif;
line-height: 1.3em;
margin: 0px 0px 0px 0px;
font-size: 12px;
color: #333;
}

Once the main body text font size has been specified, as in the previous example, other text elements in your CSS can then be set relative to this using em's:

h2, .contentheading {
padding: 0;
font-family: Arial, Helvetica,sans-serif;
font-size: 1.4em;
font-weight: normal;
vertical-align: bottom;
color: #333;
text-align: left;
width: 100%;
}
Setting the text size using percent

Sizing using percentages works, as you would probably expect a percentage to work. Just like em's, using a percentage styling method is relative.

If the parent item has a font size of 24px, and the child has a percentage of 50%, then it will be displayed with font size of 12px.

Just like em's , one popular technique for sizing using percentages is to set a parent font size on the body of your CSS, and then use percentages for all other styling. Everything will be relative to that one parent size which is set:

.tool-text {
font-size: 95%;
margin: 0;
}
Setting the text size using pixels

Pixels are fixed size units that are used in screen media. One pixel is equal to one dot on your screen and when using pixels to size your text you are telling the browsers to render the text exactly that number of pixels high. Using pixels to define our text size provides us with excellent control over the size and layout of the text. Using pixels, however, does not allow the ability to scale upwards for visually impaired users, nor scale downwards for mobile devices.

Sizing your text using pixels will allow browsers such as Firefox and Safari to still retain some text control, but when viewing with Internet Explorer 6 the user will not be able to resize this absolute styled text. All in all, setting font sizes with px is an accurate method, but do take into consideration the IE 6 lack of accessibility.

Setting the text size using points

The unit of points (pt) is usually associated with print media. Points are much like pixels in that they are of fixed size and cannot be scaled to size. Just like pixels are accurate for screen resolutions, points are accurate on paper.

72pts = one inch

It is not good practice to use pt styling for your Joomla! Template CSS, but it would be good to use points when creating a separate print.css stylesheet.

An example of print CSS may look like:

body {
color : #000000;
background : #ffffff;
font-family : "Times New Roman", Times, serif;
font-size : 12pt;
}
Font style

The "font style" property sets the style of your specified fonts.

The values are:

  • Normal

    The browser will display a normal font style

  • Italic

    The browser will display an italic font

  • Oblique

    The browser will display an oblique font

When written down in the CSS, the font-style property may look like this:

body {
font-style: italic;
}
Font weight

The font weight property sets the width of the font. For example, how thick or thin the text should be displayed.

The values are:

  • Normal

    Defines normal characters

  • Bold

    Defines thick characters

  • Bolder

    Defines thicker characters

  • Lighter

    Defines lighter characters

You can also use the values: 100-900.

This method defines thick to thin characters and offers a further level of control. As an indication, the value 400 is the same as normal, and the value 700 is the same as bold.

p
{
font-weight: bold;
}

Using CSS, it is possible to define each of the font properties within your document, or you can define all of the values into one shorthand property. This is called simply font.

The "font" property in CSS can include the "line-height" value. This element allows you to set the space between the text lines:

p
{
font: italic bold 900 12px/14px arial;
}
主站蜘蛛池模板: 浦江县| 呼玛县| 武定县| 荆门市| 泉州市| 松溪县| 余江县| 来安县| 盐山县| 曲阳县| 任丘市| 潮州市| 马鞍山市| 连云港市| 西宁市| 简阳市| 德安县| 钟祥市| 深水埗区| 常宁市| 天津市| 始兴县| 太保市| 荣成市| 西乌珠穆沁旗| 旺苍县| 瑞昌市| 阳山县| 兰州市| 余姚市| 长汀县| 永安市| 固原市| 泰兴市| 博兴县| 武陟县| 玛纳斯县| 天长市| 瓦房店市| 涟源市| 莱芜市|