Learn CSS #6

CSS Backgrounds


The CSS background properties are used to add background effects for elements.


In these chapters, you will learn about the following CSS background properties:

  • background-color
  • background-image
  • background-repeat
  • background-attachment
  • background-position
  • background (shorthand property)

CSS background-color

The background-color property specifies the background color of an element.

Example

The background color of a page is set like this:

body {
  background-color: lightblue;
}

With CSS, a color is most often specified by:

  • a valid color name – like “red”
  • a HEX value – like “#ff0000”
  • an RGB value – like “rgb(255,0,0)”

Other Elements

You can set the background color for any HTML elements:

Example

Here, the <h1>, <p>, and <div> elements will have different background colors:

h1 {
  background-color: green;
}

div {
  background-color: lightblue;
}{
  background-color: yellow;
}

Opacity / Transparency

The opacity property specifies the opacity/transparency of an element. It can take a value from 0.0 – 1.0. The lower value, the more transparent:

opacity 1

opacity 0.6

opacity 0.3

opacity 0.1

Example

div {
  background-color: green;
  opacity: 0.3;
}

Note: When using the opacity property to add transparency to the background of an element, all of its child elements inherit the same transparency. This can make the text inside a fully transparent element hard to read.


Transparency using RGBA

If you do not want to apply opacity to child elements, like in our example above, use RGBA color values. The following example sets the opacity for the background color and not the text:

100% opacity

60% opacity

30% opacity

10% opacity

An RGBA color value is specified with: rgba(red, green, blue, alpha). The alpha parameter is a number between 0.0 (fully transparent) and 1.0 (fully opaque).

Example

div {
  background: rgba(0, 128, 0, 0.3) /* Green background with 30% opacity */
}

Categories

277 Responses

  1. Definitive journal of drugs and therapeutics. earch our drug database.
    stromectol generic
    Some are medicines that help people when doctors prescribe. Some are medicines that help people when doctors prescribe.

  2. п»їMedicament prescribing information. Drug information.
    https://mobic.store/# can i buy mobic without insurance
    Drugs information sheet. Some are medicines that help people when doctors prescribe.

  3. Get warning information here. safe and effective drugs are available.
    lisinopril 2016
    Comprehensive side effect and adverse reaction information. earch our drug database.

  4. Some are medicines that help people when doctors prescribe. Get warning information here.
    https://azithromycins.online/ zithromax generic cost
    Learn about the side effects, dosages, and interactions. safe and effective drugs are available.

  5. Prescription Drug Information, Interactions & Side. п»їMedicament prescribing information.
    https://edonlinefast.com erectile dysfunction drugs
    Prescription Drug Information, Interactions & Side. Get here.

  6. Read here. Learn about the side effects, dosages, and interactions.
    https://canadianfast.com/# buy prescription drugs without doctor
    Comprehensive side effect and adverse reaction information. All trends of medicament.

  7. Some trends of drugs. All trends of medicament.
    tadalafil 5mg cost
    Comprehensive side effect and adverse reaction information. Prescription Drug Information, Interactions & Side.

  8. Read information now. Learn about the side effects, dosages, and interactions.
    https://tadalafil1st.online/# tadalafil 20mg uk
    drug information and news for professionals and consumers. drug information and news for professionals and consumers.

  9. Best and news about drug. Everything what you want to know about pills.

    buy clomid tablets
    Drugs information sheet. drug information and news for professionals and consumers.

Leave a Reply

Your email address will not be published. Required fields are marked *