Welcome Guest, Not a member yet? Create Account  


HTML Styles - CSS

#1
Lightbulb 

HTML Styles - CSS




CSS = Styles and Colors
Manipulate Text
Colors,  Boxes



Styling HTML with CSS
CSS stands for Cascading Style Sheets.
CSS describes how HTML elements are to be displayed on screen, paper, or in other media.
CSS saves a lot of work. It can control the layout of multiple web pages all at once.
CSS can be added to HTML elements in 3 ways:
  • Inline - by using the style attribute in HTML elements



  • Internal - by using a 
    <style>

  • [size=undefined]
     element in the [/size]

  • <head>


  • [size=undefined]
     section[/size]

  • [size=undefined]External - by using an external CSS file[/size]
Example

<!DOCTYPE html>
<html>
<head>
<style>
h1 {
    color: blue;
    font-family: verdana;
    font-size: 300%;
}
p  {
    color: red;
    font-family: courier;
    font-size: 160%;
}
</style>
</head>
<body>

<h1>This is a heading</h1>
<p>This is a paragraph.</p>

</body>
</html>




CSS Border

The CSS 



border

[size=undefined]
 property defines a border around an HTML element:[/size]

Example
{
    border: 1px solid powderblue;
}



CSS Padding

The CSS 



padding

[size=undefined]
 property defines a padding (space) between the text and the border:[/size]

Example
{
    border: 1px solid powderblue;
    padding: 30px;
}



CSS Margin

The CSS 



margin

[size=undefined]
 property defines a margin (space) outside the border:[/size]

Example
{
    border: 1px solid powderblue;
    margin: 50px;
}



The id Attribute

To define a specific style for one special element, add an 



id

[size=undefined]
 attribute to the element:[/size]

<p id="p01">I am different</p>

then define a style for the element with the specific id:

Example
#p01 {
    color: blue;
}



Note: The id of an element should be unique within a page, so the id selector is used to select one unique element!



The class Attribute

To define a style for special types of elements, add a 



class

[size=undefined]
 attribute to the element:[/size]


<p class="error">I am different</p>

then define a style for the elements with the specific class:
Example
p.error {
    color: red;
}



External References

External style sheets can be referenced with a full URL or with a path relative to the current web page.

This example uses a full URL to link to a style sheet:

Example
<link rel="stylesheet" href="https://www.w3schools.com/html/styles.css">
Try it Yourself »


This example links to a style sheet located in the html folder on the current web site:
Example
<link rel="stylesheet" href="/html/styles.css">




This example links to a style sheet located in the same folder as the current page:

Example
<link rel="stylesheet" href="styles.css">
Try it Yourself »


You can read more about file paths in the chapter HTML File Paths.



Chapter Summary
  • Use the HTML 



  • style



  • [size=undefined]
     attribute for inline styling[/size]

  • [size=undefined]Use the HTML [/size]

  • <style>



  • [size=undefined]
     element to define internal CSS[/size]

  • [size=undefined]Use the HTML [/size]
  • <link>



  • [size=undefined]
     element to refer to an external CSS file[/size]

  • [size=undefined]Use the HTML [/size]

  • <head>





  • [size=undefined]
     element to store <style> and <link> elements[/size]

  • [size=undefined]Use the CSS [/size]
  • color





  • [size=undefined]
     property for text colors[/size]

  • [size=undefined]Use the CSS [/size]
  • font-family






  • [size=undefined]
     property for text fonts[/size]

  • [size=undefined]Use the CSS [/size]
  • font-size







  • [size=undefined]
     property for text sizes[/size]

  • [size=undefined]Use the CSS [/size]
  • border








  • [size=undefined]
     property for borders[/size]

  • [size=undefined]Use the CSS [/size]
  • padding









  • [size=undefined]
     property for space inside the border[/size]

  • [size=undefined]Use the CSS [/size]
  • margin










  • [size=undefined]
     property for space outside the border[/size]


HTML Style Tags

Tag
Description
<style>
Defines style information for an HTML document
<link>
Defines a link between a document and an external resource
Reply




Users browsing this thread:
1 Guest(s)