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

A pink graphic lists raw hair vendors including Lady Hair, Yolissa Hair, Derun Hair Company, and Hair Boutique India, with contact details and websites, against a background of hair bundles.
A pink graphic lists raw hair vendors including Wealthy Hair, XBL Hair, Good HairFactory, and One More Hair, with contact details and websites, against a background of hair bundles.
A pink graphic lists lash vendors such as Gianni Lashes, QuinDao Yaleo, Aupres Lashes, SY Lashes, World Beauty Eyelashes, and Elour Beauty Factory, with their websites, against a background of packaged false eyelashes.
Some vendors
Start a business today and thank me later!!!
Bossgirlsbeauty

Bossgirlsbeauty

605 likes

This image shows the title slide for an article on "PRODUCTIVITY HACKS How to Get Sh*t Done!", featuring bold text over a background of a desk with handwritten notes, sticky notes, and a planner, setting the stage for productivity tips.
A hand holds a green sticky note illustrating the "EAT THE FROG" productivity hack. It features a drawing of a frog and text advising to "Do your most challenging task at the start of your day," aligning with the article's explanation.
A hand holds a green sticky note detailing the "KANBAN BOARD" method. The note displays a diagram with "To Do," "Working On," and "Complete" columns, illustrating how to categorize tasks into three groups as described in the article.
9 Productivity Hacks: Finish What You Started
There are many techniques that help you finish your coursework, home chores, or just normal life tasks. Sometimes they can pile up and become overwhelming. Here are 9 productivity hacks that help me finish things, like this blog 😊: EAT THE FROG The “frog” is considered your most important and d
Jau 🤎

Jau 🤎

3008 likes

A model with long dark hair, wearing a white top and jeans, looks over her shoulder and blows a kiss in a beauty store. Text overlay reads "Models Beauty Secrets."
A collage featuring Naomi Campbell, showing her hands, various facial expressions, and full body shots. Text describes her body care, nail care, and skincare routine, including cleansing, exfoliating, and using natural oils.
A collage featuring Adriana Lima, showing her hair, a close-up of her face, and various beauty and wellness items. Text details her hair care, natural skincare routine, and health practices like diet and boxing.
How To Look Like A Model - Beauty Edition 💅🏼
Models often prioritize a healthy lifestyle with a balanced diet, regular exercise, and sufficient sleep. Skincare routines typically involve cleansing, moisturizing, and protecting against the sun. - The secret weapon behind a model’s timeless beauty is the expert guidance they receive. Dermato
Angelina

Angelina

2999 likes

BOOST Your Career: 4 FREE Online Courses for You
Are you wanting to up your resume and LinkedIn profile? There are so many ways to go about it, but free courses can really help! Here are a few sites with free courses to take. Harvard + EdX Price: Free Course Topics: Computer Science, Programming with Python, Artificial Intelligence with Pyth
Itsleilahclaire

Itsleilahclaire

1732 likes

A laptop screen displays various windows, with a large blue 'fm' icon for the FutureMe app overlaid, and text reading 'Write a letter To your Future self'.
A search bar shows 'FutureMe app', leading to a login/signup screen with options to continue with Apple, Google, or email, under the headings 'Download' and 'Login/signup'.
The FutureMe app interface for writing a letter is shown, with the text 'Dear FutureMe, please love yourself' typed, and a mobile keyboard visible below.
✨How to send a letter to your future self ✨
There’s lots of reasons why writing a letter to your future self is a great idea, but my main reason is to reflect on myself as a person. And not only that. But also to help concentrate on my goals and not lose sight of what’s important. This is why I love this app, because you can send a message
Byaombe •••

Byaombe •••

96 likes

How to Learn Coding Fast Even as a Beginner
#codingforbeginners #programming #studymotivations #webdevelopment #learntocode
Aysha

Aysha

792 likes

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

A pink mechanical keyboard with glowing keys and colorful string lights, overlaid with text that reads "LEARN SOFTWARE DEV FOR FREE 6 RESOURCES," indicating a guide to free software development learning.
A guide titled "1. LEARN THE INTERNET" for beginners, listing key concepts like HTTPS and DNS. It recommends "Front End Masters - Sections 1-4" and shows the cover of "The Front End Developer/Engineer Handbook 2024."
A guide titled "2. LEARN HTML/CSS" for beginners, highlighting key concepts like web page structure and CSS Flexbox. It recommends "FreeCodeCamp - Responsive Web Design Course" and displays a screenshot of the course page.
Study to be a Frontend Dev - Roadmap (100% Free)
This is a study guide for becoming a Front End Developer! All resources mentioned are FREE. Don’t pay anyone for this info! Why am I not recommending a zero to job course? Two Reasons 1-There is no course that will teach you everything 2-You need to put in some sweat equity, only wat
Study Seal

