As we have progressed through this course, we have already learned some of the basics of HTML and CSS. In this chapter, we will look at integrating HTML, CSS, and Javascript in more detail.
We will begin by looking at CSS syntax, since we haven’t covered it as much as Javascript and HTML.
CSS stands for Cascading Style Sheets. CSS is used to style HTML elements, and generally to make your websites look amazing!
Similarly to accessing HTML in Javascript, we can access HTML in CSS using elements types, classes, and ids (and in some other ways, but this is enough for now!)
<p id=para1 class="paraClass"> My Paragraph </p>
p {
font-size: 30px;
}
CSS properties are in property and value pairs, with a colon inbetween, and a semi-colon between each pair. Properties are pre-defined, and the format of values changes depending on the type of property.
To access our element by its class, we would use the following syntax:
.paraClass {
color: blue;
background-color: green;
}
We use a period to access classes. Again, this CSS will style any element in the paraClass class.
#para1 {
color: red;
font-size: 10vh
}
See the Pen 5.1 Example by LSU DDEM (@lsuddem) on CodePen.
body {
background-color: pink;
font-family: Arial;
}
See the Pen Exercise 5.1 by LSU DDEM (@lsuddem) on CodePen.