Cool Stylin’ Sheets¶
Let’s add some Cascading Style Sheets (CSS) to visualize our page better.
Insert the following code in the <head>
right before the closing tag (i.e. </head>
):
html
is theCSS
selector, basically saying, “get anything in thehtml
tags!background-color
is the key, and thenazure
is the color we are setting it to.
What happened to the page?
Answer
It became Azure
!
That’s cool! But this way of using CSS, called inline CSS, can make your HTML file long and cumbersome. So the better practice is to have a separate file for CSS and bring that whole file in as a linked source.
Adding linked CSS¶
Click the New Folder button:
Type in styles to name the folder styles
:
Highlight the styles
folder by clicking on it:
Then click on the New file button:
Name the file style.css:
Double click to open the new file. Then copy and paste the following CSS:
body{
display: grid;
/* grid-template-columns: 1fr; */
grid-auto-rows: auto 1fr;
grid-template-areas: "header" "main_content" "footer";
background-color: aqua;
/* height: 100vh; */
}
header{
grid-area: header;
}
#footer{
grid-area: footer;
}
.main{
grid-area: main_content;
grid-template-areas: "content";
}
#contents{
grid-area: content;
}
Reminder!
Remember to save the style.css
file (PC:Ctrl+S | Mac:Cmd+S!
Next, go back to the index.html file and replace your entire <style> </style>
content and tags with this code:
This code tells the HTML file to use all of the CSS styles linked in the href
attribute.
More external CSS files?
You can have as many external references as you’d like, as long as you link them in this way. The bottom most CSS file has the most priority because it is the last CSS read and applied!
⚽ In-Class Exercise #2¶
Task
- Link
Leaflet
’s CSS that exists at this url:https://unpkg.com/leaflet@1.7.1/dist/leaflet.css
Extra: If you finish early, try to see if you can load Leaflet’s CSS locally instead!
We will go into CSS in more detail later, but what you need to know is that CSS has HTML element selectors
which are then followed by the styles in { }
.
🏁Checkpoint¶
Check to see if your code looks likes the following before moving on: