Although we are building an interactive JavaScript app, the foundation of any web application is always HTML and CSS. So we will begin there.
By the end of this section of the project, your page should closely resemble the example below.
Let's dive right in!
First off, we need to create the necessary files for our HTML and CSS.
- Create a new file named
index.html
. - Create a new file named
styles.css
. - Create an HTML Skeleton inside your
index.html
file.- Title your HTML document Meme Gallery.
- Leave the
<body>
element empty for now.
- Add a
<link>
tag to the<head>
of your HTML document to link yourstyles.css
file. The<link>
tag should have two attributes:- a
rel
attribute of"stylesheet"
- an
href
attribute of"styles.css"
- a
- Open
index.html
in your web browser. - If you open the Network tab of the Dev Tools in your browser and refresh the page, you should see both the
index.html
andstyles.css
loading.
Our page has a relatively simple structure, let's build the HTML for it now.
- Add a
<header>
element to the<body>
of your HTML. - Within the
<header>
:- Add a child
<h1>
element containing the text Meme Gallery. - Add a child
<input>
element. It should have two attributes for now:type
set to"url"
- and
placeholder
set to"Paste an image URL here"
- Now, add a child
<button>
element containing the text Add Image
- Add a child
- Last, add a
<main>
element to the<body>
of your HTML. This element is a sibling of the<header>
. It's also where our images will nest later on. For now we'll leave it empty.
At this stage, you should be able to load your index.html
in the browser and see something like this:
It looks kind of plain, but believe it or not, this is all of the HTML we need!
It's incredible what some web design and well-structured CSS can do for an otherwise sterile HTML document. Here is a side-by-side comparison of the transformation that our initial CSS will do for us.
Let's begin!
-
Open your
styles.css
file in your code editor. -
Create a new CSS rule using the universal selector (
*
) to resetbox-sizing
for every element in the document toborder-box
. This will help us manage our margin and padding in an intuitive way. You can read more aboutbox-sizing: border-box
in the MDN Web Docs. -
Create a new CSS rule that targets the
body
element and:- sets its
margin
to0
- sets its
font-family
tosans-serif
- sets its
background-color
to#2e3035
(a dark grey color)
- sets its
-
All of the text inside our
<header>
element will be centered, so create a new CSS rule that targets theheader
and sets itstext-align
tocenter
. -
We'd like the text inside of our
h1
to look a little more modern, so create a new CSS selector for it to:- set its
font-weight
to200
- set its
letter-spacing
to1px
- set its
-
We want to apply some fairly aggressive styling to our
input
. Fortunately, CSS has us covered. Create a new CSS rule for yourinput
to:- set its
width
to300px
so that it fills up more horizontal room on the page. - set its
padding-left
andpadding-right
to8px
to keep its placeholder nicely spaced away from its edges. - set its
margin-right
to4px
to add a little breathing room between the input and the button next to it. - finally, give it a custom
background-color
of#48494b
(a different dark gray) so that it pops out a little from the background.
- set its
-
Now apply some styles to your
button
with a new CSS selector that:- sets
padding-top
andpadding-bottom
to8px
- sets
padding-left
andpadding-right
to12px
- sets its
background-color
to#1bb76e
(a fancy green accent)
- sets
-
Verify that your document looks super-weird like this:
-
Take a deep breath. We're almost there!
-
There are some similar styles between our goal input and button, so now, create a new "group" CSS selector for both the
input
and thebutton
that does the following:- sets their
height
to31px
- removes their
border
by setting it tonone
- sets their
border-radius
to3px
for subtly rounded corners - adds a
box-shadow
to pop them off of the page a bit. You can use this as the value:0 6px 10px 0 rgba(0, 0, 0, 0.2)
These few styles should have made a big difference in how your
input
andbutton
look, yes? - sets their
-
If you click on your
button
or into yourinput
, you might notice that they have a grossoutline
when you:focus
on them. We'll need to create a "group" CSS selector for bothinput:focus
andbutton:focus
to turn off theoutline
(set it tonone
). -
Finally (for now), let's fix our remaining issue. The
color
of ourh1
,input
, andbutton
are not right. Set them all to#ffffff
(white) now using another new "group" CSS selector. Et voilá!
Hopefully you've seen just how vital HTML and CSS are to developing a nice user interface. In the next section, we'll begin adding functionality to our small app, but be careful not to forget that a clear, visually-appealing design is a very large part of usable software.
Let's start adding some functionality with JavaScript in the next section.
If you want, you can triple-check your code against a reference solution. However, if you got stuck, be sure to re-read the instructions very slowly and ask questions of the instructors rather than simply copying these examples.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Meme Gallery</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<header>
<h1>Meme Gallery</h1>
<input type="url" placeholder="Paste an image URL here">
<button>Add Image</button>
</header>
<main></main>
<script src="main.js"></script>
</body>
</html>
* {
box-sizing: border-box;
}
body {
margin: 0;
font-family: sans-serif;
background-color: #2e3035;
}
header {
text-align: center;
}
h1 {
font-weight: 200;
letter-spacing: 1px;
}
input {
width: 300px;
padding: 0 8px;
margin-right: 4px;
background-color: #48494b;
}
button {
padding: 8px 12px;
background-color: #1bb76e;
}
input,
button {
height: 31px;
border: none;
border-radius: 3px;
box-shadow: 0 6px 10px 0 rgba(0, 0, 0, 0.2);
}
input:focus,
button:focus {
outline: none;
}
header,
input,
button {
color: #ffffff
}