Everyone must know the composition of the box model, from the inside to the outside: content, padding, border, margin. There are two standard box models, one is the standard model and the other is the IE model. From the above two pictures, it is not difficult to see that in the standard model, the width and height of the box model are just the width and height of the content. In the IE model, the width and height of the box model is the total width and height of the content + padding + border. How to set two models in css The CSS3 property box-sizing (default value: content-box) is used here. /* Standard model */ box-sizing:content-box; /*IE model*/ box-sizing:border-box; content-box: This is the behavior for width and height specified by CSS 2.1. Specifying the width and height of an element (min/max properties) applies to the width and height of the box. The padding and border of an element are laid out and drawn except for the specified width and height border-box: Specify width and height (minimum/maximum properties) to determine the element's border box. That is, specifying the width and height of an element includes specifying padding and borders. The content width and height are calculated by subtracting the width of the border and padding on both sides from the specified "width" and "height" properties. Test reference cases The ideal effect and code are as follows: .input { width: 146px; height: 36px; line-height: 36px; background: transparent; border: 2px solid #0D349A; color: #bdbdbd; padding-left: 10px; padding-right: 30px; font-size: 14px; box-sizing:content-box; (default optional)} When applied in a project using the bootstrap framework, I found that the default box-sizing: border-box; in the bootstrap.min.css style would interfere with the width and height of the search box. * { -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box;} This property causes the page to appear like this: .input { width: 146px; height: 36px; line-height: 36px; background: transparent; border: 2px solid #0D349A; color: #bdbdbd; padding-left: 10px; padding-right: 30px; font-size: 14px; box-sizing:border-box;} At this time, if you want to achieve the ideal effect, you must adjust the style to: .input { width: 190px; height: 40px; line-height: 40px; background: transparent; border: 2px solid #0D349A; color: #bdbdbd; padding-left: 10px; padding-right: 30px; font-size: 14px; box-sizing:border-box;} PS Tips: When a container width is defined as width:100%;, if padding or border is added, it will overflow the parent container and expand outwards. If you use this style and specify box-sizing: border-box; then the padding and border will no longer overflow, but shrink inwards. This effect feels very practical. Summarize The above is the editor’s introduction to the interesting box model of CSS3 box-sizing attribute. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time! |
<<: Detailed process of drawing three-dimensional arrow lines using three.js
>>: docker run -v mounts data volumes abnormally, and the container status is always restarting
In web projects we often use the timeline control...
When implementing this function, the method I bor...
The specific steps of installing mysql5.7.18 unde...
Install Enter the following command to install it...
Achieve results The code is as follows html <t...
Use examples to familiarize yourself with the mean...
The shell script sets access control, and the IP ...
When you are working on a shared system, you prob...
Table of contents Docker deployment Always on clu...
The react version when writing this article is 16...
MySQL download and installation (version 8.0.20) ...
background If the catalina.out log file generated...
The web color picker function in this example use...
Recommended reading: MySQL 8.0.19 supports accoun...
Find the problem I have been learning Django rece...