-
Notifications
You must be signed in to change notification settings - Fork 0
Exercises (CSS): Webmaking with HTML and CSS
selector { property: value; }Let's write some CSS rules to change the background color of some of our elements! First, create a style element (<style>...</style>) inside your head element. Then:
- Set the
headerelement'sbackground-colortomediumvioletred. - Set the
background-colorof yoursectionelements tolightgrey. - Set the
background-colorof yourmainelement togoldenrod.
- Follow the CSS syntax pattern:
selector { property: value; }. For task 1, this means: useheaderas theselector,background-coloras thepropertyandmediumvioletredas thevalue.
- Adding a style element and the solution for task 1 (the other tasks follow this pattern).
<!DOCTYPE html>
<html>
<head>
<style>
header { background-color: mediumvioletred; }
</style>
</head>
<body>
<!-- body content -->
</body>
</html>rgb(R, G, B), where R, G, and B can be numbers (0 to 255), percentages (0% to 100%), or none.
For this short exercise, create CSS rules based on the instructions below:
- Set the
background-colorproperty of yourh1element torgb(68,68,68)(dark grey). - Set the
colorproperty of yourheaderelement to a bright yellow or gold color using anrgbexpression. Hint: red and green should dominate for yellows and golds.
- Don't forget that your CSS goes inside your
styleelement! - Follow the CSS syntax pattern:
selector { property: value; }using anrgbexpression for thevalue.
- Using an
rgbexpression to set thebackground-colorproperty ofheaderelements to a pale blue.
header { background-color: rgb(65, 120, 240); }<h1>Getting started with
<span class="big">HTML and CSS</span>
</h1>Together, let's first add a span element with the big class (i.e., class="big") inside our h1 element. Then, let's:
-
Create a CSS rule for the class selector,
.big. -
Create a declaration to set the
font-sizeproperty to120%.Contrasting color schemes can make your web page more visually appealing. For the rest of this exercise, you will create a CSS rule that will apply a color scheme of light text/dark background.
-
Create a CSS rule with the class selector,
.dark. -
Create declarations to do the following:
- Set the
background-colorproperty todarkslategrey. - Change the
colorproperty (text color) towhite.
- Set the
-
On your page, apply this rule to one or more (but not all) of your
sectionelements by adding a class attribute and thedarkclass (i.e.,class="dark").
- Don't forget that your CSS goes inside your
styleelement! - Class selectors start with a dot
.followed by the name of the class, e.g.
.big { /* property: value; */ }`- The
h1element in the finished project also has someemelements sprinkled in.
<h1>Getting started with
<span class="big">
<em>HTML</em> and <em>CSS</em>
</span>
</h1>In this short exercise, we'll create a rule for the body element and use it to change the typeface of the whole page.
- Create a rule that uses
bodyas a selector. - Add a declaration to your new rule that sets the
font-familyproperty to'Segoe UI', sans-serifBe sure to include both the font name as well as the fallback typeface (sans-serif).
That's it! Because of inheritance, every element contained in body (so, every element on the page) will use body's value of font-family.
Find your rules that use the h1 & section selectors. Then, modify each rule to include declarations for the following properties:
-
max-width, with a value between500pxand700px. This is the horizontal width of the element. -
padding, with a value between10pxand20px.
h1 {
background-color: rgb(68,68,68);
max-width: /* ... */;
padding: /* ... */;
}
section {
background-color: lightgrey;
/* ... */
}Find your rules that use the h1 & section selectors. Then, modify each rule to include declarations for the following properties:
- For your
sectionrule, set themarginproperty toauto. - For your
h1rule, set themarginproperty toautoand thetext-alignproperty tocenter.
img {
max-width: 100%;
}h1 {
background-color: rgb(68, 68, 68);
max-width: 600px;
padding: 10px;
margin: auto;
text-align: center;
/* new properties 👇 */
text-transform: uppercase;
font-size:250%;
line-height: 1;
}- A selector that works based on the relationship between elements. It means "all
emelements inside ofh1elements" (of which there are 2).
h1 em {
color:skyblue;
}<header>
<img class="header-img" src="https://picsum.photos/seed/qrst/800/250" alt="">
<h1>...</h1>
</header>.header-img {
display:block;
width:100%;
max-width:620px;
margin:auto;
}