DEV Community

Cover image for CSS Layout
Davey
Davey

Posted on • Edited on • Originally published at dave-s.Medium

4

CSS Layout

Introduction

Today is day 4 of my 30 Days of CSS, and I've been learning about CSS layouts using "float". This seems like a good start to me and should form a good foundation that I can expand upon and learn CSS Grid and Flexbox in the coming days. You can follow my progress on Twitter @cloudblogaas

Today's Problem

To challenge myself, I've decided that I should try and made a basic two column blog layout using CSS.

The Solution

The first step to developing this layout, is to add a wrapper class so that I can place the blog in the center of the page. This is done using the following CSS which sets the width of the wrapper to 80% of the page width and centers it automatically.

.wrapper {
  max-width: 80%;
  margin: auto;
}
Enter fullscreen mode Exit fullscreen mode

To implement the columns within the wrapper, I've basically created 2 classes:

.mainColumn {
  float: left;
  width:75%;
  background: red;
}
.sidebar {
  float: right;
  width: 25%;
  background: yellow;
}
Enter fullscreen mode Exit fullscreen mode

The .mainColumn class is defined as 75% of the width of its container and is floated to the left. The .sidebar container is 25% of the container and is floated to the right.

I've then added a bit of styling to add a margin and separate the layout slightly.

.panel {
  margin: 10px;
  background: white;
}

.mainColumn p, .mainColumn h1 {
  margin: 10px;
  line-height: 1.5;
  background: white;
}
Enter fullscreen mode Exit fullscreen mode

The HTML for the page is basically a few divs to give me the wrapper and columns that I want.

<div class="wrapper">
  <h1>Minimal Blog Page Layout</h1>
  <div class="mainColumn">
    <h1>Heading</h1>
    <p>...</p>
    <p>...</p>
    <p>...</p>
    </div>
  <div class="sidebar">
  <div class="panel">
    <h2>Heading</h2>
    <p>...</p>
  </div>
      <div class="panel">
    <h2>Heading</h2>
    <p>...</p>
  </div>
      <div class="panel">
    <h2>Heading</h2>
    <p>...</p>
  </div>
</div>
Enter fullscreen mode Exit fullscreen mode

And that's it. The main work here is the div's that float:left and float:right.

You can see a working version of the page on my CodePen:

Resources

I've been following a series on YouTube by The Net Ninja on CSS Positioning:

Image of Checkly

4 Playwright Locators Explained: Which One Should You Use?

- locator('.cta'): Fast but brittle
- getByText('Click me'): User-facing, but can miss broken accessibility
- getByRole('button', { name: 'Click me' }): Most robust, best for a11y
- getByTestId('cta-button'): Stable, but ignores UX

Watch video

Top comments (0)

Image of DataStax

AI Agents Made Easy with Langflow

Connect models, vector stores, memory and other AI building blocks with the click of a button to build and deploy AI-powered agents.

Get started for free

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay