Basic CSS Concepts: A Beginner’s Introduction

If you’ve ever wondered how web pages are made beautiful, dynamic, and visually appealing, the answer lies in Cascading Style Sheets (CSS). It is a fundamental web technology that allows developers to control the presentation and layout of HTML documents, making it an essential skill for anyone aspiring to become a web designer or front-end developer. This post is part four of my ‘Getting Started In Coding‘ series. It will walk you through some basic CSS concepts to get you started on your journey, but is not a tutorial. I do assume though that you would probably have read the preceding article on HTML.

What is CSS?

Cascading Style Sheets, commonly known as CSS, is a stylesheet language which we use to define the visual presentation of web documents written in HTML. With CSS, you can control various aspects of a webpage’s appearance, such as colours, fonts, layout, spacing and even animations. The “cascading” part of its name refers to the hierarchical application of styles, allowing for easy maintenance and flexibility; you will learn more about that as you progress.

How to Use CSS

There are several ways to apply CSS to an HTML document:

  1. Inline CSS: You can apply CSS directly to individual HTML elements using the style attribute. However, I would not recommend this method for larger projects; it mixes presentation with content and becomes harder to maintain.
  2. Internal CSS: Placing CSS code within the <style> tags in the <head> section of an HTML file allows you to apply styles to the entire page. This is useful for smaller projects or quick prototyping.
  3. External CSS: In this method, CSS code is written in a separate file with a .css extension and linked to the HTML document using the <link> element. This is the preferred and most efficient way of using CSS, especially for larger projects, as it promotes separation of concerns.

In the following sections, we’ll cover some basic CSS concepts to help you build a strong foundation in web design; nothing too deep, just the essentials.

Selectors and Properties

In CSS, selectors target specific HTML elements in a document, while properties define the desired visual appearance of those elements. Selectors can be html tags, classes, IDs, or even more complex patterns.

/* Selector: Targeting all paragraphs */
p {
  /* Property: Setting font size and color */
  font-size: 16px;
  color: #333333;
}
/* Selector: An ordered list within a specified element ID */
#myDiv ol {
  background-color: #fafafa;
  font-weight: bold;
}

Note that in the second example above, the targeted ID would be specified in the HTML document by:

<div id="myDiv">Some text</div>

Typography

CSS allows you to control the typography of your web pages, including font family, size, weight, style, and spacing.

/* Applying custom fonts and setting line height */
body {
  font-family: "Arial", sans-serif;
  font-size: 18px;
  line-height: 1.6;
}

Box Model

The box model is a fundamental concept in CSS that represents an HTML element as a rectangular box with four layers: content, padding, border, and margin. Understanding the box model is crucial for creating layouts and spacing elements on a webpage. It can seem a bit complex when you first try to align multiple elements on a page, but stick with it; you’re going to need to know this.

/* Creating a basic box container */
.box {
  width: 200px;
  height: 100px;
  padding: 20px;
  border: 2px solid #333;
  margin: 30px;
}

Flexbox

Flexbox is a more recent powerful layout model that makes it easier to distribute elements within a container. It allows you to create responsive and flexible designs without relying heavily on floats or positioning; for the moment you will just need to know that this means it can save you quite a few headaches.

/* Creating a basic flex container */
.container {
  display: flex;
  justify-content: center; /* Horizontally centres items */
  align-items: center; /* Vertically centres items */
}

CSS Grid

Similar to Flexbox, CSS Grid is a layout system that enables two-dimensional grid layouts. It offers more control over rows, columns, and their alignment, making it ideal for complex designs. Again, it is a more recent development that allows you to make customised layouts more easily.

/* Creating a basic grid container */
.container {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr; /* Three equal columns */
  grid-gap: 10px; /* Spacing between grid items */
}

Learning Resources

Ready to dive deeper into CSS? Here are some a couple of excellent online resources to expand your knowledge:

  1. MDN Web Docs – CSS: A comprehensive guide to CSS concepts with examples and references.
  2. freeCodeCamp: A learning platform with interactive CSS tutorials and projects.

In Summary:

CSS is an essential skill for web designers and front-end developers. Understanding the basic CSS concepts, such as selectors, properties, the box model, Flexbox, and CSS Grid will empower you to create the visual impact and responsiveness you need in your web pages. So, roll up your sleeves, and get ready to practice and experiment with CSS. The world of web design is waiting for you to explore!

Starting Off With HTML – A Brief Introduction

When you’re starting off with HTML, you need to understand the basic structure of an HTML document (who’d have thought it!). It’s really not that tricky once you have the basics sorted. This post is part three of my ‘Getting Started In Coding‘ series. It will give you a few tips to start you off on your learning journey with HTML, but is not a tutorial.

The Basic Structure Of An HTML Document

All HTML documents consist of a series of elements, enclosed by their start and end ‘tags’. Tags are generally of the form:

