Automatically translated.View original post

css box model

# Web Site Writing Basics

The CSS Box Model is a format that describes how to manage and place HTML elements in a web page. Each element is seen as a rectangular box with components: Content, Padding, Border, and Margin.

Components of the CSS Box Model:

Contents:

A section that shows the actual content of an element, such as text, images, or video.

Paddling:

The empty space between the content and the edges of the elements.

Border:

Border surrounding content and spacing (padding).

Margin:

The empty space outside the edge of an element determines the distance between it and other elements.

Box Model Operation:

The browser uses the CSS Box Model to calculate the size and position of each element on a web page. Understanding the Box Model allows us to accurately control the placement and size of the elements. Setting features such as width (width), height (height), spacing (padding), edges (border) and margins (margin) will affect the size and shape of the box.

Benefits of Box Model:

Element placement:

Box Model allows us to control the precise placement of elements on web pages.

Size Designation:

We can freely determine the size of the elements (width, height) and the free space around the content (padding, margin).

Creating a complex layout:

With the Box Model, we can create complex and beautiful layouts.

Example:

Suppose we have a div element with text content, and we want to have a distance around the text and a border, we can use the Box Model to configure the following:

Code

. My-element {

width: 200px; / * Define content width * /

Height: 100px; / * Determine content height * /

Padding: 20px; / * Define the spacing around 20px content * /

Border: 2x solid black; / * Define 2px thick black border * /

Margin: 10px; / * Define 10px margin * /

}

Based on this example, the box of .my-element will contain content (text), spacing (padding) 20px, edge (border) 2px, and margin (margin) 10px.

2025/8/19 Edited to

... Read moreเมื่อเข้าใจส่วนประกอบหลักของ CSS Box Model แล้ว การปรับใช้แต่ละส่วนเพื่อตอบโจทย์การจัดตำแหน่งบนหน้าเว็บจะช่วยพัฒนาเลย์เอาต์ให้มีความสวยงามและใช้งานได้ดีขึ้น ในประสบการณ์ส่วนตัว ผมมักใช้ Margin เพื่อเว้นระยะห่างระหว่างกล่องแต่ละองค์ประกอบให้เหมาะสม ลดความแน่นของหน้าจอ และใช้ Padding เพื่อเพิ่มพื้นที่ว่างภายในกล่อง ช่วยให้เนื้อหาไม่ติดขอบเกินไป ทำให้อ่านง่ายและดูเป็นระเบียบ นอกจากนี้ Border ก็เป็นตัวช่วยเน้นกรอบขององค์ประกอบแต่ต้องระวังขนาดของเส้นขอบไม่ควรหนาหรือบางเกินไปเพราะส่งผลกระทบกับขนาดกล่องโดยรวม และถ้าต้องการจัดตำแหน่งองค์ประกอบแบบละเอียด การใช้ค่า width, height ควบคู่กับ box-sizing จะช่วยให้กำหนดขนาดรวมขอบและระยะขอบได้ตรงตามที่ออกแบบไว้ อย่าลืมว่าการใช้ Box Model ร่วมกับเทคนิคการจัดตำแหน่งอื่นๆ เช่น flexbox หรือ grid จะช่วยเพิ่มความยืดหยุ่นและสร้างเลย์เอาต์ที่ซับซ้อนและตอบโจทย์ความต้องการใช้งานได้อย่างดีแบบครบวงจรมากขึ้น

Related posts

The image introduces 'CSS ESSENTIALS Part 5: THE CSS BOX MODEL,' displaying a diagram of nested boxes representing Margin, Padding, and Content. It asks, 'Ever wonder how every element's size is really calculated?'
This image defines 'What Is the Box Model?' showing a diagram of nested boxes: Margin, Border, Padding, and Content. It lists these four components as making up every HTML element's rectangular box.
The image focuses on the 'Content Area,' illustrating a white rectangular box labeled 'Content' with dimensions 100px height and 200px width. It states that the content box holds text, images, or other elements.
The CSS Box Model Made Simple
The CSS box model is your secret to pixel-perfect layouts! Learn how content, padding, border, and margin all stack up—and why box-sizing: border-box can save your sanity #CSSBoxModel #WebDesign #FrontendDev #LearnCSS #codewithaysha
Aysha

Aysha

5 likes

