Exercise: CSS Intro
Objective#
Practice using CSS rulesets to add styles to web pages.
Exercise 1#
Steps are to be completed in your root directory (CSS_Exercise/) and index.html file.
- Create a new css file, named
index.css, in your project's root directory - Create a link element nested in the
<head></head>of yourindex.htmlfile, that contains an href attribute with a value that links to your newly created external stylesheet (don't forget to add a rel attribute to describe the linked content as a stylesheet*)
Exercise 2#
Steps are to be completed by writing css rulesets in your index.css file.
- Add a
nav-linkclass name to each anchor element on your page. - Create a ruleset in your
index.cssfile that selects all elements withnav-linkclass name - Create a declaration in your new ruleset that changes the text color of the
nav-linkelements to orange - Create a declaration in your new ruleset that changes the text decoration of the
nav-linkelements to none, to remove the default underline for links.
Exercise 3#
Steps are to be completed by writing css rulesets in your index.css file.
- Create a ruleset in your
index.cssfile that selects all elements with themaintag name - Create a declaration in your new ruleset that changes the max width of the
mainelements to 600px - Create a declaration in your new ruleset that changes the margin top and margin bottom of the
mainelements to 24px, to center themainelements between the left and right edges of the page (or their containing element). - Create a declaration in your new ruleset that changes the margin left and margin right of the
mainelements to auto, to center themainelements between the left and right edges of the page (or their containing element).
Exercise 4#
Steps are to be completed by writing css rulesets in your index.css file.
- Create a ruleset in your
index.cssfile that selects all elements with thesectiontag name - Create a declaration in your new ruleset that changes the margin top and margin bottom of the
sectionelements to 24px, to center thesectionelements between the left and right edges of the page (or their containing element). - Create a declaration in your new ruleset that changes the padding left, padding right, padding top and padding bottom of the
sectionelements to 16px, to give thesectionelements space between their content and border.
Exercise 5#
Steps are to be completed by writing css rulesets in your index.css file.
- Add a
titleid attribute to theh1element in yourindex.htmlfile - Create a ruleset in your
index.cssfile that selects the element with thetitleid - Create a declaration in your new ruleset that changes the font size of the
titleelement to 40px. - Create a declaration in your new ruleset that changes the font weight of the
titleelement to 800, to give thetitleelement's text a bolded font weight.
Exercise 6#
Steps are to be completed by writing css rulesets in your index.css file.
- Add a
d-inlineclass name attribute to the currentlielements in yourindex.htmlfile - Create a ruleset in your
index.cssfile that selects the element with thed-inlineclass name - Create a declaration in your new ruleset that changes the display of the
d-inlineelements to inline, to have each<li></li>display as an inline element.
Exercise 7#
Steps are to be completed by writing css rulesets in your index.css file.
- Create a ruleset in your
index.cssfile that selects any<ul></ul>element nested as a child of a<nav></nav>element. Use the descendent selector. - Create a declaration in your new ruleset that changes the list style of the
nav > ulelements to none, to remove the bullet points that are displayed by default for lists.
Exercise 8#
Steps are to be completed by writing css rulesets in your index.css file.
- Create a ruleset in your
index.cssfile that selects the<body></body>element. - Create a declaration in your new ruleset that changes the background color of the
<body></body>element to #222222. - Create a declaration in your new ruleset that changes the text color of the
<body></body>element's text content to #EEEEEE.
Exercise 9#
Steps are to be completed by writing css rulesets in your index.css file.
- Add an
avatarid attribute to the<img>element in yourindex.htmlfile. - Create a ruleset in your
index.cssfile that selects the element with theavatarid. - Create a declaration in your new ruleset that changes the width of the
avatarelement to 100px. - Create a declaration in your new ruleset that changes the margin left and margin right of the
avatarelement to auto. - Create a declaration in your new ruleset that changes the margin top and margin bottom of the
avatarelement to 32px.