CSS: Color and Backgrounds

CSS: Color and Backgrounds

olor Values: name, #hex, rgb(R%, G%, B%), rgb(R, G, B)
You have four options for specifying color:

  • As a standard color name

  • As a hexadecimal value

  • As an RGB percentage

  • As a decimal value from 0 to 255

From other HTML work, you are probably familiar with the standard color names and color hex values. You can use any of these as color values with CSS.

Click here to open a new window with a reference chart of the standard names and their hex values.

CSS also offers a new option: RGB values. RGB allows you to describe color as a percentage of red, green, and blue, the three colors that are used to display an image on a monitor.

If all three are set at 100% you’ll get pure white. If all three are set at 0% you’ll get pure black. If any one is set to 100% and the others to 0%, you’ll get a pure red, green, or blue. Varying percentages in between give you different hues.

You specify RGB values by typing the letters rgb, an open parenthesis, the three percentages, and a close parenthesis, like this:

	{color: rgb(0%, 10%, 60%)}

You can also specify RGB values as a decimal number. If you are working with a program like PhotoShop, you are probably already familiar with these values; it is one of the ways PhotoShop describe color. To use a decimal number value, type the letters rgb, an open parenthesis, the three numbers separated with a comma, and a close parenthesis, like this:

	{color: rgb(255, 0, 0}

Color: {color: name/#hex/rgb(R%, G%, B%)/rgb(R, G, B)}
The color property selects a foreground color. Typically, the foreground color is the color of the text in the HTML element.

Example: This creates colored text for the paragraph element.

	P {color: green}

If you are using a CSS-enabled browser, this paragraph appears in green, with a named value of green.

	P {color: #9966cc}

If you are using a CSS-enabled browser, this paragraph appears in purple, with a hex value of 9966cc.

	P {color: rgb(70%, 0%, 30%)}

If you are using a CSS-enabled browser, this paragraph appears as 70% red, 0% green, and 30% blue.

	P {color: rgb(170, 0, 100)}

If you are using a CSS-enabled browser, this paragraph appears as 170 red, 0 green, and 100 blue.

Background Color: {background-color: colorname/hexvalue/rgb(R%, G%, B%)}
The background-color property specifies a background color. The background of an element is the space around the element. For example, the background of a headline is a bar, the depth and length of the headline text. The background of the body is the entire page.

Example: This sets a style rule for the background color of a head level one:

	h1 {background-color: darkcyan}

Project Cool

Background Image: {background-image: url(urlname)}
The background-image property specifies what image to display in the HTML element’s background area. It calls the image by its relative or full URL.

Example: This sets a style rule that calls an image named “ocean.gif” as the background for the table element:

	table {background-image: url(../images/ocean.gif)}

Background Image Repeat: {background-repeat: repeat/repeat-x/repeat-y/no-repeat}
The background-repeat property specifies how and if a background image gets repeated. The image can repeat:

  • In both X and Y directions

  • In just the X direction

  • In just the Y direction

  • In no direction. You can prevent the background image from repeating at all.

Example: This sets a style rule that calls an image named “ocean.gif” as the background for the body element and repeats it in both the X and Y directions:

	body {background-image: url(../images/ocean.gif);	      background-repeat: repeat}

Background Image Attachment: {background-attachment: scroll/fixed}
The background-attachment property specifies whether the background images scrolls or remains fixed in the same location on the page. This can be handy if you have, say a watermark logo, that you always want to appear in the center of your reader’s browser window. You can use these controls to fix its position while the content scrolls on top of it.

Example: This sets a style rule that calls an image named “ocean.gif” as the background for the body element and prevents the background image from scrolling with the page:

	body {background-image: url(../images/ocean.gif);	      background-attachment: fixed}

Background Image Position: {background-position: %vertical % horizontal – or – top/center/bottom left/center/right}
The background-position property lets you place a background image in a specific location within the element’s background. You can specify its placement in two ways:

  • As X and Y percentages.

    Example: This places an image named logo.gif 20% from the top of the page and 30 % from the left of the page. It also fixes it in place:

    	body {background-image: url(../images/logo.gif); 	background-position: 20% 30%;	background-attach: fixed}

  • As a vertical and horizontal alignment, relative to the element.

    Example: This places an image named logo.gif on the page at the top vertically and centering it horizontally:

    	body {background-image: url(../images/logo.gif); 	background-position: top center}

devx-admin

devx-admin

Share the Post:
Poland Energy Future

Westinghouse Builds Polish Power Plant

Westinghouse Electric Company and Bechtel have come together to establish a formal partnership in order to design and construct Poland’s inaugural nuclear power plant at

EV Labor Market

EV Industry Hurting For Skilled Labor

The United Auto Workers strike has highlighted the anticipated change towards a future dominated by electric vehicles (EVs), a shift which numerous people think will

Soaring EV Quotas

Soaring EV Quotas Spark Battle Against Time

Automakers are still expected to meet stringent electric vehicle (EV) sales quotas, despite the delayed ban on new petrol and diesel cars. Starting January 2023,

Affordable Electric Revolution

Tesla Rivals Make Bold Moves

Tesla, a name synonymous with EVs, has consistently been at the forefront of the automotive industry’s electric revolution. The products that Elon Musk has developed

Poland Energy Future

Westinghouse Builds Polish Power Plant

Westinghouse Electric Company and Bechtel have come together to establish a formal partnership in order to design and construct Poland’s inaugural nuclear power plant at the Lubiatowo-Kopalino site in Pomerania.

EV Labor Market

EV Industry Hurting For Skilled Labor

The United Auto Workers strike has highlighted the anticipated change towards a future dominated by electric vehicles (EVs), a shift which numerous people think will result in job losses. However,

Soaring EV Quotas

Soaring EV Quotas Spark Battle Against Time

Automakers are still expected to meet stringent electric vehicle (EV) sales quotas, despite the delayed ban on new petrol and diesel cars. Starting January 2023, more than one-fifth of automobiles

Affordable Electric Revolution

Tesla Rivals Make Bold Moves

Tesla, a name synonymous with EVs, has consistently been at the forefront of the automotive industry’s electric revolution. The products that Elon Musk has developed are at the forefront because

Sunsets' Technique

Inside the Climate Battle: Make Sunsets’ Technique

On February 12, 2023, Luke Iseman and Andrew Song from the solar geoengineering firm Make Sunsets showcased their technique for injecting sulfur dioxide (SO₂) into the stratosphere as a means

AI Adherence Prediction

AI Algorithm Predicts Treatment Adherence

Swoop, a prominent consumer health data company, has unveiled a cutting-edge algorithm capable of predicting adherence to treatment in people with Multiple Sclerosis (MS) and other health conditions. Utilizing artificial

Personalized UX

Here’s Why You Need to Use JavaScript and Cookies

In today’s increasingly digital world, websites often rely on JavaScript and cookies to provide users with a more seamless and personalized browsing experience. These key components allow websites to display

Geoengineering Methods

Scientists Dimming the Sun: It’s a Good Thing

Scientists at the University of Bern have been exploring geoengineering methods that could potentially slow down the melting of the West Antarctic ice sheet by reducing sunlight exposure. Among these

why startups succeed

The Top Reasons Why Startups Succeed

Everyone hears the stories. Apple was started in a garage. Musk slept in a rented office space while he was creating PayPal with his brother. Facebook was coded by a

Bold Evolution

Intel’s Bold Comeback

Intel, a leading figure in the semiconductor industry, has underperformed in the stock market over the past five years, with shares dropping by 4% as opposed to the 176% return

Semiconductor market

Semiconductor Slump: Rebound on the Horizon

In recent years, the semiconductor sector has faced a slump due to decreasing PC and smartphone sales, especially in 2022 and 2023. Nonetheless, as 2024 approaches, the industry seems to

Elevated Content Deals

Elevate Your Content Creation with Amazing Deals

The latest Tech Deals cater to creators of different levels and budgets, featuring a variety of computer accessories and tools designed specifically for content creation. Enhance your technological setup with

Learn Web Security

An Easy Way to Learn Web Security

The Web Security Academy has recently introduced new educational courses designed to offer a comprehensible and straightforward journey through the intricate realm of web security. These carefully designed learning courses

Military Drones Revolution

Military Drones: New Mobile Command Centers

The Air Force Special Operations Command (AFSOC) is currently working on a pioneering project that aims to transform MQ-9 Reaper drones into mobile command centers to better manage smaller unmanned

Tech Partnership

US and Vietnam: The Next Tech Leaders?

The US and Vietnam have entered into a series of multi-billion-dollar business deals, marking a significant leap forward in their cooperation in vital sectors like artificial intelligence (AI), semiconductors, and

Huge Savings

Score Massive Savings on Portable Gaming

This week in tech bargains, a well-known firm has considerably reduced the price of its portable gaming device, cutting costs by as much as 20 percent, which matches the lowest

Cloudfare Protection

Unbreakable: Cloudflare One Data Protection Suite

Recently, Cloudflare introduced its One Data Protection Suite, an extensive collection of sophisticated security tools designed to protect data in various environments, including web, private, and SaaS applications. The suite

Drone Revolution

Cool Drone Tech Unveiled at London Event

At the DSEI defense event in London, Israeli defense firms exhibited cutting-edge drone technology featuring vertical-takeoff-and-landing (VTOL) abilities while launching two innovative systems that have already been acquired by clients.

2D Semiconductor Revolution

Disrupting Electronics with 2D Semiconductors

The rapid development in electronic devices has created an increasing demand for advanced semiconductors. While silicon has traditionally been the go-to material for such applications, it suffers from certain limitations.

Cisco Growth

Cisco Cuts Jobs To Optimize Growth

Tech giant Cisco Systems Inc. recently unveiled plans to reduce its workforce in two Californian cities, with the goal of optimizing the company’s cost structure. The company has decided to

FAA Authorization

FAA Approves Drone Deliveries

In a significant development for the US drone industry, drone delivery company Zipline has gained Federal Aviation Administration (FAA) authorization, permitting them to operate drones beyond the visual line of

Mortgage Rate Challenges

Prop-Tech Firms Face Mortgage Rate Challenges

The surge in mortgage rates and a subsequent decrease in home buying have presented challenges for prop-tech firms like Divvy Homes, a rent-to-own start-up company. With a previous valuation of

Lighthouse Updates

Microsoft 365 Lighthouse: Powerful Updates

Microsoft has introduced a new update to Microsoft 365 Lighthouse, which includes support for alerts and notifications. This update is designed to give Managed Service Providers (MSPs) increased control and

Website Lock

Mysterious Website Blockage Sparks Concern

Recently, visitors of a well-known resource website encountered a message blocking their access, resulting in disappointment and frustration among its users. While the reason for this limitation remains uncertain, specialists