iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🔎

Web App Structure and Design: HTML/CSS Roles and Responsive Design Basics

に公開2

Introduction

Hello. This is a learning record for "How to Make Web Apps with Python". In my previous post, I provided an overview of the entire backend technology landscape. This time, I learned about the basic roles and syntax of HTML and CSS, which constitute the frontend of web applications. Both technologies are deep, and I am once again overwhelmed by the high level of expressiveness in CSS. In this article, I will organize the roles of HTML and CSS, focusing specifically on the mechanism of responsive design—"changing the design without changing anything in the HTML."

1. HTML and CSS: Roles of Separating Structure and Style

HTML and CSS are technologies that complement each other's necessary parts in web service development.

Technology Role Features
HTML A markup language that defines the structure and content of web pages. It composes basic elements such as headings, paragraphs, lists, images, links, and forms. It is built as a tree structure called the DOM (Document Object Model).
CSS A language that specifies the style of elements defined in HTML. It specifies colors, fonts, layouts, margins, etc., to achieve a visually appealing design. It is important for maintaining design consistency throughout the site.

How to Write CSS

CSS is written in the format of "Selector," "Property," and "Value."

CSS-Selector {
  property: value;
  property: value;
}
  • Selector: Specifies the element you want to apply the style to (e.g., body, h1, .card, ul > li, etc.).
  • Property: Specifies the type of style you want to change (e.g., background-color, font-family, padding, etc.).

2. The Principle of Immutable HTML: Basics of Responsive Design

One thing that particularly surprised me while studying was the concept of responsive design: "By specifying CSS effectively, you can achieve designs suited for PC, tablet, and smartphone environments without changing anything in the HTML."
This phenomenon is realized by the principle of separation of roles between HTML and CSS, and the functions provided by CSS.

How Responsive Design Works (CSS Solves Everything)

Responsive design is possible because of the following principles of HTML and CSS:
1. Thorough Separation: HTML purely defines the "meaning of content," and CSS purely defines the "appearance of content." HTML does not need to hold environmental information such as screen size.
2. Media Queries: CSS has a feature (media queries) to apply different styles depending on the viewing environment, such as browser width, height, and resolution.
By using these media queries, you can write instructions in a CSS file like, "If the screen width is 768px or less, hide the sidebar and make the article width 100%." As a result, for the same HTML structure, CSS can dynamically switch the design according to the device.

3. Next Steps: The Path to CSS Mastery Using AI

HTML 'canvas' and advanced CSS layout expressions (Flexbox, Grid, etc.) are deep and take time to master. However, CSS has many patterned expressions, making it one of the areas where AI (such as ChatGPT and Gemini) excels most.

  • "Please write CSS for a card centered horizontally on the screen."
  • "Please add a media query for XX for responsive support."

By giving such specific instructions, AI will generate accurate CSS code. The expressiveness and usability of a web app depend heavily on your proficiency in HTML/CSS. I intend to use AI as a powerful assistant and improve my HTML/CSS skills in parallel with building backends in Python.

References

"How to Make Web Apps with Python" by Kujira Hikouki, Yoichi Sugiyama, Shunsuke Endo
https://www.socym.co.jp/book/1496

Discussion

hiroakiKodyhiroakiKody

juner さん。コメントありがとうございます。Webデザインの最新技術に関する貴重なご意見、ありがとうございます。
CSSについて不勉強なので、大変参考になります。
**コンテナクエリ(Container Queries)**について知らなかったので、ブログの内容と合わせてAIに尋ねてみました。

ご指摘の通り、**コンテナクエリ(Container Queries)**は、現代のレスポンシブデザインにおいて非常に強力な新しいアプローチですね。

まさにおっしゃる通り、Webアプリのコンポーネント指向が進む中で、グローバルなビューポート(ブラウザの幅)を参照するメディアクエリだけでは限界がありました。

メディアクエリとコンテナクエリの使い分け

ブログ記事では「レスポンシブデザインの基礎」としてメディアクエリを紹介しましたが、開発現場のベストプラクティスとしては、以下のように使い分けるのが理想的です。

  1. メディアクエリ: ページの全体的なレイアウトや、主要なナビゲーションの切り替えなど、「ページ全体」の振る舞いを定義する際に適しています。
  2. コンテナクエリ: ウィジェットやカード、リストアイテムなどの個別のコンポーネントが、親要素のサイズに応じて独立してスタイルを変更する際に最適です。これにより、コンポーネントの再利用性が飛躍的に向上します。

私も現在学習している『PythonでつくるWebアプリのつくり方』からさらにステップアップし、Reactのようなコンポーネントベースの技術に進む際には、このコンテナクエリを積極的に活用し、デザインの柔軟性を高めていきたいと考えています。

最新の情報提供、感謝いたします!引き続き、Web開発とMCPの学習を頑張ります。