How can I resolve my doubts about learning to code?

That voice in your head

Is this for me?
Can I do this?
I’m not good at this.

It’s natural to have doubts. But what are doubts? Do doubts really exist? Or, are doubts simply beliefs you have developed about yourself?

Perhaps, these beliefs are based on a past experience with a similar topic with which you have struggled. Don’t internalize past struggles, or even failures. Those are not indicators of your capabilities.

Accept that you have struggled with something. Accept that as an event in your past but don’t let the memory, the feeling, of that struggle define you. A doubt is a feeling. 

You are an intelligent person

Even when based on a real experience, the doubt is not who you are as a person. You are a person with intelligence. Forget about that past moment. Maybe you had a bad teacher, maybe the instructions were not clear. Maybe that moment in your life simply was not the time for you to learn that topic. Now is another time, now is another moment in your life. And if you struggle today, then tomorrow will be another new moment, a new time to start

People approach coding as it’s full of arcane mysteries impenetrable to all but a select kind. You doubt you are part of that select kind. Yet, that’s a false belief. There is no special kind of person who is “good” at coding. If you can tie your shoelaces, you can learn to code. Or, even better, if you can put on a pair of flip flops, you can learn to code.

You can learn anything if you believe you can.

Of course, everyone starts at a different point, prepared with a different set of background knowledge. But forget about that. Coding is not a competition. Learning is not a competition. That’s the problem with grades. It sets up a competitive mindset that should have no place in education. 

Focus on yourself, your mindset. Forget about any negative of the past and the tell yourself, “I can do this.”

You just need to make the commitment. Make the commitment to yourself. Recognize that your mind is an incredibly powerful computer. In learning to code you are simply feeding your mind a new set of instructions: a set of instructions called computational thinking.

You are activating, pressing the power button, that part of your brain that is made to understand coding. Don’t let that other part of your brain, those negative thoughts, bad feelings and doubts defeat you.

We all struggle everyday with regulating our emotions and we all struggle everyday to focus on work, learning, and productivity. Don’t let doubt defeat you.

Take a moment and look at the computer closest to you. It could be a laptop or even a phone. Think about what it is. What is it? It’s a metal box. It has a battery, or some source of external power. The interior of the box is engineered with circuits that pass along electrical charges that paint images onto a screen. 

The computer has similarities to the human brain. Our brains have millions of neurons transmitting electrical charges forming thoughts, emotions, images, actions. The computer, unlike our minds, does not get distracted by all those thoughts and emotions.

Every application on a computer, everything a computer does, has been programmed by a human. The computer does what it has been told. An app is a set of instructions.

In learning to code, you are learning how to give instructions to a computer, you are learning how to teach a computer about your imagination.

Okay, maybe, you’re saying, “Okay, that’s a good concept. I get it. But how do I really code? How do I program something? Everything seems so arcane. The syntax is confusing. I’m getting frustrated with the simplest mistakes. Is a freakin’ semi-colon really that important?!”

Congratulations. The first step in coding is your mind casting away any doubt that you can do this. And these doubts will creep in every time you make an error in your code. We all make mistakes in coding everyday, even those of us with over 25 years of experience.

The difference: programmers are confident that they can resolve a problem. They recognize that there are mental strategies for thinking about a problem and that there are many resources for learning how to solve the problem. And they dive into that challenge and figure out what they do not know.

Here’s a mental strategy

* Take a breath. Take another deep breath.

* Say to yourself, “I can do this.”

* Look at the problem. Break down the complexity into small, discrete steps that you can figure out.

But what if you don’t know where to start. You are in the fog of unknowing. Look for what is closest to you, reach out to what you do understand. 

Let’s go through an example.

Say, I have this web page.

I want to change the background-color, the creamy yellow. You’ve already learned an essential question, “Can the background color change?”

You know there’s a bit of code for that. You know it’s CSS because you’ve learned that CSS is the set of instructions that control the style and design of a web page. You cannot remember the exact command. You get confused: is it color? or, no background-color? You google for the answer. You’ve learned that programmers google all the time. Sure, a lot of things they have remembered over time. Some things become part of your memory when you do it a lot. But the internet is always there as a reference source for figuring out how to do something. But you do need to know how to evaluate the sources that you find. Many sources on the Internet have become outdated or, perhaps, are even more confusing than necessary. 

