亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

CSS3 box size

CSS3 box size

CSS3 box-sizing property can set the width and height properties, which include padding (inner margin) and border (border).

Do not use CSS3 box-sizing property

By default, the width and top end of an element are calculated as follows:

width (width) + padding (padding) + border (border) = the actual width of the element

height (height) + padding (padding) + border (border) = the actual height of the element

This means When we set the width/height of an element, the actual displayed height and width of the element will be larger (because the element's border and padding are also calculated in width/height).

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<style> 
.div1 {
    width: 300px;
    height: 100px;
    border: 1px solid blue;
}
.div2 {
    width: 300px;
    height: 100px;    
    padding: 50px;
    border: 1px solid red;
}
</style>
</head>
<body>
<div class="div1">這個是個較小的框 (width 為 300px ,height 為 100px)。</div>
<br>
<div class="div2">這個是個較大的框 (width 為 300px ,height 為 100px)。</div>
</body>
</html>

Using this method, if you want to get a smaller box and include padding, you have to consider the width of the border and padding.

The box-sizing property of CSS3 solves this problem very well.


Use the CSS3 box-sizing property

The CSS3 box-sizing property includes padding (inside) in the width and height of an element margin) and border (border).

If box-sizing: border-box; is set on the element, padding (inner margin) and border (border) are also included in width and height:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<style> 
.div1 {
    width: 300px;
    height: 100px;
    border: 1px solid blue;
    box-sizing: border-box;
}
.div2 {
    width: 300px;
    height: 100px;    
    padding: 50px;
    border: 1px solid red;
    box-sizing: border-box;
}
</style>
</head>
<body>
<div class="div1">兩個 div 現(xiàn)在是一樣大小的!</div>
<br>
<div class="div2">php中文網(wǎng)!</div>
</body>
</html>

From the results See box-sizing: border-box; for better results, which is exactly what many developers need.

The following code can display the size of all elements in a more intuitive way. Many browsers already support box-sizing: border-box; (but not all - that's why input and text elements with width: 100%; have different widths).

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">  
<style>
* {
    box-sizing: border-box;
} 
input, textarea {
    width: 100%;
}
</style>
</head>
<body>
<form action="action_page.php">
用戶名:<br>
<input type="text" name="username" value=""><br>
郵箱:<br>
<input type="text" name="email" value=""><br>
評論:<br>
<textarea name="message" rows="5" cols="30">
</textarea>
<br><br>
<input type="submit" value="Submit">
</form> 
<p><strong>提示:</strong> 可以嘗試移除樣式中的 box-sizing 屬性,看看會發(fā)生什么。注意移除后部分瀏覽器 input, textarea, 和 submit 按鈕的寬度不一致。</p>
</body>
</html>


Continuing Learning
||
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <style> * { box-sizing: border-box; } input, textarea { width: 100%; } </style> </head> <body> <form action="action_page.php"> 用戶名:<br> <input type="text" name="username" value=""><br> 郵箱:<br> <input type="text" name="email" value=""><br> 評論:<br> <textarea name="message" rows="5" cols="30"> </textarea> <br><br> <input type="submit" value="Submit"> </form> <p><strong>提示:</strong> 可以嘗試移除樣式中的 box-sizing 屬性,看看會發(fā)生什么。注意移除后部分瀏覽器 input, textarea, 和 submit 按鈕的寬度不一致。</p> </body> </html>
submitReset Code