Box Model (Box Model) in CSS
Elements in HTML can be considered boxes. In CSS, the term 'box model' is used to refer to design and layout.
Basically the CSS box model is a box that surrounds HTML elements, including margins, borders, padding, and internal content. The image below shows the location and relationship between these components.
Components in a CSS box model
Explain components:
- Content - content in the box, where text and images are displayed
- Padding - white space around content, transparent
- Border - border around content and padding
- Margin - the margin outside the border, transparent
The box model allows adding borders around the element and defining spaces between them.
div {
width: 300px;
border: 25px solid green;
padding: 25px;
margin: 25px;
}
Element width and height
To determine the height and width of the correct element on all browsers, you need to know how the box model works. When setting the height
and width
properties of elements with CSS, you only set up for the content only. To accurately calculate the element size, both the border, margin and padding sections need to be added.
Assume element
has a total width of 350px.
div {
width: 320px;
padding: 10px;
border: 5px solid gray;
margin: 0;
}
The actual calculation will be like this:
320px (width)
+ 20px (padding left and right)
+ 10px (left and right borders)
+ 0px (left and right margins)
= 350px
Thus, the total width of the actual element is calculated by the formula:
The total width of the element = padding left + padding right + left border + right edge + left margin + right margin
The total height of the actual element is calculated by the formula:
Total height of the element = padding on + padding below + upper border + lower border + upper margin + lower margin
Previous lesson: Height and width in CSS
The following article: Outline in CSS
You should read it
May be interested
- How to find Windows laptop modeldo you need to know your laptop or windows computer model? maybe you're looking for a driver for your device or looking for support from the manufacturer. whatever the reason is, it's easy to find and there are many different ways to solve it.
- How does Uber work? - Decoding Uberin this article, the author will give a little-known number about uber along with detailed explanations about the model that uber uses to make money. uber's customer segmentation, value proposition, key issues, solutions, cost structure and uber revenue model are all discussed.
- Collection of the most beautiful vector model imagesif you love fashion and art, you cannot miss these inspiring model images. they show the creativity, style and unique personality of each individual in the fashion industry.
- No engine but this model plane can fly up to 881km/h!spencer lisenby's engineless remote-controlled aircraft (also known as a glider) was able to reach speeds of up to 881 km/h in a record-setting performance at parker mountain where there are northeasterly winds. very strong blow.
- 3 ways to check the graphics card model on Windows 11you probably know all the major graphics card manufacturers, such as amd, nvidia, intel and asus, etc.. but what model of gpu exactly is yours?
- Instructions on how to make a helicopter model from a very simple plastic bottle coverin addition to buying aircraft models in stores, you can create your own unique, mini-home helicopter from old plastic bottles.
- Steps to create relationships between multiple tables using Data Model in Excelexcel is a powerful tool for data analysis and automation after processing large data sets. you can spend considerable time analyzing tons of data using vlookup, index-match, sumif...
- OpenAI Announces o3 Pro, Its Smartest Reasoning Model Everopenai has just officially launched o3-pro, a leading reasoning ai model that uses higher computing power to think deeper and provide answers with superior quality.
- Tesla unveils coronavirus ventilator prototype that uses Model 3 partsthe model 3 infotainment system provides the basis for tesla's ventilator, hastily designed to combat device shortages around the world.
- Hardware in OSI reference model: Grade 1the open system interconnect (osi) reference model is a model developed by the open system interconnect (osi), which describes how data from an application on a computer is transmitted to an application on a computer. how different. m & o