Urgent.News

What's breaking now, across thousands of outlets.

Tech

How CSS Controls the Layout of a Webpage: A Beginner-Friendly Guide

Have you ever looked at a webpage and wondered: “How did they get everything to sit exactly there?” The heading is at the top. The navigation links are arranged neatly. The cards sit beside each other. The button is aligned with the text. The sidebar stays where it belongs. And on a smaller screen, everything rearranges itself instead of becoming a complete mess. That isn't happening by accident.…

Have you ever marveled at a webpage and pondered how it perfectly aligns all its elements? The heading sits at the top, the navigation links are neatly arranged, the cards sit side by side, the button aligns with the text, and the sidebar stays in its designated spot. Even when viewed on a smaller screen, everything reorganizes itself without creating a chaotic mess.

This seamless arrangement is not accidental. It is made possible by CSS, the language that sets the stage for how elements are displayed, where they appear, their spacing, alignment, and relationships with other elements on the page.

CSS layout goes beyond merely changing colors, fonts, borders, and backgrounds. It dictates how elements are positioned, occupy space, align, and interact with one another. Once you grasp CSS layout, you are not just styling individual elements; you are learning how to orchestrate these elements to function harmoniously as a webpage.

To comprehend CSS layout, consider these HTML elements: My Website Welcome to my website. Learn More. HTML provides the elements, but HTML alone lacks the control over their visual arrangement. CSS comes into play here, allowing you to dictate aspects such as whether elements appear on separate lines, sit next to each other, maintain spacing between them, be arranged in rows or columns, stay in a fixed position, form multiple columns for a group of cards, and adapt the layout on smaller screens.

A crucial concept in CSS layout is the display property. The display property determines how an element contributes to the layout. For instance:

.container { display: block; }

Or:

.container { display: flex; }

Or:

.container { display: grid; }

Each of these values yields distinct layouts, making the understanding of display a fundamental step.

Some key display-related concepts for beginners include:

Block Elements: Block elements typically start on a new line and occupy the width of their parent container by default. Examples include headings and paragraphs, which naturally stack vertically, like boxes placed one below another.

Inline Elements: Inline elements flow alongside other content without automatically starting on a new line. Examples include links and emphasized text. They blend seamlessly within a line of text.

Inline-Block: This combines the characteristics of inline and block elements. For example, .card { display: inline-block; width: 200px; } allows elements to sit next to each other while still enabling control over dimensions like width and height.

Two powerful layout systems that build on display properties are Flexbox and CSS Grid. Flexbox helps arrange elements in a row or column, making it ideal for creating navigation bars, buttons, toolbars, card rows, form layouts, and aligning content. CSS Grid, on the other hand, excels when you need to work with both rows and columns simultaneously.

For instance, .container { display: grid; grid-template-columns: repeat(3, 1fr); } creates a three-column layout, ideal for image galleries, product cards, dashboards, website sections, and complex page structures.

It’s not necessary to memorize every Grid property right away. Instead, focus on understanding the concept of using Grid to arrange elements into rows and columns. Flexbox and Grid serve different purposes and can be utilized together. While Flexbox is best for one-dimensional layouts (rows or columns), Grid is suited for two-dimensional arrangements (rows and columns). A practical way to think about them is:

Flexbox: Think one direction—either a row or a column.

Grid: Think two directions—rows and columns.

For example, you could employ Grid to structure the overall layout of a dashboard and use Flexbox inside individual cards. CSS layout is not about committing to one tool exclusively. It’s about understanding which tool best fits the layout you wish to create. CSS layout empowers you to transform individual elements into a cohesive and functional webpage.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

One week after PHP2Shell: attacked in the wild, and now a Linux kernel flaw on top

On 21 October the PHP team released emergency updates for two critical flaws, CVE-2026-109618 and CVE-2026-109619 (“PHP2Shell”). Back then the question was how fast you could patch.

  • PHP released emergency updates for PHP2Shell flaws on 21 October
  • Linux kernel flaw CVE-2026-46300 allows root access exploitation
  • Combined threat can compromise servers and all associated sites and secrets

Three holes in a green CI, and a lock for the free plan

What this is about. On a site we worked on recently, the test pipeline went green across the board, and we looked into what green actually covered. Three things turned out not to be covered at all.

  • Three issues uncovered in green CI: missing tests, schema mismatches, and lack of wait mechanism.
  • Tests added to CI to address missing tests and schema mismatches.
  • Script implemented to wait for green CI status in private, free plan repository.

What are you doing this weekend?

Feel free to tell what you plan on doing this weekend and even ask for help or feedback. Please keep in mind it’s more than OK to do nothing at all too!

Your form needs an uncertain state, not just success and failure

Prepared with substantial AI assistance for StackEndBox. This article uses the company's public enquiry-controller code and synthetic local tests.

  • Implement four distinct states: ready, sending, received, and uncertain.
  • Transition from sent to received only with successful HTTP response and UUID-shaped reference.
  • Uncertain state indicates confirmation could not be confirmed, avoiding unsupported claims.

More from Friday 30 October →