Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
檀越@新空间
Coding Tree
提交
ea50bdf1
C
Coding Tree
项目概览
檀越@新空间
/
Coding Tree
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
Coding Tree
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
ea50bdf1
编写于
1月 14, 2022
作者:
彭世瑜
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix
上级
fe2e24b1
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
219 addition
and
5 deletion
+219
-5
blog/front-end-learn/css-box.md
blog/front-end-learn/css-box.md
+155
-5
blog/front-end-learn/demo/css-box-2.html
blog/front-end-learn/demo/css-box-2.html
+18
-0
blog/front-end-learn/demo/css-box-3.html
blog/front-end-learn/demo/css-box-3.html
+32
-0
blog/front-end-learn/demo/css-box-4.html
blog/front-end-learn/demo/css-box-4.html
+14
-0
未找到文件。
blog/front-end-learn/css-box.md
浏览文件 @
ea50bdf1
...
@@ -83,7 +83,14 @@ display: block;
...
@@ -83,7 +83,14 @@ display: block;
-
width
-
width
-
height
-
height
(4)边框
```
css
.box
{
width
:
100px
;
height
:
100px
;
}
```
## 边框 border
```
css
```
css
/* 粗细 线条样式 颜色(不分先后顺序)*/
/* 粗细 线条样式 颜色(不分先后顺序)*/
...
@@ -108,11 +115,9 @@ border-color: 边框颜色
...
@@ -108,11 +115,9 @@ border-color: 边框颜色
-
dashed 虚线
-
dashed 虚线
-
dotted 点线
-
dotted 点线
盒子尺寸 = width / height + 边框线
布局顺序:从外到内,从上到下
布局顺序:从外到内,从上到下
(5)
内边距 padding
##
内边距 padding
```
css
```
css
/* 可取 4 个值、3 个值、2 个值、1 个值 */
/* 可取 4 个值、3 个值、2 个值、1 个值 */
...
@@ -120,12 +125,157 @@ padding: 上 右 下 左;
...
@@ -120,12 +125,157 @@ padding: 上 右 下 左;
padding
:
上
左右
下
;
padding
:
上
左右
下
;
padding
:
上下
左右
;
padding
:
上下
左右
;
padding
:
上下左右
;
padding
:
上下左右
;
/* 单个方向 */
padding-top
:
10
px
;
padding-bottom
:
10
px
;
padding-left
:
10
px
;
padding-right
:
10
px
;
```
```
规律:顺时针,值不够看对边
规律:顺时针,值不够看对边
(6)
导航实例
##
导航实例
[](
demo/css-box-1.html
':include :type=code'
)
[](
demo/css-box-1.html
':include :type=code'
)
[](
demo/css-box-1.html
':include height=70'
)
[](
demo/css-box-1.html
':include height=70'
)
## 盒子尺寸计算
```
box-sizing: content-box 默认
盒子最终宽度 = width(content) + padding + border
box-sizing: border-box
盒子最终宽度 = width = padding + border + content
```
## 外边距 margin
设置值的方式和 padding 类似
```
css
/* 可取 4 个值、3 个值、2 个值、1 个值 */
margin
:
上
右
下
左
;
margin
:
上
左右
下
;
margin
:
上下
左右
;
margin
:
上下左右
;
/* 单个方向 */
margin-top
:
10
px
;
margin-bottom
:
10
px
;
margin-left
:
10
px
;
margin-right
:
10
px
;
```
使用 margin 让元素居中
```
css
.box
{
width
:
100px
;
height
:
100px
;
background-color
:
#ccc
;
margin
:
0
auto
;
}
```
## 清除浏览器默认样式
京东
```
css
*
{
margin
:
0
;
padding
:
0
;
}
```
淘宝
```
css
blockquote
,
body
,
button
,
dd
,
dl
,
dt
,
fieldset
,
form
,
h1
,
h2
,
h3
,
h4
,
h5
,
h6
,
hr
,
input
,
legend
,
li
,
ol
,
p
,
pre
,
td
,
textarea
,
th
,
ul
{
margin
:
0
;
padding
:
0
;
}
```
常用的清除样式
```
css
*
{
margin
:
0
;
padding
:
0
;
box-sizing
:
border-box
;
}
```
去掉列表前的符号
```
css
ul
{
list-style
:
none
;
}
```
## 外边距折叠现象
-
合并现象
-
塌陷现象
(1)合并现象
-
场景:垂直布局的块级元素,上下的 margin 会合并
-
结果:最终两者距离为 margin 的最大值
-
解决方法:只给其中一个盒子设置 margin
[](
demo/css-box-2.html
':include :type=code'
)
[](
demo/css-box-2.html
':include height=400'
)
(2)塌陷现象
-
场景:相互嵌套的块级元素,子元素的 margin-top 会作用在父元素上
-
结果:导致父元素一起往下移动
-
解决方法:
1.
给父元素设置 border-top 或者 padding-top(分隔父子元素的 margin-top)
2.
给父元素设置 overflow:hidden;
3.
转换为行内块元素
4.
设置浮动
[](
demo/css-box-3.html
':include :type=code'
)
[](
demo/css-box-3.html
':include height=530'
)
## 行内标签的 margin/pading
垂直方向不生效,使用行高 line-height 实现
[](
demo/css-box-4.html
':include :type=code'
)
[](
demo/css-box-4.html
':include height=60'
)
blog/front-end-learn/demo/css-box-2.html
0 → 100644
浏览文件 @
ea50bdf1
<style>
.box-1
{
width
:
100px
;
height
:
100px
;
background-color
:
#698e6a
;
margin-bottom
:
50px
;
}
.box-2
{
margin-top
:
100px
;
width
:
100px
;
height
:
100px
;
background-color
:
#7f9faf
;
}
</style>
<div
class=
"box-1"
></div>
<div
class=
"box-2"
></div>
\ No newline at end of file
blog/front-end-learn/demo/css-box-3.html
0 → 100644
浏览文件 @
ea50bdf1
<style>
.box-father
{
width
:
200px
;
height
:
200px
;
background-color
:
#b2b6b6
;
}
.box-child
{
width
:
100px
;
height
:
100px
;
background-color
:
#7f9faf
;
margin-top
:
100px
;
}
.resolve
{
overflow
:
hidden
;
margin-top
:
20px
;
}
</style>
<div
class=
"box-wrap"
>
<!-- 元素的margin-top 作用在了父元素上 -->
<div
class=
"box-father"
>
<div
class=
"box-child"
></div>
</div>
<!-- [完美解决方案]给父元素设置 overflow:hidden; -->
<div
class=
"box-father resolve"
>
<div
class=
"box-child"
></div>
</div>
</div>
\ No newline at end of file
blog/front-end-learn/demo/css-box-4.html
0 → 100644
浏览文件 @
ea50bdf1
<style>
.box
{
border
:
1px
solid
#eee
;
}
.box
span
{
margin
:
20px
;
padding
:
20px
;
}
</style>
<div
class=
"box"
>
<span>
乾坤空落落,岁月去堂堂。
</span>
</div>
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录