width 宽度,css中width指的是内容的宽度,而不是盒子的宽度。 height高度 ,css中Height指的是内容的高度,而不是盒子的高度。 padding 内边距 border 边框 margin 外边距
.box1{ width:100px; height:100px; padding:100px; border:1px solid red;} 计算如下:1+100+100+100+1=302px.box2{ width:250px; height:250px; padding:25px; border:1px solid red;} 计算如下:1+25+250+25+1=302px 上面代码中盒子的真实占有宽度计算公式: 真实占有宽度=左border+左padding+width+右padding+右border
The first type: small attributes, that is, composite attributes.
padding-top:30px; 上padding-right:20px; 右padding-bottom:40px; 下padding-left:100px; 左
The second type: comprehensive attributes.
Separated by spaces, top, right, bottom and left.
padding:30px 20px 40px 100px;
padding:20px;padding-left:30px;
Question 1:
p{ width:200px; height:200px; padding-left:10px; padding-right:20px; padding:40px 50px 60px; padding-bottom:30px; border:1px solid #000; }
Answer: padding -left:10px; and padding-right:20px; are useless, because the subsequent padding attribute overlays them.
none 定义无边框。 hidden 与 “none” 相同。不过应用于表时除外,对于表,hidden 用于解决边框冲突。 dotted 定义点状边框。在大多数浏览器中呈现为实线。 dashed 定义虚线。在大多数浏览器中呈现为实线。 solid 定义实线。 double 定义双线。双线的宽度等于 border-width 的值。 groove 定义 3D 凹槽边框。其效果取决于 border-color 的值。 ridge 定义 3D 垄状边框。其效果取决于 border-color 的值。 inset 定义 3D inset 边框。其效果取决于 border-color 的值。 outset 定义 3D outset 边框。其效果取决于 border-color 的值。 inherit 规定应该从父元素继承边框样式。 常用的有:solid 、dashed、 dotted
First Type: By element
border-width:10px; 边框宽度border-style:solid; 线型border-color:red; 颜色等价于:border:10px solid red;
If a small element is followed by multiple values separated by spaces, then the order is top, right, bottom, left:
border-width:10px 20px;border-style:solid dashed dotted;border-color:red green blue yellow;
Second type: By direction
The first method of disassembly:
border-top:10px solid red;border-right:10px solid red;border-bottom:10px solid red;border-left:10px solid red;等价于:border:10px solid red
The second method of disassembly is to dismantle each element in each direction:
border-top-width:10px;border-top-style:solid;border-top-color:red;border-right-width:10px;border-right-style:solid;border-right-color:red;border-bottom-width:10px;border-bottom-style:solid;border-bottom-color:red;border-left-width:10px;border-left-style:solid;border-left-color:red;等价于:border:10px solid red;
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>三角形</title> <style type="text/css"> p{ width: 0px; height: 0px; border: 30px solid white; border-top-color: pink; transition:all 1s ease 0s; } p:hover{ transform: rotate(180deg); } </style> </head> <body> <p> </p> </body> </html>
<1>From a macro perspective, web pages and design software such as PS are essentially different Avoid:
Web page production, from top to bottom. With design software, you can draw wherever you want.
<2>Microscopic properties of standard flow:
(1) Blank folding phenomenon.
(2) The height is uneven, and the bottom edges are aligned.
(3) Automatically wrap the line. If you can’t finish writing in one line, wrap it in a new line.
<3>Block-level elements and inline elements
(1) Tags are divided into two levels: block-level elements and inline elements.
(2) Block-level elements:
霸占一行,不能与其他任何元素并列。 能接受宽高。 如果不设置宽度,那么宽度将默认变为父亲的100%。
(3) Inline elements:
可以与其他行内元素并排。 不能设置宽高。默认的宽度,就是文字的宽度。
(4) Labels are divided into: text level and container level.
文本级:p、span、a、b、i、u、em 容器级:p 、h系列 、li 、dt 、dd
Basically all text-level tags are inline elements. Except for p, it is a block-level element.
All container-level tags are block-level elements.
<1>Block-level elements can be set to inline elements. Inline elements can be set as block-level elements.
<2>display is used to change the inline and block-level properties of elements.
display:inline; 这个标签将会变为行内元素。 display:block; 这个标签将会变为块级元素。
<3>There are three methods in CSS to separate an element from the standard document flow.
(1) Floating
(2) Absolute positioning
(3) Fixed positioning
<1>If there is enough space, they will be close to the second brother. If there is not enough space, he will lean on Brother Yi. If there is not enough space to lean against Brother 1, stick to the left wall yourself.
<2>float:left/right;
The above is the detailed content of Introduction to css box model. For more information, please follow other related articles on the PHP Chinese website!