CSS Cheat Sheet
Essential CSS tricks every developer needs! 🔥 Save this for your next project - covers flexbox, grid, animations, and responsive design in one handy reference. Perfect for beginners and pros alike! 💻✨ #CSS #WebDevelopment #Coding #Programming #Developer
EM

EM

4 likes

A dark blue background with the title 'CSS KNOWLEDGE TEST!' and a purple lightbulb icon. Text asks 'How many can you get right? comment your score below!' with a Lemon8 logo and username.
A dark blue background with a white box containing 'Q1: What does the CSS property justify-content: space-between; do?' and four multiple-choice options (A-D).
A dark blue background with a white box containing 'Q2: Which unit is relative to the parent element's font size?' and four multiple-choice options (A-D).
💡 Think you know CSS? Let’s find out!
💡 Think you know CSS? Let’s find out! Take this short quiz and see how many you get right 😎 Comment your score below 👇 #CodeWithAysha #CSSQuiz #LearnToCode
Aysha

Aysha

3 likes

Wheels 😎 Tires 😎 Inbox your year make and model!
#gettoknowme Texarkana Tire & Wheel
TexarkanaTireAndWheel

TexarkanaTireAndWheel

3 likes

Clay Sardine Trinket Box 🐟🍅
Using air-dry clay to make a sardine can trinket box! 🐟 This is the second piece of functional art in my “Nostalgic Food” series which commemorates the main ingredient for an underrated Vietnamese comfort dish called “Bánh Mì Cá Mòi”. 🐟🍅🥖 #claycraft #clayart #functionalart #jewelrybox
TRIPLE THR3AT Art

TRIPLE THR3AT Art

640 likes

