CSS: Tips and Tricks

- Read Article
You have already learned HTML, and you have heard that Cascading Style Sheets (or CSS) is used for styling pages, but haven’t yet learned CSS. Take a minute to learn the basics (the very basics) of CSS.
- Read Article
External style sheets are created in separate documents with a .css extension. An external style sheet is simply a listing of CSS rules. It cannot contain HTML tags. The
<link>
tag, which goes in the head of an HTML page, is used to link to an external style sheet. There is no limit to the number of external style sheets a single HTML page can use. Also, external style sheets can be combined with embedded style sheets. Follow these steps to create an external style sheet. - Read Article
Aligning text in CSS can be achieved using the
text-align
property or thevertical-align
property. - Read Article
In this how to, you'll learn how to create a horizontal navigation menu.
- Read Article
A "fixed-width" layout is one in which the layout of the page is contained within a wrapper that doesn't adjust its size when the width of the browser changes. In this how to, you'll learn how to create a 2-column fixed-width layout.
- Read Article
When you use CSS to put a border on your
<th>
and<td>
tags, you will notice that you get space between them. In the old days, you would remove that space using the now-deprecatedcellspacing
attribute. These days, you do it with the CSSborder-collapse
property. - Read Article
You can set background images in CSS using the
background-image
and several other properties to control the behavior of the image. - Read Article
Text spacing and placement in CSS is controlled using the
letter-spacing
,word-spacing
,line-height
, andtext-indent
properties. Learn how to set text spacing and placement in the following steps. - Read Article
Back before CSS, people used HTML tables to lay out web pages. The rule is the same now as it was then: tables should not be used to lay out pages. They should be used for tabular data, such as financial reports or a meeting agenda. To style tables with CSS, you should first be familiar with HTML table syntax.
- Read Article
Prior to browser support for CSS3, creating boxes with rounded corners required the creative use of background images, borders, and positioning. Thankfully, these days are gone. Today, browsers support CSS3 and its
border-radius
properties. Theborder-radius
properties makes rounding the corners on a box easy. - Read Article
In this how-to, you'll learn how to create a vertical navigation menu.
- Read Article
CSS3's opacity property makes it easy to change the opacity of images, text,
<div> s, and other elements. Where before we might have resorted to images with a semitransparent alpha setting, we can now change the opacity via CSS. Even better, we can change opacity more easily with:hover
to create rollover effects. Let's look at an example: - Read Article
CSS3 offers the ability to include multiple background images for a given element - use a comma-delimited list to specify as many as you like:
The order of the listed background images determines the position of the layer relative to the viewer, akin to the CSSbackground-image:url(img1.gif), url(img2.png), url(img3.gif)
z-index
property: the first background image is on "top", the next below that, etc. - Read Article
When elements are positioned absolutely, they are removed from the normal flow. As a result, they do not affect the positioning of subsequent sibling elements. Learn how to use absolute positioning in the following steps.
- Read Article
Shorthand properties can take multiple values, allow you to write less code, and provide smaller files for the user to download. Find out how to use the CSS
border
shorthand property in these steps. - Read Article
You can use CSS pseudo-classes to create CSS buttons. Before CSS, you needed images to create links that looked like buttons.
- Read Article
Pages that are designed to use the full width of the browser are often described as having a "fluid" or "liquid" layout. That's because one or more of the columns must be automatically resized according to the size of the browser window. In this how to, you'll learn how to create a fluid-width layout.
- Read Article
The
color
andbackground-color
properties determine how color is set in CSS. - Read Article
Embedded style sheets appear in the style element in the head of an HTML page. Follow these 10 steps to create a CSS embedded style sheet.
- Read Article
Inline styles are created by adding the
style
attribute to a tag. As with theclass
andid
attributes, almost all elements can take thestyle
attribute. (Exceptions includehtml
,head
,title
,meta
,script
, andstyle
.) The value of thestyle
attribute is a list of one or more property-value pairs separated by semicolons. Learn how to add inline styles to CSS in these six steps. - Read Article
Three properties work together to make borders:
border-style
,border-color
, andborder-width
. In addition, each side of an element can also have a different border style. These are indicated by the following properties:- border-top
- border-right
- border-bottom
- border-left
Learn how to use these CSS properties to add a border to an element by following the steps below.
- Read Article
Shorthand properties can take multiple values, allow you to write less code, and provide smaller files for the user to download. Find out how to use the CSS padding property as well as the
margin
property in these steps. - Read Article
In this how to, you'll learn how to create a fly-out menu with CSS.
- Read Article
Setting up a slide show to repeat automatically is useful in situations where the audience may view it at different times. You can set up a slide show to repeat automatically in PowerPoint in just five easy steps.
- Read Article
The
margin
property is used to specify the margin around an element. It can be applied to both block and inline elements. Margins can be specified in number of units (e.g.,20px
) or in percentage of the width of the containing element. Learn how to adjust margins with CSS below. - Read Article
The
background
property is used to set the individual properties for background-color,background-image
,background-repeat
,background-attachment
, andbackground-position
. Note that order matters (although some browsers may show some leniency). Learn how to use the CSSbackground
shorthand property in the following steps. - Read Article
By using CSS to apply styles to the form, fieldset, and legend elements, you can layout a form without using tables. Here's how to do it.
- Read Article
In the past, we used the HTML tag to change font family, size, and other attributes. CSS makes it much easier. Learn how to modify font family and font size using CSS in the following steps.
- Read Article
In this how-to, you'll learn how to create a drop-down menu with CSS.
- Read Article
The
padding
property is used to specify the padding between an element's edges and its content. It can be applied to both block and inline elements. Padding can be specified in number of units (e.g.,20px
) or in percentage of the width of the containing element. Learn how to apply padding with CSS below. - Read Article
Elements with fixed positioning stay in the same position in the browser window even when the page is scrolled. It can be used to keep an element (e.g., a navigation menu) on the page at all times. Learn how to use fixed positioning in the following steps.
- Read Article
The CSS3 transition property defines how an element changes from one state to another. With transition—or the specific properties listed below, for which transition serves as a shorthand—we can stretch out the change on an element's width, background color, or other property over a specified duration. You have to include appropriate vendor prefixes for transitions: -moz- for older version of Firefox, webkit for older versions of Chrome/Safari, and -o- for older versions of Opera. Internet Explorer supports CSS transitions, unprefixed, from version 10+.
- Read Article
Shorthand properties are CSS properties that can take multiple values, with each value relating to a different regular CSS property. Values in shorthand properties are separated by spaces, as shown below.
- Read Article
Changing text style in CSS is achieved using the
text-decoration
andtext-transform
properties. Thetext-decoration
property is used to add effects to text, such as underlines and line-throughs. Thetext-transform
property is used to change the capitalization of text. - Read Article
A CSS sprite is an image file that contains several graphics used on a web page. By showing different parts of the sprite in different locations, it appears that there are several different images, but they are all contained in a single file, which translates to a single download. In this How-To, you'll learn how to create a grid of images by using a sprite.
- Read Article
Styles can be defined for different media. For example, you may want to style a page one way for viewing with a browser and a different way for viewing in print. The media type is defined in the
<link>
tag for external style sheets and in the<style>
tag for embedded style sheets. - Read Article
The
@import
rule in CSS is used to import one style sheet into another. - Read Article
The
white-space
property determines how sequences of whitespace are displayed. You can learn how to use the CSSwhite-space
property in just a few steps. - Read Article
The
z-index
property specifies the stack level of an element on the page compared to other elements in its same flow. Learn how to use thez-index
property in the following steps. - Read Article
With the
box-shadow
property, we can attach a drop shadow to an element. In this brief article, we show how.