p {
color: red;
}
.my-class-name {
color: blue;
}
#my-id-name {
color: purple;
}
Image from internetingishard.com
We re-created the following section from the turing website.
Image from turing.io
The <div> HTML container element is used to group other HTML elements together.
To open the inspector, right-click on the website and select "inspect".
Part of building a website includes ensuring everyone can access the website. For this, we'll need to use a company that offers web hosting.
A service that stores all the necessary files to render your website. This includes the HTML and CSS files.
For our final project, we'll use the web hosting service Neocities.
Why neocities?
Visit neocities.org to create an account.
Neocities offers an HTML tutorial
Clear out the existing HTML but keep the HTML structure.
<!DOCTYPE html>
<html>
<head>
your-website-name
</head>
<body>
</body>
</html>
<head>
your-website-name
</head>
Focusing on the top portion of our website, we have a vertical split. Ignoring the content for now, let's focus on building this layout.
<body>
</body>
.split-layout-container {
height: 100vh;
background-color: purple;
}
The "vh" unit stands for "viewport height". The viewport height is the height of the browser's window, which across laptops, tables, and phones.
So far, we've discussed two ways elements take up space on a page: block layout and inline layout. For advanced positioning, we're going to use a third layout option called: Flexbox.
A flexbox layout consists of a flex container that holds flex items. These flex items can "flex" their sizes, growing to fill unused space in the container, or shrinking to avoid overflowing.
<body>
</body>
.split-layout-container {
display: flex;
height: 100vh;
background-color: purple;
}
.split-layout-media {
background-color: lightblue;
width: 50%;
}
.split-layout-container {
background-color: pink;
width: 50%;
}
A large number of sites use "lists" to create their navigation or footer as these section are a collection of links.
Wrap each list item in a link (aka, anchor tag):
Remove the bullet point icon
Remove the blue color and underline
Style each list item to be on the same line
Nav is on the right-hand side of the page
.navigation-list {
list-style-type: none;
}
.navigation a {
color: black;
text-decoration: none;
}
Place each list item to on the same line
Nav is on the right-hand side of the page
.navigation-list {
display: flex;
flex-direction: row-reverse;
list-style-type: none;
}
Create space between each list item
Create space around the navigation links
.navigation {
background-color: yellow;
padding-top: 40px;
padding-bottom: 20px;
}
Side-note, the background color is temporary and will help us see the padding that surrounds the nav element
Below the nav, let's add a container (div). Within that div, add the intro text.
Pineapple
Lorem ipsum dolor sit amet...
Visit lipsum.com to generate dummy text, also known as Lorem Ipsum.
Centering an element, vertically, can be tricky business. However, we can use flexbox to make it easy. Revisit the "split-layout-content" CSS class and set the layout to use "flex".
.split-layout-content {
background-color: pink;
width: 50%;
display: flex;
}
The flex layout defaults to placing elements in a row. In our case, we want a column layout.
.split-layout-content {
background-color: pink;
width: 50%;
display: flex;
flex-direction: column;
}
Not much has changed but changing the layout of the parent container will help the "intro" container position itself vertically. Let's vertically center the intro container.
.intro {
display: flex;
flex-direction: column;
height: 100%;
justify-content: center;
}
Add space around the text
Limit how much space the text can occupy
.intro {
display: flex;
flex-direction: column;
height: 100%;
justify-content: center;
max-width: 500px;
padding: 0 50px;
}
Add space between each line of text
.intro {
display: flex;
flex-direction: column;
height: 100%;
justify-content: center;
max-width: 500px;
padding: 0 50px;
line-height: 1.5;
}
Remove the pink and yellow background colors
Set the green background color
Below is the updated CSS with the green color:
.split-layout-content {
background-color: #828170;
display: flex;
flex-direction: column;
width: 50%;
}
.navigation {
padding-top: 40px;
padding-bottom: 20px;
}
Update the navigation links and the intro text to use the color white. Below is the updated CSS:
.navigation a {
color: white;
text-decoration: none;
}
.intro {
color: white;
display: flex;
flex-direction: column;
height: 100%;
justify-content: center;
line-height: 1.5;
max-width: 500px;
padding: 0 50px;
}
Remove the white border around the page
body {
margin: 0;
}
Set the font family
Set the font size
body {
font-family: Georgia, Arial, sans-serif;
font-size: 18px;
margin: 0;
}
Visit Unsplash for high-quality, free images.
A tall image will work best.
Once you found an image you like:
Update the existing HTML for "split-layout-media" and add a nested image tag to reference the recently uploaded image.
Position the image:
.split-layout-media img {
height: 100vh;
object-fit: cover;
width: 100%;
}
Current State of our Website
If you copy from below, update the image name to match the name of the image you uploaded to Neocities.
<!DOCTYPE html>
<html>
<head>
Pineapples
</head>
<body>
Pineapple
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla
libero orci, dictum vitae dapibus ornare, mollis eu urna. Proin
posuere maximus lacinia. Mauris non odio eget nisi dapibus vulputate
vitae non tellus. Nam dolor ex, ornare eu hendrerit nec, consequat
sit amet nisl. Etiam in condimentum ipsum, et fringilla massa.
Curabitur vel arcu quam.
</body>
</html>
body {
font-family: Georgia, Arial, sans-serif;
font-size: 18px;
margin: 0;
}
/* Intro Section */
.split-layout-container {
background-color: purple;
display: flex;
height: 100vh;
}
.split-layout-media {
background-color: lightblue;
width: 50%;
}
.split-layout-media img {
height: 100vh;
object-fit: cover;
width: 100%;
}
.split-layout-content {
background-color: #828170;
display: flex;
flex-direction: column;
width: 50%;
}
/* Nav Section */
.navigation {
padding-top: 40px;
padding-bottom: 20px;
}
.navigation-list {
display: flex;
flex-direction: row-reverse;
list-style-type: none;
}
.navigation a {
color: white;
text-decoration: none;
}
.navigation li {
padding-right: 60px;
}
.intro {
color: white;
display: flex;
flex-direction: column;
height: 100%;
justify-content: center;
line-height: 1.5;
margin: 0 auto;
max-width: 500px;
padding: 0 50px;
}