Model Lighting Tutorial (1) — Guide to LED Types
My inbox has been flooded with requests for lighting tips lately (I'm truly impressed!). Today, we're kicking off our Model Lighting Tutorial series! First up, let's explore four types of commonly used LEDs: ① Single-color LEDs (great for beginners) ② RGB LEDs (for stunning color
Zion Marvelous Workshop

Zion Marvelous Workshop

3 likes

A dark blue cover page titled "Beginner-Friendly CSS Visual Guide" with a CSS file icon, inviting users to master CSS basics and style websites like a pro. The Lemon8 logo and username are at the bottom.
A dark blue slide introducing CSS, defining it as Cascading Style Sheets for styling HTML elements. It shows a CSS icon and provides examples of CSS syntax with a selector, property, and value.
A dark blue slide explaining CSS Selectors. It features a diagram showing a CSS file icon branching to 'p', 'div', 'class', and 'id' selectors, with text describing common selector types and their usage.
Beginner-Friendly CSS Visual Guide
#cssforbeginners #frontenddevelopment #cssvisualguide #codingforbeginners #htmlandcss
Aysha

Aysha

9 likes

The cover image for a CSS Cheatsheet for Beginners, featuring the CSS3 logo and the text "Learn the most-used properties in one place!" on a dark blue background.
A CSS Cheatsheet section detailing properties for Background (color, image, repeat, position, size), Border (border, radius, top), and Outline (outline, offset) with example values.
A CSS Cheatsheet section outlining properties for Position (relative, top, left, z-index), Size & Dimension (width, height, max-width), and Float & Clear (float, clear) with example values.
CSS CHEATSHEET for Beginners
#css3cheatsheet #learncss #webdesignbasics #frontendtips #codingforbeginners
Aysha

Aysha

31 likes

Miniso Blind box unboxing 🌈
I got my top pull !!! @MINISO these are straight from the tik tok shop #mickeymouse #hello kitty #blindbox #Unboxing #Lemon8
✨LEXI ✨

✨LEXI ✨

17 likes

How To Land 600+ Brands In Your Inbox
Gatekeeping never been my thang 🚫 I just dropped the biggest bomb yet, The Brands List gives you access to 600+ direct contacts at fashion, beauty, lifestyle, skincare, and home brands. These aren’t cold DMs or random emails—these are real connections that lead to real opportunities. I created
Chanelle Renee

Chanelle Renee

2 likes

HTML and Css Fundamentals.
1. Core HTML Elements: Defines HTML as the "skeleton" of a website, explaining the use of h1 to h6 for headings, <p> for paragraphs, and styling tags like <strong> for importance, <em> for emphasis, <sub> for subscripts, and <sup> for superscripts. 2. Lists
ZeroandoneHQ

ZeroandoneHQ

1 like

The Easiest Online Business Model No One Explains
Vlogmas Day 2 is here, and today we’re breaking down one of the simplest ways to start earning from home… affiliate marketing. If you’re brand new, here’s the easiest way to think about it: Affiliate marketing is when you share products or services you genuinely like, and when someone buys th
Internet Incomes

Internet Incomes

0 likes

Close-up of a green luxury sedan's front wheel. It features a black multi-spoke custom forged wheel, performance tire (255/35 ZR 21), and a red multi-piston brake caliper. The car's headlight with "BMW LED" is partially visible.
Front quarter view of a green luxury sedan. The car's sleek headlight with "BMW LED" is prominent, alongside a black multi-spoke custom forged wheel and a red multi-piston brake caliper. Reflections are visible on the car's paint.
Side view of a green luxury sedan's rear wheel. It shows a black multi-spoke custom forged wheel with a performance tire (285/30 ZR 21). The car's door handle and reflective green paint are also visible.
If the 5 Series looked this good straight from the factory, would it really get so much hate online? Let’s be real— the short-wheelbase 5 Series looks so much more proportional than the long-wheelbase version. The Cape York Green with Burgundy Red interior completely stole my heart. Upgraded w
Kathy Qin462

Kathy Qin462

3 likes

A dark blue graphic titled 'CSS Tips to Write Cleaner & Shorter Code!' with a lightbulb and CSS file icon. It displays a code snippet `margin: 10px 20px;` and text encouraging beginners to cut down on repetition and level up their styling game.
A graphic demonstrating CSS margin and padding shorthand. It contrasts separate `margin-top`, `margin-right`, `margin-bottom`, `margin-left` properties with the concise `margin: 10px 20px;` shorthand, explaining 10px for top/bottom and 20px for left/right.
A graphic illustrating CSS font shorthand. It compares multiple font properties like `font-style`, `font-weight`, `font-size`, `line-height`, and `font-family` with the single-line shorthand `font: italic bold 16px/1.5 'Poppins', sans-serif;` for cleaner code.
CSS Tips to Write Cleaner & Shorter Code!
#csstips #webdevelopment #learntocode #frontendtips #codebetter
Aysha

Aysha

20 likes

Satisfying Unboxing: The Clearest Reptile Box! ✨🦎
If you love the ASMR of new pet gear, you need to see this! I just put together this assembly-model enclosure. The panels are incredibly clear, and the base is a solid, leak-proof piece. It feels super stable once all the clips are in. Perfect for spiders or small reptiles! 🕸️ #Lemon8Pets #P
TXacrylicdecrofactory

TXacrylicdecrofactory

3 likes

Chicago Model Call
Saturday, February 21 | Chicago Looking for a brunette or redhead that wants to go solid platinum blonde, no dimension. Curly/ textured hair preferred, but all hair types welcome. No bleach and tones, full transformation only No box dye Must be comfortable on camera Must be fun
Sabrina Bias

Sabrina Bias

0 likes

Chevron-Style Breadcrumb Navigation in CSS
#webdesign #codinglife #studytips #codingforbeginners #breadcrumbs
Aysha

Aysha

5 likes

This is the best #carstoragebox
An awesome #organizer that adds extra storage to your #TeslaModel3 or #TeslaModelY ! Purchased from: https://tesfavs.com/
TesFavs

TesFavs

6 likes

The image introduces "HTML + CSS IN ACTION: 30 Days of Mini Projects Modal Popup," showcasing a modal example with text "This is a Modal" and an "Open Modal" button. It highlights "Pop up power—no JavaScript needed" for Day 23, by Code With Aysha.
This image defines a modal popup as a small overlay that captures user attention and "locks" the screen. It displays a side panel with "Quick Settings" including Dark Mode, Font Size, Accent Color, Animations, Notifications, and Quick Links.
The image explains why building modals with HTML + CSS matters, demonstrating a "Page" and an "Overlay + Centered Card" modal. It emphasizes learning CSS selectors, visibility control, layering, transitions, and responsive centering without JavaScript.
Build a Sleek Slide-in Side Panel with HTML CSS
Build a modern slide-in side panel using only HTML and CSS! Perfect for quick settings, theme controls, and navigation links. Fully responsive and beginner-friendly — no JavaScript required. #HTMLCSS #WebDesign #FrontendDevelopment #codewithaysha
Aysha

Aysha

5 likes

Hogwarts box - Harry Potter
It came with stationary thought it’s too pretty to throw away. Using it to store HP memories rn Thanx 4 following! YT|IG|TT 💚⚡️🐍 #harrypotter #wizardingworld #Slytherin #harrypottercollector #harrypotterfan
AzkabanFamily

AzkabanFamily

82 likes

Modelones Cat eye polish!
#cat eye nails #unfiltered #nailinspo #beautyfinds #gelxdesign 💌 Brand: @modelones 💌 Brand: @BTArtboxnails
Jess

Jess

4 likes

Front of the Pip-Boy 3000 collector's edition box, featuring a schematic of the device, 'STANDARD ISSUE,' 'DELUXE CHRONOMETER,' and an 'INSPECTED BY 13' stamp. Stock number is also visible.
Side of the Pip-Boy 3000 box, showing a schematic of the device with 'STATS ITEMS DATA' buttons and a separate illustration of the Pip-Boy on a stand. Labeled 'DELUXE CHRONOMETER'.
Side of the Pip-Boy 3000 box displaying multiple schematics of the device from various angles, including front, side, and top views. The text 'MADE IN CHINA' is visible.
Pipyboy 3000 collector's edition box.
full 360° of the box for the original wearable Pipboy. posting this for archive purposes. #fallout #fallout3 #collectorsedition #pipboy3000 #collectibles
albhednomad

albhednomad

1 like

Pink Swap Box
Love swapping pink boxes with my fellow girls if you want to be involved in a swap DME on Instagram #pinkswap
Eliza Disney Lifestyle Content

Eliza Disney Lifestyle Content

9 likes

🫶Plastic Transparent Cosmetics Storage Box🛍
Plastic Transparent Cosmetics Storage Box Product information: Color: [upgrade pattern 3 layers] display stand-independent paper box packaging, [upgrade style 4 layers] display stand-independent paper box packaging, [upgrade style 5 layers] display stand-independent paper box packaging, [Upgrad
Scotn Ichols

Scotn Ichols

12 likes

The image introduces CSS Backgrounds, Part 10 of CSS Essentials. It shows the `background` property using `linear-gradient` to define style and color, encouraging users to make layouts pop with background styling.
This image explains the `background-color` property, demonstrating how to set an element's base color using a hex code. It highlights its use for creating contrast, branding, or clarity in web design.
The image illustrates the `background-image` property, showing how to add an image behind content using `url('pattern.png')`. It suggests using this property to add texture or branding flair to web elements.
CSS Backgrounds – Color, Images & Control
#CSSBackgrounds #LearnCSS #CSSForBeginners #FrontendTips #codewithaysha
Aysha

Aysha

11 likes

A display of various 'Mystery Box' options at Second and Charles, including boxes for 50 DVDs/Blu-Rays, 100 Music CDs, and 6 Fiction Books. The image highlights the 'Second and Charles Fiction Mystery Box' with a price range of $25-30.
A book cover for 'Nine Perfect Strangers' by Liane Moriarty, a #1 New York Times Bestselling Author. The cover features a colorful smoke design and mentions a Hulu Original Series. Text describes the plot of a wellness resort.
A book cover for 'Where Are The Children?' by Mary Higgins Clark, described as a psychological thriller. The cover shows a house with a swing set in a field. Text summarizes the plot about a mother whose children vanish.
Second and Charles Fiction mystery box
Second and Charles mystery box haul! 6 mystery fiction books for $25. Second and Charles buys and sells books, comics, games,and more! This was my first time going and I definitely would go back! You can also shop all their locations inventory online! Have you read any of these books? What’
TheKayleeEdit

TheKayleeEdit

9 likes

A cover image for an HTML + CSS project titled 'Parallax Sunset Mountains', featuring a stylized sunset with dark mountains and trees, highlighting it as 'Day 27' of mini-projects by Code With Aysha.
An explanation of the parallax effect, defining it as layers moving at different speeds during scrolling to create depth, motion, and a realistic 3D look using pure CSS, with an example of mountains.
An illustration detailing the anatomy of a parallax scene, showing sun/sky as the back layer, distant mountains as the mid layer, trees as the front layer, and birds as foreground animation.
Parallax Sunset Mountains (HTML + CSS Project)
In this mini-project, we create a beautiful parallax landscape using pure HTML + CSS — no JavaScript needed. The scene includes: 🌞 glowing sunset ⛰️ layered mountains 🌲 dark forest silhouette #HTMLCSS #Parallax #WebDesign #codewithaysha
Aysha

Aysha

4 likes

See more