Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

CSS example

CSS example

CSS Background

Set the background color of the page

Set the background color of different elements

Set an image as the background of the page

A poor background image

How to repeat a background image horizontally

How to position a background image

A fixed background image (this image does not scroll with the rest of the page)

Declare background properties

Advanced background example

Explanation of background properties

CSS Text

Set the text color of different elements

Text Alignment

Remove the underline from links

Decorate text

Control the letters in text

Indented text

Specify the space between characters

Specify the space between lines

Set the text direction of an element

Increase the space between words

Disable text wrapping within an element

Vertical alignment of inline text and images

 

Explanation of Text Properties

CSS Fonts

Set the font of text

Set the font size

Set the font size using px

Set the font size using em

Set the font size using percentages and em

Set the font style

Set the font variant

Set the font weight

All font properties in a single declaration

 

Explanation of Font Properties

CSS Links

Add different colors to visited/unvisited links

Use text decoration on links

Specify the background color of links

Add other styles to hyperlinks

Advanced - Create a link box

 

Explanation of Link Properties

CSS Lists

All different list item markers in a list

Set an image as the list item marker

Set a list item marker image using a cross-browser solution

All list properties in a single declaration

CSS: Remove the default style of list item li

 

Explanation of List Properties

CSS Tables

Specify Th and TD elements and a black border for a table

Use border-collapse

Specify the width and height of a table

Set the horizontal alignment of content (text alignment)

Set the vertical alignment of content (vertical alignment)

Specify the padding of TH and TD elements

Specify the color of table borders

Set the position of the table caption

Create a fancy table

 

Explanation of Table Properties

CSS Box Model

Specify a total element width of 250 pixels

Specify a total element width of 250 pixels using a cross-browser solution

 

Explanation of the Box Model

CSS Border

Set the width of all four borders

Set the width of the top border

Set the width of the bottom border

Setting the Width of the Left Border

Set the width of the right border

 

Set the style of all four borders

Set the style of the top border

Setting the Style of the Bottom Border

Set the style of the left border

Set the style of the right border

 

Setting the Colors of All Four Borders

Set the color of the top border

Set the color of the bottom border

Set the color of the left border

Setting the Color of the Right Border

 

All border properties in a single declaration

 

Set a different border on each side

All top border properties in a single declaration

All bottom border properties in a single declaration

All left border properties in a single declaration

All right border properties in a single declaration

 

Explanation of Border Properties

CSS Outline

Draw a line around an element (outline)

Set the style of the outline

Set the outline color

Set the width of the outline

 

Explanation of outline properties

CSS Margins

Specify the margins of an element

Margin shorthand property

Set the top margin of text using a value in centimeters

Set the bottom margin of text using a percentage value

Set the left margin of text using a value in centimeters

 

Explanation of the Margin property

CSS Padding

Set the left padding of an element

Set the right padding of an element

Sets the top padding of an element.

Set the bottom padding of an element

All padding properties in a single declaration

 

Explanation of the padding property

CSS Grouping and Nesting

Group selector

Nested selector

 

Explanation of grouping and nesting

CSS Dimensions

Set the height of an image using a pixel value

Set the height of an image using a percentage

Setting the Width of an Element Using Pixels

Set the width of an element using a percentage

Sets the maximum height of an element.

Set the maximum width of an element using a pixel value

Setting the Maximum Width of an Element Using a Percentage

Setting the Minimum Height of an Element

Set the minimum width of an element using a pixel value

Set the minimum width of an element using a percentage

 

Explanation of dimension properties

CSS Display

How to hide an element (visibility:hidden)

How to not display an element (display:none)

How to display an element as an inline element

How to display an element as a block element

How to use the collapse property for tables

 

Explanation of the Display property

CSS Positioning

The position of an element relative to the browser window

Relative positioning of an element

Absolute positioning of an element

Overlapping elements

Set the shape of an element

How to use scrollbars to display overflowing content within an element

How to set the browser to handle overflow automatically

Set the top of an image using a pixel value

Set the bottom of an image using a pixel value

Set the left of an image using a pixel value

Set the right of an image using a pixel value

Change the cursor

 

Explanation of positioning properties

CSS Float

Simple use of the float property

Add a border and margin to an image and float it to the left of a paragraph

Float headings and images to the right

Float the first letter of a paragraph to the left

Create an image gallery using the float property

Enabling float - the clear property

Create a horizontal menu

Create a webpage without tables

 

Explanation of the Float property

CSS Aligning Elements

Center alignment using margin

Left/right position alignment

Set left/right position alignment using a cross-browser solution

Left/right alignment with float

Set left/right alignment with float using a cross-browser solution

 

Explanation of alignment properties

CSS Generated Content

Insert the URL in parentheses after each link using the content property

Numbering of chapters and sections such as "Section 1", "1.1", "1.2", etc.

The quotes property specifies the quotation marks

CSS Pseudo-classes

Add different colors to hyperlinks

Add other styles to hyperlinks

Using :focus

:first-child - matches the first p element

:first-child - matches the first i element within a p element

:first-child - matches all i elements within the first p element

Using :lang

 

Explanation of pseudo-classes

CSS Pseudo-elements

Set the first letter of text as a special letter

Set the first line of text as special

Set the first letter of the first line of text as special

Using :before to insert some content before an element

Using :after to insert some content after an element

 

Explanation of pseudo-elements

CSS Navigation Bar

Full styling of a vertical navigation bar

Full styling of a horizontal navigation bar

 

Explanation of the navigation bar

CSS Image Gallery

Image gallery

 

Explanation of the image gallery

CSS Image Opacity

Create a transparent image - mouse hover effect

Create a transparent box with a background image and text

 

Explanation of image opacity

CSS Image Sprites

Image sprites

Image sprites - navigation list

Hover effects with image sprites

 

Explanation of image sprites

CSS Attribute Selectors

Select elements with a title attribute

Select elements with title="a specific value"

Select elements with a specific title value (using ~ to separate attribute and value)

Select elements with a specific title value (using | to separate attribute and value)

 

Explanation of attribute selectors


CSS Application Examples

More examples:https://www.jyshare.com/examples/