css常用语法

· · 个人记录

基本语法

标签名{

    属性: 值;

}

在标签名后加上 :hover 表示鼠标碰到的状态

在标签名后加上 :active 表示鼠标按住的状态

在标签名后加上 ::after 表示附加元素,用于实现一些额外的特效。

常用属性

name{
background: #FFFFFF; /* 设置背景颜色 */
background-image: url(https://s2.ax1x.com/2019/08/01/ea5j4H.jpg) !important; /* 设置背景图片 */
color: #FFFFFF; /* 设置颜色 */
padding: 10px; /* 设置边框宽度 */
margin-top: 5px; /* 上宽度 */
margin-bottom: 5px; /* 下宽度 */
margin-left: 5px; /* 左宽度 */
margin-right: 5px; /* 右宽度 */
border-radius: 100px; /* 圆角 */
transition: all .2s ease; /* 非线性动画 */
border-width: 0; /* 边框宽度 */
transform: translateX(80px); /* X坐标平移 */
transform: translateY(80px); /* Y坐标平移 */
word-break: break-all; /* 文本强制换行 */
box-shadow: 0px 0px 10px #000; /* 阴影 */
}

动画

@keyframes 动画名{
    0% {
        初始状态;
    }
    100% {
        结束状态;
    }
}
标签名{
    animation: 动画名  持续时间s;
}

其他语法

属性值后面加上 !important; 可以提高优先级 \ 魔改专用

模版

鼠标碰到超链接时,下面出现下划线

a{
    position: relative;
}
a::after {
    content: "";
    width: 0;
    height: 2px;
    background: rgba(255, 0, 0, .63);
    position: absolute;
    top: 100%;
    left: 50%;
    transition: all .35s;
}
a:hover::after {
    left: 0%;
    width: 100%;
}

背景显示初音未来

html > body {
    background-image: url(https://s2.ax1x.com/2019/08/01/ea5j4H.jpg) !important;
    background-repeat: no-repeat;
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
}