Study Seal

685 likes

A laptop with a red backlit keyboard displays code on its screen. Overlayed text reads "Tech Career Guide LOW-CODE DEVELOPMENT Increase your productivity," promoting low-code development as a way to boost efficiency.
A laptop screen shows a code editor with file structures and code. An icon of '</>' is next to text defining low-code as a method using visual tools and pre-made parts for faster, easier software development.
A laptop displays a code editor, while text describes three low-code platforms: Microsoft Power Apps for custom business apps, Zoho Creator for automating processes, and Quick Base for managing data and workflows.
Why developers should utilize Low-Code Tools
Hello everyone! I wanted to share insights about low code, a method of building software using visual tools and pre-made components. It simplifies development, enabling faster application creation without deep coding expertise. Low code platforms empower users across industries to streamline develo
Yun Jung

Yun Jung

180 likes

A flat lay of a completed weekly bullet journal spread with pens and markers on a white desk, illustrating the tutorial's final product.
A hand gives a thumbs-up next to an open dot-grid notebook on a white desk, with text indicating the first step: '1. grab a notebook'.
A laptop displays Pinterest bullet journal inspiration next to an open notebook with various spread layouts, illustrating the '2. inspo timeee' step.
how to create a weekly bujo spread 🎧🌱✏️
how to create a weekly bujo spread 🎧🌱✏️ this is a pretty simple bullet journal spread you guys can recreate! a lot of people look on pinterest/instagram for inspo pictures and think it’s too difficult to recreate, but i promise it’s easier than it looks! as always, let me know if you have an
lia 💗

lia 💗

810 likes

Wound Care & the Musculoskeletal System
Tips and notes on wound care, sterile dressings, the muscles and bones #lpn #lpnstudent #nursingstudent #woundcare #musculoskeletal #notetaking #notability
Aarin Waters

Aarin Waters

195 likes

Title slide featuring a smiling, green-haired anime character with antlers and flowers, introducing a guide on how to get started as a PNGtuber.
Step 1: A green-haired anime character with antlers and flowers, illustrating the instruction to make or buy a PNGtuber model, with a note about buying on Etsy.
Step 2 (Option A): Screenshot of Veadotube_Mini interface showing a deer model, explaining how to set up multiple model states for blinking and talking using four image files.
How to Get Started as a PNGtuber!
I remember the first time I tried to set up a PNGtuber, I was so lost. I must have watched a hundred videos trying to figure it out lol Hopefully, this slideshow will help you get yours set up easily! If you get stuck or have any questions, I’m happy to help as best I can. PNGtubing is a great
VeiledOpal

VeiledOpal

4928 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

2 likes

A desk setup with a monitor, white keyboard, and pink mouse, featuring the title 'best websites for learning computer science' and a 'Start' button.
A tablet displaying the GitHub website, with text overlay 'github Collaborate, host, and manage your coding projects seamlessly.'
A tablet displaying the Stack Overflow website, with text overlay 'stack overflow Get answers to coding questions and learn from industry professionals.'
Sites for CS Students!
Learning computer science can feel like drinking from a firehose sometimes, but the right resources make all the difference. Whether you’re debugging code, prepping for interviews, or diving into data science, these websites are absolute must-haves. GitHub is your go-to for managing projects and
CompSkyy

CompSkyy

214 likes

Powerful Websites
#software #fy #fypシ゚viral #businesssoftware #freewebsites
Tha Smoke Websites

Tha Smoke Websites

176 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

3 likes

An infographic displaying normal ranges for vital signs: Blood Pressure (Systolic 100-120, Diastolic 60-79), Heart Rate (60-100), Respirations (12-16 per min), and Temperature (Oral 97.6-99.6, Axillary 96.6-98.6).
Handwritten notes on EKG basics, illustrating the heart's electrical conduction pathway, an EKG waveform with P, QRS, and T waves, and an EKG grid for voltage and time interpretation.
A hand-drawn diagram of the human heart, labeling major structures like the superior/inferior vena cava, aorta, pulmonary artery/veins, atria, ventricles, and various valves.
Helpful notes 🫶
#school #medicalstudent #college #notes #information #notetaking #help #heart #collegestudent #collegelife
Sweird711