<tag-name>the contents of the element</tag-name>

Angle brackets <> enclose the tag. Each tag performs a stylistic and/or semantic function, informing the browser how to display any enclosed text amongst other things.

Every HTML document begins with a doctype declaration, which tells browsers that this is indeed an HTML document. Immediately following will be a pair of starting and closing ‘html’ tags which delineate the actual HTML content of the page. For an HTML5 document (don’t worry about other versions for the moment), it looks something like this:

<!DOCTYPE html>
<html>
the actual page content goes here...
</html>
Continue reading “Starting Off With HTML – A Brief Introduction”

How To Go About Choosing Your First Programming Language

It may seem obvious that web development is the way to go if you want to learn coding. Certainly it is a hugely in-demand skill, but it is by no means the only path available. The safest course is to investigate the plethora of options in a bewildering array of industries before honing in on one as a career path. Ultimately it will have a significant impact on choosing your first programming language to learn.

First Steps

You may, of course already have an idea of a particular target industry to work in. If that is the case you should probably begin by:

  • Researching the technologies and languages that are most common in that field.
  • Check out the job sites to see what kind of positions are available at the moment. Cross-check the required skillsets with your list from the first step.
  • Look up the available learning resources, online courses (paid-for or free), tutorial sites, classic text books, YouTube videos etc. You may think that only paid-for services will be worthwhile; but there is a wealth of excellent information available. And many programmers are very generous in sharing their expertise. Apparently some experts are even advocating the use of AI language models like ChatGPT as a learning resource for coding.
Continue reading “How To Go About Choosing Your First Programming Language”

So You Want To Learn To Code?

People choose to learn to code for a multitude of reasons. This article aims to assist those with little or no prior experience in computer programming who want to learn to code and are not sure where to begin. It may also be of use to those who, like me, had taken a long period out of the industry and decided to return. It is part of my series on starting a career in coding, which can be found here. In any case, whether you’re just starting out in your career, returning to the workforce after some time out or just feel it’s time for a change in direction, you should take the time to consider a few important factors up front.

Before we begin in earnest there are a coupe of points I would like to make.

Firstly, although in my case I did have plenty of coding experience, it was in outdated languages and architecture which were no longer in high demand. This meant that I would need to re-invent my skillset. This is not in itself an insubstantial undertaking. There are however fundamental principles of coding which apply to almost all languages with which I was already familiar. The newcomer will be introduced to many of those as they learn their first programming language. After this, the learning curve tends to reduce with subsequent languages.

Secondly, I should point out here that there are many possible ways to learn to code. The path I set out here may not resonate with everyone; that is perfectly ok. I am just trying to set out some helpful markers to get started on what can be a long and complicated journey.

You Have Some Important Decisions To Make

Begin by asking yourself…

What Do You Want From This Journey?

Only you will know what you are hoping to achieve when you choose to learn to code. If you want a new hobby, you may choose to invest less time and effort in the process. You will still want to be thorough, but may not be on a particular schedule to learn. Those seeking a career-change may have set deadlines by which they want to move. This may require more of your free time and dedication to achieve.

Either way, you should prepare yourself accordingly for the effort ahead, and set aside appropriate amounts of time for the purpose.

Where Do Your Interests Lie?

There are opportunities to write code in almost every industry out there, but some of them may align more with your interests and passions. We spend so many of our waking hours at work. It seems unthinkable that we should do so in settings that don’t inspire us, and yet…

Aside from this important consideration, there may be implications for which language you learn first. If you have a strong desire to work in a particular field, the in-demand skills for that field will guide your choices.

What Are Your Strengths?

At the risk of getting too deep, this is an important consideration. I do believe that most people have the ability to learn to code, and to do it well. As with most professions, the quality of teaching and mentoring will have a huge impact on your eventual success. But some will still find it easier than others to learn to code, and to move forward from there. To avoid setting out on a path to frustration, consider…

Mindset

The type of mindset that lends itself well to coding has:

  • good analytical skills
  • the ability to think methodically and logically
  • strong creative problem-solving capabilities

As you progress in your career:

  • the ability to translate technical briefs into reality
  • motivation to learn new technical skills in a constantly evolving field

Soft Skills

A career in coding will most likely require:

  • patience
  • teamwork
  • decision-making skills
  • organisational skills

As you progress in your career:

  • the ability to communicate complex technical subjects with clarity
  • the ability to help others to follow technical processes

In Summary

Try not to wade in too quickly. The last thing you want is to invest your time in learning skills which don’t directly translate to achieving your goals. With some careful thought up front, you will not just be able to learn to code, but to do it well in an environment that inspires you.

The time you spend at this stage will help you decide what you want to achieve when you learn to code; look on it as a worthwhile investment in yourself. The next article in this series takes a closer look at choosing your first programming language to learn; you can read it here.