首页 技术 正文
技术 2022年11月16日
0 收藏 822 点赞 5,082 浏览 1022 个字

盒子模型代码简写

回忆盒模型时外边距(margin)、内边距(padding)和边框(border)设置上下左右四个方向的边距是按照顺时针方向设置的:上右下左。

语法:

  1. margin:10px 15px 12px 14px;/*上设置为10px、右设置为15px、下设置为12px、左设置为14px*/

通常有三种缩写的方法:1、如果top、right、bottom、left的值相同,

  1. margin:10px 10px 10px 10px;

可缩写为:

  1. margin:10px;

2、如果top和bottom值相同、left和 right的值相同

  1. margin:10px 20px 10px 20px;

可缩写为

  1. margin:10px 20px;

3、如果left和right的值相同

  1. margin:10px 20px 30px 20px;

可缩写为

  1. margin:10px 20px 30px;

注意:padding、border的缩写方法和margin是一致的


颜色值缩写

关于颜色的css样式也是可以缩写的,当你设置的颜色是16进制的色彩值时,如果每两位的值相同,可以缩写一半。
举个栗子:

  1. p{color:#000000;}

缩写:

  1. p{color:#000;}

另外一个栗子:

  1. p{color: #336699;}

缩写:

  1. p{color: #369;}

字体缩写

网页中的字体css样式代码也有他自己的缩写方式

  1. body{
  2. font-style:italic;
  3. font-variant:small-caps;
  4. font-weight:bold;
  5. font-size:12px;
  6. line-height:1.5em;
  7. font-family:"宋体",sans-serif;
  8. }

这么多行的代码其实可以缩写为一句:

  1. body{
  2. font:italic small-caps bold 12px/1.5em "宋体",sans-serif;
  3. }

注意:

1、使用这一简写方式你至少要指定 font-size 和 font-family 属性,其他的属性(如 font-weight、font-style、font-varient、line-height)如未指定将自动使用默认值。

2、在缩写时 font-size 与 line-height 中间要加入“/”斜扛。

一般情况下因为对于中文网站,英文还是比较少的,所以下面缩写代码比较常用:

  1. body{
  2. font:12px/1.5em "宋体",sans-serif;
  3. }

只是有字号、行间距、中文字体、英文字体设置。


来自为知笔记(Wiz)

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,993
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,507
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,350
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,135
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,768
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,845