Translating Design To Code
Front End Engineer
@whynotdostuff
alecortega
There are only three things that make up all of the internet
So how does this actually work?
You already know how to code CSS
.basketball {
border-radius: 50%;
color: orange;
height: 10px;
width: 10px;
}.soccerball {
border-radius: 50%;
color: white;
height: 9px;
width: 9px;
}It's giving something a certain name, and then giving that name specific attributes that describe what it looks like
.basketball {
border-radius: 50%;
color: orange;
height: 10px;
width: 10px;
}The element that we want to put these styles on
What we want to describe
The value for that description
.basketball {
border-radius: 50%;
color: orange;
height: 10px;
width: 10px;
}A name we can give this grouping of styles.
<div class="basketball"></div>
<div class="basketball"></div>
<div class="basketball"></div>Begins with a "."
<div class="basketball"></div>We can place this name on as many elements as we want
#basketball {
border-radius: 50%;
color: orange;
height: 10px;
width: 10px;
}A name we can give this grouping of styles.
<div id="basketball"></div>
<div id="basketball"></div>
<div id="basketball"></div>
Begins with a "#"
<div id="basketball"></div>We can only place this on ONE element.
p {
color: orange;
font-size: 15px;
}The tag that we want to place these styles on.
<p>Resilient Coders</p>
<p>Resilient Coders</p>
<p>Resilient Coders</p>
<p>Resilient Coders</p>Will apply styling on all tags that match.
<h1>
Title
</h1><h1 class='title'>
Title
</h1>.title {
color: blue;
}So we give each element a name and then give that name a description in our CSS?
<div class="basketball"></div>
<div class="soccerball"></div>
<div class="tennisball"></div>
<div class="baseball"></div>.soccerball {
border-radius: 50%;
color: white;
height: 9px;
width: 9px;
}.basketball {
border-radius: 50%;
color: orange;
height: 10px;
width: 10px;
}.tennisball {
border-radius: 50%;
color: green;
height: 4px;
width: 4px;
}.baseball {
border-radius: 50%;
color: white;
height: 4px;
width: 4px;
}Think of classes like adjectives
not names
.round {
border-radius: 50%;
}.baseball {
color: white;
height: 4px;
width: 4px;
}.basketball {
color: orange;
height: 10px;
width: 10px;
}<div class="round basketball"></div>
<div class="round soccerball"></div>
<div class="round tennisball"></div>
<div class="round baseball"></div><div class="box-1"></div>
<div class="box-2"></div>
<div class="box-3"></div>.box-1 {
background-color: blue;
height: 100px;
width: 100px;
}
.box-2 {
background-color: green;
height: 100px;
width: 200px;
}
.box-3 {
background-color: blue;
height: 100px;
width: 100px;
}.box {
height: 100px;
}
.box-1 {
background-color: blue;
width: 100px;
}
.box-2 {
background-color: green;
width: 200px;
}
.box-3 {
background-color: blue;
width: 100px;
}.box-1 {
background-color: blue;
height: 100px;
width: 100px;
}
.box-2 {
background-color: green;
height: 100px;
width: 200px;
}
.box-3 {
background-color: blue;
height: 100px;
width: 100px;
}.box {
height: 100px;
}
.small {
background-color: blue;
width: 100px;
}
.large {
background-color: green;
width: 200px;
}
<div class="small box"></div>
<div class="large box"></div>
<div class="small box"></div>But how do I build a website with this?
Copy paste this <link> tag into your code and make sure the css file is in the same folder as your html file
<head>
<link rel="stylesheet" type="text/css" href="main.css">
</head>
<body>
</body>Imagine everything like a box within a box within a box within a...
<body>
</body>
HTML structure is the same as the visual hierarchy of your page
<div>
</div>
<img src=''/>
<p>
</p>
<body>
</body>
<body>
<div>
<img src="./path/to/img"/>
<p>
Resilient Coders is a...
</p>
</div>
</body>Ok I did that but it still looks like...
Let's start with the background
body {
/* Uhhh how do background on this */
}I still Google CSS properties I can't remember, and I do this professionally.
Start with "CSS" then whatever you want to change
w3schools, MDN, or css-tricks are all really awesome.
w3schools.com
Whoa look at that, that's exactly what we want!
body {
background-image: url('resilient.jpg');
}We can just copy paste the example into our code and change it to where our image is.
Examples and libraries of code exist to reduce the amount of work that you need to do and help you learn!
Nope!
Aiight, awesome but it still looks like...
We need some way of making this <div> look like a white container.
<div>
</div>
<body>
<div class="container">
<img src="resilient.jpg"/>
<p>
Resilient Coders is a...
</p>
</div>
</body>Let's put a class on it so we can describe what it should look like in our CSS!
.container {
background-color: white;
}Now all we have to do it describe what we want it to look like.
Remember when we described how big the basketball was? We can do the same thing to our elements here!
.container {
background-color: white;
width: 600px;
}Let's describe it as 600px wide
Margin
Padding
Content
Pushes boxes away
from other boxes
Gives a cushion for things inside the box
Four ways to write margin or padding:
div {
// margin: top right bottom left;
margin: 5px 10px 15px 20px;
// margin: top (right and left) bottom;
margin: 5px 15px 10px;
// margin: (top and bottom) (right and left);
margin: 10px 15px;
// margin: all sides;
margin: 10px;
}Adding "auto" for the left and right sides will center an element
div {
margin: 0 auto;
}Let's center our container and push it away from the top of the page by 75px
.container {
background-color: white;
margin: 75px auto 0;
width: 600px;
}Now let's try adding some padding to the container to make things look nice
.container {
background-color: white;
margin: 75px auto 0;
padding: 35px;
width: 600px;
}@whynotdostuff
alecortega