
box-sizing attribute definition and usage
The box-sizing attribute is a new attribute in css3, allowing You define certain elements in a way to fit within a specified area (for example, if you need to place two bordered boxes side by side, you can do so by setting the box-sizing property to "border-box", which causes the browser to render the There is a box with a specified width and height, and the border and padding are put into the box);
Internet Explorer, Opera and Chrome browsers support the box-sizing attribute. Firefox does not yet support this attribute, but it does. -moz-box-sizing attribute replaces the box-sizing attribute;
box-sizing attribute syntax format
box-sizing: content-box/border-box/inherit;
Related information: "CSS_CSS3 Knowledge 》
Parameter description
content-box: This is the width and height behavior specified by CSS2.1. The width and height are applied to the content box of the element respectively. In the width Draw the element's padding and border in addition to the height and height;
border-box: The width and height set for the element determine the element's border box, that is, any padding and border specified for the element Borders will be drawn within the set width and height. The width and height of the content can be obtained by subtracting the border and padding respectively from the set width and height;
inherit: Specifies that the value of the box-sizing attribute should be inherited from the parent element;
Example:
<!DOCTYPE html><html><head><meta charset="utf-8" />
<title>css3 box-sizing属性笔记</title><style type="text/css">
body{background-color: #aaa;}div.container{width:30em;border:1em solid;}
.box{box-sizing:border-box;-moz-box-sizing:border-box; /* Firefox */
-webkit-box-sizing:border-box; /* Safari */
width:50%;border:1em solid red;float:left;}
</style></head><body><div class="container">
<div class="box">这个 div占据左半部分。</div><div class="box">这个 div占据右半部分。</div>
</div></body></html>Run result:

The above is the detailed content of What is the box-sizing property. For more information, please follow other related articles on the PHP Chinese website!
Weekly Platform News: Web Apps in Galaxy Store, Tappable Stories, CSS SubgridApr 14, 2025 am 11:20 AMIn this week's roundup: Firefox gains locksmith-like powers, Samsung's Galaxy Store starts supporting Progressive Web Apps, CSS Subgrid is shipping in Firefox
Weekly Platform News: Internet Explorer Mode, Speed Report in Search Console, Restricting Notification PromptsApr 14, 2025 am 11:15 AMIn this week's roundup: Internet Explorer finds its way into Edge, Google Search Console touts a new speed report, and Firefox gives Facebook's notification
The Power (and Fun) of Scope with CSS Custom PropertiesApr 14, 2025 am 11:11 AMYou’re probably already at least a little familiar with CSS variables. If not, here’s a two-second overview: they are really called custom properties, you set
We Are ProgrammersApr 14, 2025 am 11:04 AMBuilding websites is programming. Writing HTML and CSS is programming. I am a programmer, and if you're here, reading CSS-Tricks, chances are you're a
How Do You Remove Unused CSS From a Site?Apr 14, 2025 am 10:59 AMHere's what I'd like you to know upfront: this is a hard problem. If you've landed here because you're hoping to be pointed at a tool you can run that tells
An Introduction to the Picture-in-Picture Web APIApr 14, 2025 am 10:57 AMPicture-in-Picture made its first appearance on the web in the Safari browser with the release of macOS Sierra in 2016. It made it possible for a user to pop
Ways to Organize and Prepare Images for a Blur-Up Effect Using GatsbyApr 14, 2025 am 10:56 AMGatsby does a great job processing and handling images. For example, it helps you save time with image optimization because you don’t have to manually
Oh Hey, Padding Percentage is Based on the Parent Element's WidthApr 14, 2025 am 10:55 AMI learned something about percentage-based (%) padding today that I had totally wrong in my head! I always thought that percentage padding was based on the


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Dreamweaver CS6
Visual web development tools