Sweird711

182 likes

Tech Career Guide: SQL Best practices
Hello everyone! I wanted to share essential SQL best practices for effective database management. Design your database with normalization principles for streamlined data organization and integrity. Use indexes strategically on key columns to optimize query performance. Write efficient SQL queries b
Yun Jung

Yun Jung

221 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

5 Ways to earn as a content creator
Ever wonder how content creators make a living? 🌟 I've dabbled in it all: from sponsored content that aligns with my values, to affiliate links for my go-to products. Sure, not every venture's a hit—some fizzled, while others fit like a glove. There's merch with my personal touch, membe
Ayesha 🍋

Ayesha 🍋

19 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

A smiling woman in a light blue suit sits on a sofa, with text overlays "Build a Winning Tech Portfolio" and "with These Top Online Courses" featuring a folder icon. The Lemon8 logo and username are at the bottom.
A woman wearing headphones smiles while looking right, with a microphone and lamp nearby. An overlay describes "1. Coursera's Full Stack Web Development Specialization" and its benefits for practical web development experience.
A smiling woman holds a white mug. An overlay describes "2. Data Scientist Nanodegree" and its benefits for providing deep insights into data science with actionable projects and mentorship.
Discover the best courses to show your skills ✨
Looking to build an impressive tech portfolio that your skills and sets you apart from the competition? A standout portfolio can be a game-changer in landing your dream job. Here are some top online courses that offer hands-on projects and portfolio-building elements to help you create a compelling
Dominica Amauri

Dominica Amauri

63 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

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

636 likes

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

TexarkanaTireAndWheel

3 likes

✨Meet Your Deadlines Like a Pro✨
✨🗓 how to meet your deadlines like a pro! 🖊 do you have a recent project? ⚡️ time to get into focus mode? 🏃‍♀️ this 3 tips will help you reach every deadline on time! 🎊 ▫️Make your deadline a day before it actually is! 👋🏻✨ this will help you motivate start right away 🔥 and have an extra-day
Deathfront101

Deathfront101

109 likes

Tips to get you started with portfolio websites😎
#portfolio #lemon8diarychallenge #programming #html #css #development
Feibertord ⚡️

Feibertord ⚡️

22 likes

keeping creativity alive
As one does before the new year, I made a list of realistic resolutions. That list was quickly scrapped when I stumbled upon old journal entries. Every year, for the past 5 years, I gave myself the same goals: be more creative - read more books, start drawing again, finish my scrapbooks, the li
stellamoon

stellamoon

9 likes

PR I’ve Been Sent As A Content Creator
Part 1 #pr #prbox #gettoknowme #prpackage #microinfluencer
Chanelle Renee

Chanelle Renee

10 likes

@Mr Williams what is a labubu? #labubu #popmart
Andra

Andra

57 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 + CSS + JavaScript = MAGIC! 🔥
HTML alone is just a structure, CSS adds style, but JavaScript brings it to life! 🚀 Watch how I build this Digital Clock from scratch using HTML, CSS & JavaScript! 👨‍💻💡 Try it yourself & level up your coding skills #codingforbeginners #htmlcssforbeginners #studymotivation #learntocod
Aysha

Aysha

2 likes

Personal training available
Fitness doesn’t serve one reason—it fuels many. You work out for more than just a six-pack. You train for energy, for better moods, for your kids, your partner, your peace of mind. Health is your anchor. Strength is your edge. Every time you show up, you're investing in a better version of y
PastorGainz Ramey

PastorGainz Ramey

0 likes

Learn Coding the Easy Way!
#LearnToCode #CodingTutorials #ProgrammingForBeginners #TechEducation #CodeWithMe
InsightEvolution

InsightEvolution

2 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

19 likes

Questions about resume
What’s everyone’s thoughts on this? On the one hand you want to stand out from the rest and on the other a typical job isn’t necessarily all that exciting to write about. Where do you think the line is in terms of embellishing a resume? Obviously lying isn’t acceptable and downright silly but also
Veronica

Veronica

17 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

79 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

See more