CSS基础

这篇博客深入探讨了CSS中的字体属性,包括font-family、font-size、font-weight和font-style,以及如何通过font复合属性简洁设置。此外,还讲解了文本颜色、对齐、修饰和行间距的控制。在布局方面,介绍了块元素和行内元素的特性,以及如何利用display属性转换元素显示模式。示例代码展示了实际应用。
摘要由CSDN通过智能技术生成

1、font:
font-family:字体
多个字体之间使用逗号分隔
多个字体依次在计算机中寻找,找到就使用,否则就默认为微软雅黑

font-size:字体大小,单位px
默认16px

font-weight:字体粗细
700或bold 加粗
400或normal 不加粗
注意,没有单位

font-style:italic 斜体
不倾斜是normal

font:复合属性,可以连写
有顺序
font:font-style font-weight font-size/line-height font-family
不需要设置的属性可以省略,但是必须保留font-size和font-family 否则不起作用


2、文本:
color:字体颜色
可以使用英文单词
可以使用十六进制代码#fff(通常使用)
也可以使用rgb值

text-align:文本对齐
left:左对齐 
center :居中
right:右对齐

text-indent:文本缩进
2em

text-decoration:文本修饰
underline下划线
overline上划线
line-through删除线
none

line-height:设置行间距
上间距+文字高度+下间距 = 行间距
line-height越大,上下间距的值会变大,上间距 = 下间距


3、元素显示模式:

元素以什么方式显示,如:div独占一行,span可以在一行内放多个
html元素分为两种:块元素和行内元素
块元素:p、div、h1~h6、ul
特点:
    1、独占一行
    2、可以设置宽高
    3、宽度默认是父元素的100%
行内元素:strong、em、i、del、a、span
特点:
    1、一行可以放多个
    2、设置宽高无效
    3、默认高度是内容的高度
    4、行内元素只能容纳文本和其他行内元素

行内块元素:img、input、td
同时具有行内元素和块元素的特点
1、一行显示多个,但元素之间有空隙(行内特点)
2、默认高度就是内容高度(行内特点)
3、高度、宽度可以设置(块特点)

元素显示模式的转换:
display样式:
block
inline
inline-block

代码

body {
    font-family: "Karla";
    background: #edeae5;
    width: 100%;
    height: 100%;
    position: relative;
    margin: 0px;
    text-align: center;
}
 
a {
    text-decoration: none;
    color: rgba(0, 0, 0, 0.5);
    font-style: italic;
    transition: 0.4s;
}
 
a:hover {
    color: rgba(0, 0, 0, 0.7);
}
 
div {
    transition: linear 0.2s;
}
 
#container {
    width: 480px;
    height: 480px;
    position: absolute;
    top: calc(50% - 240px);
    left: calc(50% - 240px);
}
 
.circle {
    width: 60px;
    height: 60px;
    background: white;
    display: inline-block;
    margin-right: 30px;
    border-radius: 50%;
}
 
.square {
    width: 60px;
    height: 60px;
    background: white;
    display: inline-block;
    margin-right: 30px;
    background: #e67e22;
}
 
.row {
    margin-bottom: 30px;
}
 
.green {
    background: #78c272;
}
 
.fancy {
    border: 3px inset rgba(199, 196, 196, 1);
    /* border: 3px inset rgba(52, 19, 236, 1); */
    width: 54px;
    height: 54px;
}
 
#third-row .circle {
    background: #de6868;
}
 
.row .circle:first-child {
    opacity: 0;
}
 
.row .circle.fancy {
    border-style: dotted;
}
 
.row .green {
    background: #6392c0;
}
 
.row .fancy {
    background: #6392c0;
}
 
.row .circle:hover {
    opacity: 0.5;
}
 
#second-row .circle:hover {
    transform: scale(1.25);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值