Back to our example. You know there is a code to specify color. You remember the term hex. But there is no way that anyone can remember the millions of hex codes. You look it up. You’ve learned how to do that. Let’s change it from creamy yellow (#F0F3BD) to a bluish sapphire (#05668D).

You realize that in the CSS you set the hex code on the HTML body element to change the background color of the page.

body {
  background-color: #F0F3BD;
  margin: 0;
  padding: 0;
  font-family: Georgia, serif;

Changing background-color on the body element from #F0F3BD to #05668D changes the background color of the page.

You may be wondering why the top section is still teal green. Let’s look at that part of the HTML:

  <section id="top"> 
    <h1>Hey, You, Welcome to My World</h1>

Note the ID #top on the section. And the corresponding CSS:

body {
  background-color: #05668D;
  margin: 0;
  padding: 0;
  font-family: Georgia, serif;

#top {
  background-color: #00A896;
  padding-top: 10rem;
  padding-bottom: 10rem;

Be sure you understand what is happening in that CSS code.

Let’s go further. Let’s look at your web page. You have two sections labeled “top” and “bottom”. Now, we want the bottom section to change color when the mouse moves into that section. (“Let’s set aside whether that’s a good idea or not.”)

You think, “How do I…?” Now, don’t go immediately to google and type in the question that you have. That’s not computational thinking. Do not doubt your ability to think up a possible solution. 

Let’s think about this.

We know that a web page consists of HTML elements. Those elements can be styled with CSS. And we also know that those HTML elements can be further styled with class names and ID names. That is a core set of knowledge about HTML and CSS that has not changed for decades. And it’s not going to change in the future.

What do we know about JavaScript? 

Based on what you know, you know that JavaScript controls the behavior of a page. But you also know that you  can use CSS to change the color of an element on hover. Remember, how a link color can change when you hover over it with a mouse? You should ask yourself, “Can I use CSS for doing that or do I need to use JavaScript?” 

In programming, there are usually more than one way to do something. One way may be more efficient. Another way may be easier. One way might present more problems down the road. While there is usually a best practice for each technique, as a beginner, you do not want to get stuck on figuring out the most optimal way of doing something. Many people would disagree with me on that. But when you are learning something new, you don’t want to get paralyzed by perfection. The same way is true when you are developing a prototype or a small project. Don’t get paralyzed by perfection. And remember: what you are developing at this stage is unlikely to be used by millions of people. It does not need to be so highly optimized that it can process thousands of hits per second. You are learning. Focus on getting something to work. Later is the process of refactoring, of improving the code. 

How can we programmatically control the behavior of a web page.

Let’s further define “programmatically”:

You know that a program, code, is a set of instructions. It’s a set of instructions written in a specific programming language. In this case, we are using JavaScript because JavaScript is a specific language with the specific function of working within an application called a browser, like Chrome or Safari or Firefox. There are a lot of other programming languages, but we’re not going to go over those now. Most importantly, do not confuse JavaScript with Java, which is an entirely different programming language. Other than having similar names, the two languages are not the same. If you are talking with an experienced developer and you say, Java, when you should be talking about JavaScript, then you will lose all credibility. Be sure you know the difference. 

How do you use JavaScript programmatically? What is really happening?

The browser is an app, though we often don’t think of it that way. It’s an app that downloads HTML documents and presents those documents onto a screen (within the browser). The app also downloads and reads a CSS file to determine the layout and appearance of the document. Built inside of every browser is JavaScript. JavaScript can interpret your code, your set of instructions. JavaScript has the capabilities for processing a script to change the appearance or behavior of a web page. 

Let’s go back to our example of changing the background color for the bottom section when the mouse hovers into that section. 

The browser, like any app, is smart. It was programmed to do certain things. In addition to download and styling documents, the browser keeps track of a lot of information that is happening. The browser stores all that information as “properties”. The values of those properties can be accessed programmatically, in other words, by your code.

Let’s look at some these properties. A browser gives us a console to view parts of the code. You are already familiar with the Inspect element of Chrome. In Chrome, open up the Inspect tool by right clicking on the web page. Once you have the Inspect tool open, click on the word Console to display the console box.

The console box is an interactive in which you can view and run JS commands. The console is really valuable in debugging (i.e., troubleshooting) your JS code since it can give you clues as to what is (and is not) happening in your code.

One of the most important aspects of JavaScript is that the browser makes available all sorts of properties that can be manipulated with JS. We’re going to look at a few properties as examples. Be sure to have the web page open in Chrome, and have the Inspect tool open to the Console.

Exploring the DOM

The Document Object Model (DOM) is the most important part of understanding how JS manipulates the behavior of a web page. Using the console, we will walk through some examples of how JS examines the DOM. At this point, the goal is for you to grasp the concepts behind how JS accesses different parts of a web document. Keep in mind: if JS can access a specific property of a web document, then JS can change that property. The change in the property can have a visual effect on the screen.

My recommendation is that you read through this section, try the examples in a console on your own laptop, and then later come back to this section as reference material when needed.

In the console box is a prompt, as indicated by the greater than (>) sign. You type commands into the console box at the prompt and then hit enter/return to run the command.

Type the word “document” and hit return. You should get something like the following:

The document command has returned the document object. You can reveal the contents of the document object by clicking on the triangle next to #document. When you do that, you will see the HTML document:

Now you know that every time you see one of those little triangles, then you can click to reveal further details. Click on the triangles next to head and body to reveal the full HTML document.

Most often, you will only be accessing a specific part of a document. JS has many valuable ways of doing that. We’re just going to start touching on a couple of methods here. Let’s get just the body element. In that case, simply type document.body in the console and press return:

Remember that the body element contains the visible parts of the web page. But, more often, you will want to get a very specific part of the body. Notice how the HTML elements are structured in a hierarchy. That tree-like hierarchy allows you to drill down and retrieve specific elements. Let’s say that we just wanted to get the section with the ID bottom. Take a look at the following screenshot of the console, and see if you can understand what’s happening:

The command to get the bottom section is document.getElementByID(“bottom”); remember, we are only using the word “bottom” in the command because that is the actual ID name. If the ID was named something else (like “panel”), then we would use the word “panel” instead of “bottom” in the command. Make sure you understand that. For practice, in the console try, getting various elements by ID from the web page.

In addition to document.getElementByID, there are several other handy methods for retrieving parts of an HTML document object, such as

  • getElementsByTagName
  • getElementsByClassName

Storing values in variables

Every programming language has the concept of a variable, which allows you to store a value. Storing values in variables makes it easier to do things with those values. For instance, we can store the section “bottom” from our previous example in a variable named bottom. (There are several ways of declaring variables as well as best practices and rules for naming variables. We’ll talk about those later.) Here, we are just introducing the concept. And you can try this in the console:

(When you press enter, you will get back “undefined” but don’t worry about that, for now.)

The variable makes it easier for writing code. All HTML elements have many properties, and those properties can be accessed via JS. For instance, all the CSS settings of an element can be accessed through JS. You access the CSS styles of an element through the adding .style to the end of an element variable in JS. For instance, to see the property styles for the variable we named “bottom”, simply type in the console:

The screenshot only shows a partial list of the dozens of style properties accessible via JS. Note that you are only seeing the style property names. You are not seeing the values of the style properties because the JS is not actually reading the CSS stylesheet. (We’ll come back to that in a later lesson.) Meanwhile, you can experiment with changing the background color for the bottom section by typing: = "red"

You also can use a hex code in place of “red”. For simplicity, I simply used a common color value. As you can see in the screenshot below, the background color for the bottom section has changed to red.

It’s important to note that any changes you make via the console are not permanently applied to the document. Console changes only take place on the computer’s display. When you refresh the page, the change will disappear unless you add it to the actual code.

The takeaway so far is that we have learned that the console can be used for debugging and quick testing. Now, let’s look at how we make an actual change to the code using JS that will transition the background color to red when a user hovers a mouse over the bottom section of that page.

User Interface Events

The concept of events happening in the user interface is another very important aspect of JS. We’ll go over this in more detail but, for now, here’s a brief introduction.

An event is when something happens inside the user interface of a web page. For our example, the event we’re listening for is when the mouse hovers over the bottom section. When that event occurs, then we are going to code an action to take place. That action will be to change the background color of the section.

Linking HTML to a JS file

Just as with CSS, we want to put our JS code into an external file. JS code files have the extension .js. Also, there should be no spaces in the filenames. Additionally, I prefer to group all my .js files for a site into a subfolder named “js” for JavaScript. The links to JS files are placed inside the body element of an HTML document and just before the closing body tag:

Pay attention to the structure and format of the script tag and the link to the JS file. Your JS file may have any name. In this example, I used “main”.

What’s in a JS file?

A JavaScript file is just a regular file, just like HTML and CSS are regular text files. To start, just create a new file in your code editor and give it a filename with a .js extension. Then we add the code:

var bottom = document.getElementById('bottom');
bottom.onmouseover = changeBackgroundColor;

function changeBackgroundColor() { = "red";

That’s it. That’s our complete JS file for changing the background color of the bottom section to red when the mouse moves over that section. Of course, this is a very simplistic example. We will be breaking down more complex examples in further detail.


Introduction to Bootstrap 4

Using Bootstrap

The current version of Bootstrap is 4.5; new versions come out regularly. When you’re looking at documentation on the web to figure out how to do something in Bootstrap, be sure to note the version number. Version 4 is very different from version 3. So, a lot of older advice about Bootstrap can lead you in the wrong direction.

Let’s walkthrough a page created with Bootstrap 4. First, here’s the plain page without any Bootstrap code:

It’s quite boring: some links at the top, a full-width image, and a paragraph of text.

Here’s the same page with Bootstrap:

Notice the navbar is looking nicer, and the paragraph is well formatted. Plus, this file also uses the free Font Awesome to add in those iconic links to GitHub, Twitter, and LinkedIn.

Before we take a close look at how Bootstrap works, here’s my own web page using this same code:

On my site, I opted not to use a navbar. I actually have a lot of different web sites, so I wanted my personal branded page to be minimal and distinguished by a unique image.

This code is freely available in case you want to use it for your own site. See the code repository at and a live version of the site:

Code Walkthrough

Let’s take a look at what’s happening.

Step 1 in using Bootstrap

Since Bootstrap is a CSS framework, keep in mind that it’s really just a bunch of CSS code that you can freely use. How do you use? Well, how would you use any CSS code? You have to link to the CSS file for Bootstrap.

Bootstrap makes this really easy for you. Just go to the getting started page on the Bootstrap site. Look for the CSS link. There’s a convenient copy button that copies the entire link to your clipboard to make copy-and-paste super easy.

Be sure that you’re always using the latest production release of Bootstrap. As of this writing, it’s version 4.5 You can locate the current version number in the navbar:

Google searches often will point you to an outdated version number, so be sure to check.

Now that you’ve copied the Bootstrap CSS link to your clipboard, you simply want to paste it into the head section of your HTML file:

There are a few things happening here in this head section. Let’s look at certain line numbers, but focus on line 8:

line 7: links to Google font
line 8: links to the Bootstrap CSS file. Note that the file extension at the end of URL in the href is simply .css. Again, remember, that Bootstrap is mainly just a CSS file that someone else developed for you to use.
line 9: links to Font Awesome, which is also just a CSS file.
line 10: links to a special CSS file for the code walkthrough. (You will not be using this link in any of your files, but I included it so that you could see how it works.)
line 11: links to an overall styles.css file for my website
line 12: links to a specific bd-hero-styles.css for this page.

The lesson learned through all these links is that an HTML file can link to multiple CSS files. Very important: the order in which the CSS files are listed in the head section determines the order in which the browser reads the files. Remember that files listed later overwrite any earlier CSS code. This is very important to remember since it may trip you up if you put the Bootstrap CSS after your own CSS file. In that case, none of your own CSS code will appear on the web page.

Also, you can and most likely will want to combine the contents of styles.css and bd-hero-styles.css into a single styles.css file. For a project I’m working on, I needed to have the files separate. But on your site, you’re unlikely to have that need.

Step 2: Creating the navbar with Bootstrap

Navbars can be a bit tricky, especially when developing one from scratch in plain CSS. Indeed, the convenience of the navbar code in Bootstrap is one of the reasons I use Bootstrap.

The Bootstrap documentation provides sample code for various types of navbars. You can copy/paste this code into your own project. That documentation page can be rather confusing when you first look at it.

Step 3: Creating containers in Bootstrap

In this step, we will go over the initial step in defining a layout in Bootstrap: setting up a container for the grid. Containers, as the name suggest, contain the grid that controls the layout of the content. In other words, containers also contain the content. . A web page may have one containers or multiple containers. Containers can be nested, but in most cases you don’t use nested containers.

How do you define a container in Bootstrap? Remember that Bootstrap is a set of CSS code. So, it comes with a .container class. You add this .container class to an HTML element in the body of the HTML page. Most often, you will add the .container class to an HTML element such as main, section, article, or div.

By default, the .container class comes with padding that provides an attractive left and right margin. That makes the content look centered on the web page without you needing to do anything else.

In some cases, you will the content to stretch all the way across a page without any margin. This is most common when using an image that you want to fully span the width of the page. You implement this style by using the class .container-fluid instead of .container.

Terms. Be sure to understand the following three terms when working with grid layouts.

Viewport: the part of the web page that is visible within the browser. The viewport is only what you see at a particular time. The viewport does not include the entire web page if you have to scroll to see the rest of the web page. The browser automatically knows what parts of the page is visible on the screen. This information, known as the viewport, is very useful in developing web pages, particularly when you add interactions or behaviors that you only want to start activating when a person scrolls into a certain area of the page.

In terms of layout and responsive design, the viewport keeps track of the width of the visible page within the browser.

Breakpoints: A breakpoint is a specified width of the viewport, e.g., 960px. When the browser is adjusted to go beyond or below that width, i.e., breakpoint, the design can respond with a change of layout to accommodate the smaller or larger width. This is where responsive design comes into play.

Min-width: the viewport width in pixels at which

Bootstrap sets sizes for the following widths as max-width and breakpoints:

≥ 576px
≥ 768px
≥ 992px
Extra Large
≥ 1200px
Min-width breakpoints: top row

When use the class .container, the width of the container changes depending upon the width of the viewport. While this may seem confusing at first, this feature allows you to specify in your CSS different layouts for different widths. Obviously, phones have viewports with smaller widths than laptop and desktop computers. That’s where having your content in a container that can automatically adjust based on the viewport width is really helpful.

Creating Grids in Bootstrap

Always keep in mind that Bootstrap is a set of predefined CSS classes that you can use in your HTML. Bootstrap allows you to easily define a grid that is 12 columns wide. And you can add as many or as few rows as you need.

To define a grid, start with the container. Then you define the number of columns, and then a row.

<main class="container">
<section class="col-10 offset-1">
<div class="row">
<h1>This is a heading</h1>
<p>This is a paragraph of text</p>

The code above shows a simple Bootstrap grid that is 10 columns wide, and that is offset by 1 column on the left margin. The offset provides extra margin.


Grids, responsive design, & CSS frameworks

This articles provides an introduction to grids, responsive design, and CSS frameworks.

Grids are a fundamental part of design that makes your life a lot easier. The second part of the article will talk about responsive design: or, how web sites adapt (or respond) to different sizes of screens. The web designer and developer have to plan and decide how the site responds, and then implement the code to make it happen. And that’s where CSS frameworks come into play, which we will cover in the third part of the video. CSS frameworks are freely available sets of code that other, very experienced developers, have created for us to reuse in order to implement a quality responsive design. In other words, you don’t have to reinvent the wheel. But there’s still a lot of thought that goes into using a CSS framework. In the course, we’ll focus on the most popular CSS framework: Bootstrap. This post you’re now reading provides a context for understanding why we’re using Bootstrap.

Why grids for design layout?

A bit of graphic design history is in order. Utilizing a grid is one of the best steps you can make to improve your layout. That’s common knowledge among designers. But everyone has to learn about grids at some point.

Grids provide a consistent structure for organizing and aligning content. Don’t be misled into thinking that a grid implies everything is just boring rows and columns like a spreadsheet. The grid is a concept for organizing content. A grid actually offers a large variety of layout possibilities, even possibilities that don’t at first even appear to be a grid.

For learning more about grids, particularly in print design, I highly recommend Thinking with Type.

What is a grid?

In some ways, all of us have been learning to compose with a grid since elementary school. Remember that lined paper on which you first learned to write, or perhaps that you even write on today (if you still write by pen and paper). Each of those horizontal lines represent a row that helps you keep the content aligned neatly.

Designers, though, tend to use columns mostly. Think of a newspaper layout. Perhaps some of you have never actually read a print newspaper. But think about how columns divide a page into vertical parts.

Combine rows and columns and you have a true grid where items can occupy multiple blocks either horizontally and/or vertically. You also can have grids within grids.

Grids have been a consistent element of layout since long before even the early days of the printing press, and before the age of illuminated manuscripts. In the early 20th century, advances in printing led to new types of publications.

“Modern man has found in illustrated newspapers and magazines a new source of delight.”

The New Typography (1928), Jan Tschichold

If illustrated newspapers and magazines formed new sources of delight for the early 20th century, then the Web with its colorful, interactive, motion-driven apps has surpassed every expectation and promises to keep evolving into even more delightful (and, perhaps, frightening) experiences.

Jan Tschichold emerged as one of the foremost thinkers to ever impact the design of print publications. He argued that “the enormous importance of magazines today requires us to give them the most careful attention. Since today more magazines are read than books, and much more important matter appears only in magazines, there are many new problems, of which the most important is how to find a contemporary style for their production.”

In describing the thoughtful placement blocks of text and images Tschichold stated an approach:

Constructive, meaningful, and economical (= beautiful)

Jan Tschichold

Nearly 40 years after Tschichold articulation of what constitutes a beautiful layout, Josef Muller-Brockmann produced a series of definitive guides that provided detailed instructions for grids. Out of that came the landmark work Grid Systems, which is essential reading for anyone involved in working with grids.

Responsive design

When the web started gaining popularity back in the 1990s, computer monitors were more or less the same size. But as smart phones, then tablets, came out in the 200s, web design got a lot more difficult. Developers had to account for devices with different size screens. The complexity of design and development for mobile devices required many modifications to the code, which allowed for sites to look good on every device. Honestly, it was a painful period in web development as it required knowledge of many obscure techniques in CSS. Code became clunky and more difficult to maintain.

Fortunately, developers started sharing bits of their code on the Internet. That eventually lead to the emergence of CSS frameworks: systematic collections of CSS code that can be freely reused for improving web development.

The landmark article Responsive Web Design by Ethan Marcotte (2010) identified the initial techniques for adapting web sites to different devices. The term “responsive design” became adopted to describe that process. While the technical aspect of Marcotte’s article are now dated, the concept remains the same.

CSS frameworks = responsive design + grids + web design

By this point in the course, students have gained some experience in creating HTML files and working with CSS. They’ve probably noticed that a lot of aspects are repeated over and over again when starting to develop a site. Years ago, before frameworks, us developers would have some base code that we would copy over when starting a new web project. The first framework that I started using a lot was YAML CSS. (You don’t need to bother with that, I am just noting if as a reference for my own historical work.) I also used the 960 grid system. That approach made a lot of sense to me. And, of course, I often would build sites out of WordPress and theming, but that’s a topic for another course.

Have you noticed that a lot of websites look similar or have similar features? That’s likely because they’re using a template or a framework like Bootstrap.

CSS frameworks significantly changed the way I do front-end web development. There was a time when I mostly used Zurb Foundation for most of my own work, but I switched over to Bootstrap since it’s easier for students to learn. Since these students have extremely limited design skills (at this point), Bootstrap enables them to create an attractive site with a the wider range of built-in styles that comes with Bootstrap. (And I switched to Bootstrap because I felt that I should be using the same framework that I taught.)

Of course, part of my former preference for Foundation was that I wanted the built-in styles to get out of my way. I needed the framework to handle some of the heavy lifting of the layout that I prefer not to bother with myself. But, now I’m mostly use Bootstrap but do know that there are other options out there. A very popular CSS framework is Tailwind. And, increasingly, many developers are not using a CSS framework at all but using the CSS grid capabilities built into the Web standards. But I feel like that’s a bit complex for students new to web design. So, for this class, don’t worry about anything other than Bootstrap.

Next, we’ll take a close look at actually how to implement Bootstrap in your code. You’re going to be pleasantly surprised at the difference it makes.


Creativity with CSS

Week 4 notes for DCI 110: Web Programming for Non-Programmers

In video lesson 2, we examined this basic site:

It’s okay, but it has some problems. Notice that yellow bar at the very top? That shouldn’t be there. All the fonts are also bland, just the default fonts. The spacing of “Hello, beautiful world” needs to be higher in that top section. The font sizes are a bit difficult to read and would look better a bit larger.

Let’s make some changes to go from that to the following:

Okay, that looks a bit better.

For this lesson, we’re going to look at the following CSS techniques:

  • box model
  • font sizing

CSS Box Model

Learning target: I can modify elements by manipulating values defined by the box model.

Understanding the CSS box model is a requirement for advancing further with CSS. A helpful resource in explaining the CSS box model is by Shay Howe: Opening the Box Model. As you read that explanation of the CSS box model, keep the following in mind:

  • think of every HTML element as a block; (already see the similarity between a block and a box?)
  • every block, i.e., every HTML element, is a rectangular box with content + 5 adjustable properties: width, height, padding, borders, margins.
  • the width of a block consists of the the margin sizes (left margin + right margin) + border size (left border + right border) + padding (left padding + right padding) + the size of the content.
  • be sure that you understand the distinction between padding and margin.

Stop now, and read about the box model on Shaw Howe’s site. You should also read Chris Coyler’s brief article The CSS Box Model. Then come back here.

Feeling comfortable with the CSS box model? If not, go back and re-read that material.

Okay, let’s review our learning target: I can modify elements by manipulating values defined by the box model.

Modifying elements in the CSS box model

A lot of web design involves manipulating the elements of the CSS box model. It sounds simple, and in some ways it is simple. But the different boxes on a web page can impact each other. Here’s the top part of our page from last week, along with a few annotations:

  1. Why is that yellow bar at the top? It’s not intentional. Maybe it looks okay, but I really wanted the green box to be flush against the top. What’s happening there?
  2. The h1 “Welcome to our world” is too close to the top of the green box. Let’s give it some space and increase the font size.
  3. Move “Hello, beautiful world” up and increase the font size.

We won’t worry about the rest of the page for now.

The HTML for the above image (only code for the top snippet of the page is shown):

  <section id="top">  
    <h1>Welcome to our world</h1>
  <p><img src="images/globe.png"> Hello, beautiful world</p>

Let’s review our first problem question: Why is that yellow bar at the top?

The yellow that we are seeing at the very top is actually the background of the page. Remember that the entire page was set to yellow and that the green box (section top) sits on top of the background. Something is pushing the elements in the green box down on the page to reveal part of the yellow box. What is that something?

This is the common type of troubleshooting you will encounter over and over again in web development. It’s a little puzzle you have to figure out. The steps you want to follow in breaking it down is to take one HTML element at a time to see if it’s the guilty party causing the problem. In this example, our first logical guess is that the (section top) is the culprit. That seems perfectly logical since the green box is being pushed down. But upon closer inspection, we find that it’s not the section tag. And we also find that there’s nothing wrong with the body tag.

Determining that there’s nothing wrong involves looking at the CSS for those elements, plus also using the inspect tool in your web browser. If you were to hover over the h1 with the inspect tool, you will see that a top margin has been added by default. Remember, all browsers add default styles to the elements unless you use a CSS reset. I’m not using a reset on this page; therefore, you can see that the default top margin for the h1 is interfering with the intended design. Rather than going back and adding a CSS reset, I’m just going to modify the margin for the h1. Recall how this is part of the learning target: modifying box elements by manipulating values.

In the CSS, we can use the following to get rid of the margin-top on the h1 that is causing the yellow spacing:

h1 {
text-align: center;
color: #04415A;
margin-top: 0;

Let’s review the second problem question: give some spacing to the h1 and increase the font size. How would you increase the spacing above the h1 by 1rem? (Would you use margin or padding?)

For assignment C.5: Provide the CSS code to provide spacing above the h1. Only 1 line of CSS code needs adding to the h1 CSS style specifications above.

Use Canvas to submit your answer for assignment C.5.

How would you increase the font size? Note that this question addresses another learning target: I can specify a typographic hierarchy of font sizes using the em.

For assignment C.6: Provide the CSS code to increase the font size. The default body font size is 16px. We want to increase the h1 font size to 48px, but using only rem and not pixels.

Use Canvas to submit your answer for assignment C.6. It should be just one line of CSS code that is added to the h1 in the CSS style sheet.

If you have trouble answering these questions, then it may be useful if you go back to the video for lesson 2 and copy the HTML and CSS code to create this page and layout. Yes, it’s tedious to copy the code by hand from the video but it will be good practice to make sure you have everything working correctly. By examining the actual code, you can troubleshoot and determine if you have the correct answer.

We will adjust the third problem question, adjusting the spacing of “Hello, beautiful world”, in the next lesson.

Answering the two questions for assignments C.5 and C.6 should improve your confidence for tackling what comes next with CSS.


A cluster of assignments

This week in Web Programming for Non-programmers we have a cluster of assignments that aims to solidify your basic skills in working with HTML and CSS.

Background reading

This week read the following:

Organizing files for static websites on my blog.

View the video CSS for Beginners. Model Code & Critical Thinking Questions (5m). Lesson 2 on my YouTube channel. (The video refers to another video that explains the code presented in the video. I will upload that video next week after you have completed the questions in this week’s assignment.) Use the readings, listed below, to help you understand the video.

Chapter 2: Getting to Know CSS by Shay Howe.

On the Mozilla Developer Network site, read:

<link>: The External Resource Link Element

CSS selectors

Type, Class, and ID selectors

Class selectors and ID selectors

View the video What is GitHub (1m) on my YouTube channel and also read the brief post What is GitHub? on my blog.

Assignments for Week 3

There are 7 assignments this week. (2 assignments were transferred from last week to this week.) Most of the assignments are actually quite short, so it’s not as much work as it sounds. The assignments are all related to each other and are intended as small steps that help you work on your term project. As always, the due dates are recommended dates and not requirements. I do strongly recommend that you complete all assignments by the end of Sunday, September 13. See the details of each assignment in Canvas.

assignment H.3: File/directory management.

assignment C.1: Link to CSS file.

assignment C.2: ID & Class.

assignment C. 3: CSS file formatting

assignment C. 4: CSS comments

assignment CP3 (challenge problem): Creating an offline website

assignment CP4 (challenge problem): Publishing via GitHub pages (details on this assignment will be released on Thursday, Sept 8, 2020).


Organizing files for static websites

One of the most common problems that I’ve seen among students is file management. Or, more precisely, the lack of any kind of file management. If you are a student who depends upon the search function for finding files on you computer, then you need to break that habit. Web development depends upon organized file structures.

When helping a student troubleshoot a problem, I often will ask the student to show me the directory where his files are located. On more than one occasion, the student showed me something like this:

No. Please, no. Don’t do that.

To make your life easier in web development: learn to organize your files.

Key point

A website, at its most basic, is simply a directory of files on a server.

Simple, right?

Consider the incredible simplicity of that concept. On a server, the web server software looks for a designated folder (often called public_html). The files in that folder are the website.

Developing on your machine

As you develop websites on your local machine (i.e., your laptop), you want to organize your files in the same way that you do on the server. Note: I use the terms directory/subdirectory/folder/subfolder interchangeably. They mean the same thing.

A method for organizing files in web projects

Here’s the method that I use for organizing all my web development projects.

main project directory

Identify the main directory in which I’m going to store my projects. Note that I say projects. In this class and throughout your web development career, you will be working on multiple projects (often at the same time). Each project should exist in its own directory. But it’s good to have a main project directory: a directory of directories.

One place to put the project directory is under your Documents directory. Personally, I don’t ever store much of anything on the hard drive of my computer. I’m always concerned about backups and losing data. I actually use a paid Dropbox account that appears as a networked drive on my computer. The major benefit is that I can access my projects from any computer I work on: my home computer, my office computer, my laptop.

But for the purposes of this video: I’m going to assume you are using the Documents directory of your laptop.

Create the main projects directory. You can name the directory anything you like. I use WebDev.

Important! In naming files and directories for web projects, do not use spaces in those names.

Project directories

You now have a single directory to place all your projects. Remember, put each project in a different directory of the main projects folder.

Let’s create a project folder called “termProject”. You can name the folder anything you like, as long as you do not use spaces or special characters in the name.

At this point, you should have something like the following in your Documents directory (or wherever you’re placing your projects). Uh, don’t use the Desktop:

In the termProject folder, you want to create some subfolders:

  • css
  • js
  • images

In the termProject folder, you should end up with something like the following:

The index.html file

By convention, the file representing the default home page of a website is called index.html. That file exists in the top-level of your website folder, i.e., in this case our website folder is termProject. Do not put index.html in a subfolder of termProject.

Create an index.html in your termProject folder. (It can be just a blank file with the name index.html.) You should have something like the following:

Don’t worry about the file size for index.html. The above image says ‘zero bytes’ because the file is empty. As you add contents to the index.html file, then the size will change.

There you go! You have the basic structure for organizing files on a website. As you create more html files, you simply add those to the directory. You also, if you want, can create more subdirectories in case you have a lot of html files. Actually, you can create any subdirectory you want to hold different types of files. You can probably guess what type of files go in the css, images, and js subdirectories?

Getting a good handle on organizing files for a website is very important for making your life easier.


Listening is not learning

Sitting in a classroom while a professor lectures, or sitting at home watching a video of a professor speaking is not learning.

It’s listening. Sometimes it’s not even that. Sometimes, as we all know, even in the classroom you are barely paying any attention. But even if you are attentive, you are only using your minimal capacity for learning.

Taking notes during a class is helpful but can also be a distraction as you lose track of what the professor is saying while you are writing, especially if you are trying to transcribe verbatim everything the professor says. I’ve seen that in classrooms. It’s not that helpful, especially these days when lectures can be recorded. With video, you can pause, slow it down, or speed up and play the lecture at 1.5 speed.

Listening is acquiring information.

Learning happens when you take that information, do something with it like applying it to a problem or transforming the information in a different way.

Learning happens when you repeat that process of transferring what you have heard to different situations.

Learning happens when you do that over and over again.

Learning requires repetition. Remember, somewhere in school you had all that math homework: all those problems to solve, all those variations? The repetition is intended to help you learn, though you might still be wondering when you’re going to apply that calculus.

And that’s a key to learning: learning happens when you apply information to solve a problem that is of interest to you. That problem could be a project you are developing.

In this course, the term project is a project that should be of very strong interest to you. It’s about you.

You will learn the coding techniques as you apply those techniques to your project.

You are looking at videos now, on LinkedIn Learning and YouTube, to provide an introductory context and background information. As you view these videos, try to absorb what you can. Don’t stress if you don’t understand everything. As you transfer what you have heard to work on your project, you will find yourself going back and looking at those videos again. You will find yourself searching the Internet for how to do this or that. That’s normal. That’s how you learn. You learn by doing, not by listening.


Pandoc & The Peak of Shenandoah

Objective: a tutorial for the staff of Shenandoah in processing and uploading new posts to The Peak.

The Peak is the blog-like supplement to the twice-yearly Shenandoah literary magazine.

Credit for the technical development of The Peak goes to the wonderful work of W&L undergrad Coletta Fuller, who adapted Shenandoah’s primary theme and provided the masonry layout for The Peak.

Each section of The Peak home page, which exists within the overall Shenandoah site, is a slender block containing an image, a category, headline, and an edited excerpt.

The entire block is coded as a link to the post for that entry.

What are the steps for transforming a submission for The Peak into an actual post on the site?

The Peak is published with the WordPress platform that uses a highly customized theme for styling aspects like line breaks and paragraph indents. Articles for The Peak are submitted as Word files.

Step 1: Access The Peak WP site

You will need login credentials on Shenandoah’s WP installation for this step.

Step 2: Add new post

Start the new post in WP. Paste in the title. Select the appropriate category, e.g., On Craft. Save draft of the post.

Step 3. Converting docx file to HTML

This is the most complicated step. You cannot just copy and paste the text from Word into WordPress and expect happiness. You will be disappointed by the formatting. Also, the default save as HTML in Word is not effective, either.

You should use pandoc to convert docx files to HTML. Pandoc is a freely available, command-line tool that converts documents between all sorts of formats.

Installing Pandoc: On a Mac, the easiest installation method is to download the pkg installer from the Pandoc site:

If you are using a Windows machine, then the page might look slightly different and you should follow the instructions for installing on Windows. The rest of this document will assume that you are using a Mac.

Install the package file that you downloaded from the pandoc site by double-clicking on the downloaded file. It should then walk you a self-explanatory set of steps to complete the installation.

Ready? Is it installed? Unlike many apps, Pandoc has no graphical user interface. You will have to open up the Terminal app on a Mac and use the command-line. It’s easier than it sounds. On a Mac, the terminal app is in the Applications => Utilities folder.

Opening the terminal app will pop up the Terminal window. Your terminal app will look different than mine. Since I use the terminal app a lot, I’ve customized the colors and have a translucent background. But what you should be the same is in the upper left corner will be a prompt that ends in a $ sign. The prefix of the prompt will differ; it often displays the machine name and the username that is logged in.

Place the cursor focus in the window with the mouse (or trackpad on a laptop) and click. This should bring the terminal app to the foreground so that you can type commands into the terminal app.

To see if you have installed pandoc successfully, you can type the command:

which pandoc

Hit return (or enter) after typing the command. The terminal should then display a line that provides the path to the application. The path displayed on your Mac might be slightly different than mine below. Don’t worry. The important thing is that a path appears. If you enter the command “which pandoc”, hit return, and nothings happens, then pandoc is not installed. If you have a problem installing pandoc, then that requires a consultation with someone more experienced.

Okay, let’s assume that pandoc installed correctly.

Locate your .docx file. For simplicity, let’s just say that the docx file you want to convert is in the Downloads folder. In that case, from the command prompt, you should be able to type cd Downloads, and hit enter. To ensure you are in the right directory, you can the command pwd, which means “print working directory”; this command will display the current directory you are in.

Important: the Word file MUST be a .docx file. (Note the x at the end of the file extension.) If it is a .doc file (no x), then you must open the file in Word and save it as .docx before proceeding.

The actual conversion: for this step, you must know the exact filename that you want to convert. If you have any spaces in the filename, then you must enclose the filename in quotation marks in the following command. Otherwise, an error will result. Note: on the command line, filenames are case sensitive.

To convert the file named “Weiden The Peak final.docx” to html, use the following command:

pandoc "Weiden The Peak final.docx" -t html -o weiden.html

If all is successful, after hitting enter, then nothing should appear to have happened. Huh? Yes, success is not getting an error message. If you just get the blank prompt, then the file probably converted successfully. To ensure that the file converted, you can list the filename on the screen by using the list command and the name of the html file: ls weiden.html

At this point, you can open the html file in a text editor. Do not use Notepad. You may want to download and use Atom (free), which is what I use though there are many other options. Here’s what our sample file looks like after the pandoc conversion from .docx to .html and opened in Atom (only part of the file is shown in the image below):

Step 4: Copying to WordPress

The hard part is now over.

Next, you simply copy and paste the HTML, as shown above, from Atom (or another text editor) and paste into the editing space for the post you created in WordPress:

Save the draft.

Step 5: Adjusting the author name

By default, the author of the post in WordPress will be you. If the actual author has not yet published a piece in The Peak, then you will need to add the author information to The Peak user database. You can check to see if the author is already listed by opening up the dropdown menu in the Author section of the WP post, which is located towards the bottom of the screen:

If the author is already listed, then you can just select the author name and save post.


How the Internet Works

The web. We use it everyday. It makes this very presentation possible. The Internet. The Web. So few people even know the distinction. That’s okay. Today the distinction is largely irrelevant to our everyday lives even as our lives are embedded in the network.

How did we get here? How did the web get to this point? More importantly, where are we going? Where is the Web, the Internet, going. The 21st century Internet is really dependent upon the people born in the 21st century: a generation already in college. For them to define the Internet of the next 30 years, they need to understand the last 50 years of the Internet. Everything we use today on the net has a direct connection to events 50 years ago. This is not merely a history lesson. This is a lesson about today and the future.

The desktop computer: all alone

If we go back a bit more than 30 years, to the 1980s, when I was in college, there were no computers in the classroom. A few students had an Apple computer but most had just a typewriter. I remember the business office for the college had a desktop computer, sitting all alone on an assistant’s desk. The math department in the science building had a minicomputer, a much larger system, with a series of terminals with monochrome screens.

The 1980s battle between Microsoft and Apple over the desktop computer was handily won by Microsoft, though now that’s a bit hard to imagine to a generation who have grown up using mostly Macs. The desktop computer, quite a bulky device, was a machine isolated in the home or office. It didn’t connect to anything else. Everything was installed by floppy disks, but the computer was a work horse for its time. Imagine it, sitting there on a desk doing its thing, with no other computer to talk to. Everything was stored on a series of floppy disks or on the quite small internal hard drive. The capabilities of the desktop computer in the 1980s was limited by the capacity of the hardware.

Computers talking to each other

In the 1980s, businesses increasingly took advantage of the ability to physically connect office computers into local area network (LAN). A cable would plug into the back of a computer. Originally, these cables were strung across the rooms, over the floors, and daisy-chained to each computer. Eventually, the cables were installed in the walls and computers were plugged directly into an outlet on a wall. You still see that today (look around the university for those Ethernet outlets), though the speed running through those cables are much greater than before.

The LAN was a great benefit to office productivity in the workplace. But you were still very limited to your local office environment in those days and even into the early 1990s.

Big computers talking to each other

But let’s go back to the 1960s and 1970s and see what was happening in the research laboratories of universities and government. That’s often where the innovation starts before it gets commercialized on a large scale to the public. The remarkable achievement in telecommunications that makes the Internet possible is a process called packet switching. Watch the following video that discusses how packet switching was developed. Pay particularly close to attention to the opening when the scientist explains the example of sending every page of a Bible to someone. His description is the core mechanism that transmits everything over the Internet today.

While the video is quite dated, from the early 2000s it seems, everything they talk about is still highly relevant today. These are core technologies that enable everything you do today on the Internet.

As you watch that video, note also around the 7 minute mark when he briefly describes how messaging and email evolved from a networked system sharing documents.

The video has a primarily British perspective but the experience of the time was largely the same in the USA. Around the 10-minute mark, they discuss the difficulties of deploying a packet switching network over a broad area. The telephone companies used an entirely different form of networking (circuit switching) to transmit voice calls from telephone to telephone. Telephone lines were everywhere, but those lines were low speed since that’s all that was required for voice. The phone companies were very resistant to changing their network infrastructure. Indeed, that change took decades, even into the early 2000s. And in the 1990s, connecting homes to the Internet became a battle between phone companies and cable companies. The cable companies found themselves in a better position since large cables had to be installed in the homes to deliver cable TV.

In the USA, the government had an initiative called Defense Advanced Research Projects Agency (DARPA), being operated out of the Department of Defense. DARPA worked with research universities in the US that were developing their own networks so that scientists could communicate with each other and perform scientific analysis on large, expensive mainframe computers.

So, think about all the individual local networks existing in isolation, not connected to each other.

Internet: a network of networks

An internet is defined as a network of networks, i.e., one network connected to another network forms an internet (lowercase ‘i’). When networks started connecting to other networks all over the world and using the same technology of packet switching, then that initiative became known as the Internet (uppercase “I”). This is why the word Internet usually starts with a capital letter since it’s referring to a proper noun and not the generic term for networks connected to each other. In reality, it doesn’t really matter whether you use uppercase or lowercase these days. Most people don’t know what the term internet even means other than that big network that spans the globe. (Think about the similarities of the word internet with the word interstate, particularly the interstate highways. How often do you just say the word, Interstate, without any further designation other than perhaps the specific route, I-81. The prefix “inter” in internet is used in the same conceptual way as “inter” is used in interstate.)

Remember the example from the video above about sending a Bible page by page? Breaking down content into packets and then sending each individual packet separately over the network to its destination, all of which now happens in milliseconds, is a bit of a difficult concept to wrap your minds around. Fortunately, the detailed aspects are not needed for most web programming. Primarily, you need to understand the concept and know that the details are handled through software and hardware developed by engineers who are working at an entirely different level of abstraction.

Indeed, an abstract model actually exists that helps us understand the concepts of how the Internet works.

Internet protocols

Let’s take a look at the protocols that make the Internet actually work. Again, you use these everyday without realizing it. You even see some of these terms everyday, like HTTP, but you may have no idea as to what it signifies. Internet protocols define how the Internet works. In the earlier video above, you viewed the British discussion on the development of packet switching. In that video, they touched upon corresponding developments in the USA. Two Americans most involved in developing the early Internet were Vinton Cerf and Bob Kahn. In 2004, Cerf and Kahn received the Turing Award from the Association for Computing Machinery. The Turing Award is often described as the Nobel Prize for computing. When they accepted the award, they held an insightful discussion on the evolution of the Internet. W

The video starts at the 13 minute mark, after the introductions. You can stop watching when the Q&A starts at the end of their discussion.

As you watch the Cerf/Kahn video, listen for key concepts, such as

  • open
  • layer
  • gateway/routing
  • security

Always be thinking that what they are explaining is how to approach the complexity of understanding how the Internet works. By modeling that complexity, they were able to build mechanisms that took concepts from ideas to implementations in the real-world. With tremendous foresight, they created an open system that anyone can build on top of to create new systems. Kahn describes the open network as a cafeteria model where you pick, from a large variety of services, what you want to use.

In contrast, a closed model is a service that is self-contained. Think about Facebook, which exists on the open network. But within Facebook, everything you do is controlled by Facebook. The possibilities of what you can create within FB is not open to you, those possibilities are closed to you except in the way that FB wants you to do something. Notice the distinction between open and closed systems?

Cerf talks about layers, like a staircase where each step (each layer) leads to another step (layer). In the early days of network development in the USA, these guys (Cerf & Kahn) could make the decisions just among themselves as to how things worked. But, again, with foresight, they wanted to get the community of people who used the Internet involved in planning, decision-making, and implementing how the Internet would evolve. The Internet Engineering Task Force (IETF) emerged as the primary force behind protocol development for the Internet. The IETF is still very active today.

Working online

For decades now, the IETF has conducted most of its work online via email and shared documents. Occasional meetings throughout the world solidifies the work of the IETF. The accomplishments of the IETF, through this distributed work model, is really phenomenal. And it has demonstrated, for decades now, that location independent work is entirely feasible and highly productive.

Then there’s the Web …

This post focuses on the Internet. Remember, the Web rides on top of the Internet layers. I’ll describe more about the evolution of the Web and development of Web standards in another post.


Weekly 1-minute summary

In the syllabus you see something called one-minute summary for Week 1, etc.

That’s a task you should do for yourself. You do not submit it to me. I’ll never see it. Now is the time to start developing habits of mind for yourself.

At the end of each week, take a minute or however long you need, to jot down a few notes on what you learned this week in this course. Indeed, you might want to do this for all your courses, or even for your life in general.

If you’re not sure what to write about, if you’re not sure that you learned anything during the week, then here are some possibilities for you to reflect upon. Only choose 1 of these if you’re not sure what to write about. Don’t try to respond to all these prompts every week, though I do know people who actually spend a couple of hours at the end of every week thinking deeply about what they did that week. That’s great. I don’t do that myself. Do what works for you. Be aware of managing your time, but at least give yourself one-minute every week where you reflect on that week. (Remember, you’re not submitting this to me at all; this is for you.)

  • Try to state in 3 complete sentences the key points of the week.
  • Each week of the course has at least one essential question: write down what new insights you have learned about that topic.
  • have any of your interactions with other students in the course changed the way that you perceive what you are learning?
  • If you learned a new tool this week, describe your reaction to it. How would you use this tool in the future? How would you improve it?
  • Has your learning process changed?
  • What became clear to you that was previously very confusing?
  • What connections are emerging between this course and your other courses or your everyday life? You use technology everyday. How are you understanding it a bit better every week?
  • What improvements are you noticing in your own skills at staying organized, studying, or even interacting with others?
  • Did you try any new learning strategies? Were they effective?
  • How can you improve your learning strategies? Note: think in terms of learning and not studying. Studying is something you do for an exam. Learning is something you will do throughout your life even when there is no grade.
  • What mistakes have you made this week. Remember, you’re writing only to yourself. You can be candid and honest with yourself.
  • What gave you the most pride during the week? What gave you a real sense of accomplishment?

Ultimately, when you think about what you learned during the week, what you are doing is actually learning about yourself.

[Several of the prompts above were adapted from Linda Nilson’s book Creating Self-Regulated Learners: Strategies to Strengthen Students’ Self-Awareness and Learning Skills.