一语道破CSS3(二)

2024-02-24 04:40
文章标签 frontend css3 一语道破

本文主要是介绍一语道破CSS3(二),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

在这里插入图片描述

  • CSS背景:CSS允许使用纯色作为背景,也允许使用背景图创建相当复杂的效果
属性描述
background-color设置背景颜色
background-image以图片做背景
background-repeat设置的背景图片是否及如何重复
background-position设置背景图片的起始位置
background-attachment背景图像是否固定或随页面其余部分滚动
background-size规定背景图片的尺寸
background-origin规定背景图片的定位区域
background-clip规定背景的绘制区域

(1)padding:设置内边框,如:padding: 10px;
(2)background-position属性:如果设置属性值right,就默认从右上角,而且从照片的中间开始显示。我们可以这样改变:right top;。这个属性也可以直接使用坐标,如:0px 0px。
(3)background-attachment属性:默认随页面动。fixed属性值随页面动,

  • CSS文本:可以改变文本颜色、字符间距、对齐文本、装饰文本、文本缩进
属性描述
color *文本颜色
direction文本方向
line-height行高
letter-spacing字符间距
text- align *文本的对齐方式
text-decoration向文本添加修饰
text-indent缩进元素中文本的首行
text-transform处理元素中的字母
unicode-bidi设置文本方向
white-space元素中空白的处理方式
word-spacing字间距

(1)text-indent属性:属性值可以是:2em。em是字符。

  • CSS字体:定义文本的字体的大小,类型等
属性描述
font-family设置字体系列
font-size设置字体的尺寸
font-style设置分风格
font-weight设置字体粗细
  • 链接:使用text-decoration:none;去掉链接的下划线。
  • CSS轮廓:主要是突出元素的作用。就是给内容加一个框框。
属性描述
outline设置轮廓属性
outline-color轮廓颜色
outline-style设置轮廓样式
outline-width设置轮廓宽度
  • CSS定位:改变元素在页面上的位置。
    (1)CSS定位机制:
    1. 普通流:元素按照其在HTML中的位置顺序决定排布的过程。
    2. 浮动:
    3. 绝对布局:
属性描述
position把元素故在一一个静态的、相对的、绝对的、或固定的位置中
top元素向上的偏移量
left元素向左的偏移量
right元素向右的偏移量
bottom元素向下的偏移量
overflow设置元素溢出其区域发生的事情
clip设置元素显示的形状
vertical-align设置元素垂直对齐方式
z-index设置元素的堆叠顺序
  • CSS定位属性:
    (1)position属性有四个值:

    1. static:静态布局。没有偏移量。即使设置了。
    2. relative:相对布局。可以设置top,right,left等的偏移量。
    3. absolute:绝对布局。相当于它在页面内不再占有位置。也有偏移量。
    4. fixed:将设置为fixed的元素固定在页面上,不随页面滚动而动。

    (2)z-index:控制那个元素在页面的前面显示(当覆盖时)值大的在前面。相对和绝对布局有可用。

  • CSS浮动:
    (1)float属性:浮动会随容器大小来适应屏幕。

    1. left:元素向左浮动。

    2. right:元素向右浮动

    3. none:不浮动

    4. inherit:从父级继承浮动属性。
      (2)clear属性:清除浮动属性。

    5. left、right:去掉向左向右的浮动

    6. both:左右两侧均去掉

    7. inherit:从父级继承来的clear属性。

  • CSS盒子模型:
    (1)盒子模型概述:

    1. margin:外边距
    2. border:边框
    3. padding:内边距
    4. content:内容

    (2)CSS内边距:内容外部,边框外部。padding-*设置某一边的内边距(left,right,top)。
    (3)CSS边框:

    1. border-style:定义了10中不同的非继承样式。包括none。border-left-style改变左边的样式。
    2. CSS3提供的是三个边框属性:border-radius(圆角边框)、border-shadow(边框阴影)、border-image(边框图片)。

    (4)CSS外边框:围绕在内容边框的区域就是外边距,默认为透明区域。margin。
    (5)CSS外边距合并:两个内容之间的外边距会自动叠加,遵循大的内边距。

  • CSS常用操作:
    (1)对齐操作:

    1. margin:进行水平对齐。如:margin-left auto;。如:margin 0px auto;,前一个是上下,后一个是左右。
    2. position、float:左右对齐。

    (2)尺寸操作:width,height等。

    (3)分类操作:如:clear、display(如何显示,做导航栏)、float、position、cursor(鼠标指针的显示形式)等

    (4)导航栏:使用列表来创建,(text-decoration none;去掉链接的下划线)

    (5)图片操作:opacity,透明效果。取值[0,1]

  • 类选择器和id选择器的区别:
    (1)id是唯一的,class不唯一。
    (2)id选择器不能结合使用
    (3)当使用js时,要使用到id。

2D,3D的转换
过渡
动画
多列

  • 2D、3D转换:通过CSS,我们能够对元素进行移动、缩放、移动、拉长或拉伸,转换是是元素改变形状、尺寸和位置的一种效果。
    (1)2D转换方法:

    1. translate():移动。是transform的属性值。例:
      -webkit-transform: translate(100px);/*支持Chrome浏览器 */,向x,y轴移动的像素。

    2. rotate():旋转。例:
      -webkit-transform: rotate(90deg);,旋转度数

    3. scale():缩放。-webkit-transform: scale(1,2);,宽和高

    4. skew():倾斜度数。向x,y轴倾斜的度数。

    5. matrix():矩阵的效果。

    (2)3D转换方法:

    1. rotateX():
    2. rotateY():
  • CSS动画过度:CSS3过度是元素从一种样式转化成另外一种样式。

CSS3样式:
img{-webkit-transition: width 2s,height 2s,-webkit-transform 2s;/*执行时间*/transition: width 2s,height 2s,transform 2s;transition-delay: 2s;/*延时显示动画*/}
img:hover{width:20%;height: 20%;transform: rotate(350deg);-webkit-transform: rotate(360deg);
}
  • 动画:通过CSS3考验创建动画。
    (1)遵循@keyframes规则:规定动画时长和名称。
div{width: 100px;height: 100px;background-color: aqua;position: relative;/*相对定位*/animation: anim 5s infinite alternate;/*动画执行时间为5秒,并且重复执行*/-webkit-animation: anim 5s infinite alternate;/* 按反方向执行*/}
@keyframes anim {0%{ background-color: darkgray;left: 0px;top: 0px}/*颜色和移动*/25%{background-color: blue;left: 200px;top: 0px}50%{background-color: blueviolet;left: 200px;top: 200px}75%{background-color: red;left: 200px;top: 0px}100%{background-color: black;left: 200px;top: 0px}
}
@-webkit-keyframes anim {/*适配Chrome浏览器*/0%{ background-color: darkgray;left: 0px;top: 0px}25%{background-color: blue;left: 200px;top: 0px}50%{background-color: blueviolet;left: 200px;top: 200px}75%{background-color: red;left: 200px;top: 0px}100%{background-color: black;left: 200px;top: 0px}
}
  • 多列:可以创建多列来对文本或区域进行布局。加线来分裂。也需要适配浏览器。
    (1)属性:
    1. column-count:
    2. column-gap:间距
    3. column-rule:

开发:

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><link rel="stylesheet" type="text/css" href="mycss.css">
</head>
<body><div class="container"><div class="wrapper"><div class="heading"><div class="heading_nav"><div class="heading_title">我的第一个web页面</div><div class="heading_navbar"><ul><li><a href="https://blog.csdn.net/qq_44755403">博客首页</a></li><li><a href="https://blog.csdn.net/qq_44755403/article/details/104837072">快速排序</a></li><li><a href="https://blog.csdn.net/qq_44755403/article/details/104383192">C++教程</a></li><li><a href="https://blog.csdn.net/qq_44755403/article/details/104589115">HTML教程</a></li></ul></div><div class="heading_image"><img src="../images/4.jpg" width="3%" height="3%"></div><div class="heading_sopt"><form><input type="text"></form></div></div></div><div class="body"><div class="body_title"><h3>HTML的应用</h3><p>Lorem ipsum dolor sit amet, consectetur adipisicing elit.Blanditiis dignissimos dolores earum minus, nesciunt perspiciatisquas quia, quisquam reprehenderit sapiente suscipit, tenetur?Accusamus assumenda cum est nemo nisi optio quae.Lorem ipsum dolor sit amet, consectetur adipisicing elit. Architectoat esse expedita id laborum, nihil placeat sapiente sequi solutatempore? Ab accusantium dicta hic labore obcaecati perferendisquam quidem saepe.</p></div><hr/><hr/><div class="cube"><div class="box1"><img src="http://129.211.56.163/images/1.jpg" alt="蚁人" class="img3"></div><div class="box2"><img src="http://129.211.56.163/images/2.jpg" alt="女侠" class="img3"></div><div class="box3"><img src="http://129.211.56.163/images/3.jpg" alt="美国队长" class="img3"></div><div class="box4"><img src="http://129.211.56.163/images/4.jpg" alt="全体漫威" class="img3"></div><div class="box5"><img src="http://129.211.56.163/images/5.jpg" alt="雷神" class="img3"></div><div class="box6"><img src="http://129.211.56.163/images/6.jpg" alt="钢铁侠" class="img3"></div></div>
<!--                <div>-->
<!--                    <img src="../images/4.jpg" width="10%" height="10%" align="center" class="img2">-->
<!--                </div>--></div></div><div class="footing">@1139049948</div></div>
</body>
</html>
*{margin: 0px;padding: 0px;
}
body{background-color: azure;
}
.wrapper{width: 80%;height: 1000px;background-color: aquamarine;margin: 0px auto;}
.heading{margin: 0px auto;width: 100%;height: 90px;background-color: aliceblue;
}
.heading_title{float: left;font-family: Arial;font-size: 30px;color: darkorchid;}
.heading_nav{padding-bottom: 30px;padding-top: 30px;width: 100%;height: 30px;position: relative;
}
li{padding-left: 10px;display: inline;/*一行显示*/
}
ul{margin-left: 40px;float: left;list-style: none;padding-top: 6px;padding-bottom: 6px;
}
a:link{font-weight: bold;color: darkgray;text-align: center;padding: 6px;text-decoration: none;/*去掉下化线*/
}
a:hover,a:active{color: black;}
.heading_image img{border-radius: 30px;display: inline;float: right;
}
.heading_sopt form{display: inline;float: right;width: 80px;height: 35px;position: relative;margin-right: 150px;margin-top: 5px;
}
button{float: right;margin-right: 10px;
}
from input{height: 35px;border-radius: 30px;
}
.body_title p{margin-top: 50px;margin-bottom: 20px;}
.body_title h3{font-size: 30px;font-family: Arial;width: auto;color: black;text-align: center;
}/*.img2{*/
/*    position: relative;!*相对定位*!*/
/*    animation: anim 5s infinite alternate;!*动画执行时间为5秒,并且重复执行*!*/
/*    -webkit-animation: anim 5s infinite alternate;!* 按反方向执行*!*//*}*/
/*@keyframes anim {*/
/*    0%{ background-color: darkgray;left: 0px;top: 0px}!*颜色和移动*!*/
/*    25%{background-color: blue;left: 200px;top: 0px}*/
/*    50%{background-color: blueviolet;left: 200px;top: 200px}*/
/*    75%{background-color: red;left: 0px;top: 200px}*/
/*    100%{background-color: black;left: 0px;top: 0px}*/
/*}*/
/*@-webkit-keyframes anim {!*适配Chrome浏览器*!*/
/*    0%{ background-color: darkgray;left: 0px;top: 0px}*/
/*    25%{background-color: blue;left: 200px;top: 0px}*/
/*    50%{background-color: blueviolet;left: 200px;top: 200px}*/
/*    75%{background-color: red;left: 0px;top: 200px}*/
/*    100%{background-color: black;left: 0px;top: 0px}*/
/*}*/.cube{width: 200px;height: 200px;margin: 100px auto;transform-style: preserve-3d;transform: rotateX(45deg) rotateZ(45deg);animation: rotate 20s infinite linear;}.cube>div{width: 200px;height: 200px;opacity: 0.7;position: absolute;}
.img3{width: 200px;height: 200px;vertical-align: top;}
.box1{transform: rotateY(90deg) translateZ(100px);}
.box2{transform: rotateY(-90deg) translateZ(100px);
}
.box3{transform: rotateX(90deg) translateZ(100px);;
}
.box4{transform: rotateX(-90deg) translateZ(100px);;
}
.box5{transform: translateZ(100px);
}
.box6{transform: rotateY(-180deg) translateZ(100px);
}
@keyframes rotate {form{transform: rotateX(0) rotateZ(0);}to{transform: rotateX(1turn) rotateZ(1turn);}
}
.footing{width: 80%;height: 30px;margin: 0px auto;background-color: darkgray;padding-top: 20px;text-align: center;color: black;font-size: 15px;
}

成品展示:
在这里插入图片描述

这篇关于一语道破CSS3(二)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/740973

相关文章

前端 CSS 动态设置样式::class、:style 等技巧(推荐)

《前端CSS动态设置样式::class、:style等技巧(推荐)》:本文主要介绍了Vue.js中动态绑定类名和内联样式的两种方法:对象语法和数组语法,通过对象语法,可以根据条件动态切换类名或样式;通过数组语法,可以同时绑定多个类名或样式,此外,还可以结合计算属性来生成复杂的类名或样式对象,详细内容请阅读本文,希望能对你有所帮助...

禁止HTML页面滚动的操作方法

《禁止HTML页面滚动的操作方法》:本文主要介绍了三种禁止HTML页面滚动的方法:通过CSS的overflow属性、使用JavaScript的滚动事件监听器以及使用CSS的position:fixed属性,每种方法都有其适用场景和优缺点,详细内容请阅读本文,希望能对你有所帮助... 在前端开发中,禁止htm

Vue3中的动态组件详解

《Vue3中的动态组件详解》本文介绍了Vue3中的动态组件,通过`component:is=动态组件名或组件对象/component`来实现根据条件动态渲染不同的组件,此外,还提到了使用`markRa... 目录vue3动态组件动态组件的基本使用第一种写法第二种写法性能优化解决方法总结Vue3动态组件动态

spring-boot-starter-thymeleaf加载外部html文件方式

《spring-boot-starter-thymeleaf加载外部html文件方式》本文介绍了在SpringMVC中使用Thymeleaf模板引擎加载外部HTML文件的方法,以及在SpringBoo... 目录1.Thymeleaf介绍2.springboot使用thymeleaf2.1.引入spring

部署Vue项目到服务器后404错误的原因及解决方案

《部署Vue项目到服务器后404错误的原因及解决方案》文章介绍了Vue项目部署步骤以及404错误的解决方案,部署步骤包括构建项目、上传文件、配置Web服务器、重启Nginx和访问域名,404错误通常是... 目录一、vue项目部署步骤二、404错误原因及解决方案错误场景原因分析解决方案一、Vue项目部署步骤

前端原生js实现拖拽排课效果实例

《前端原生js实现拖拽排课效果实例》:本文主要介绍如何实现一个简单的课程表拖拽功能,通过HTML、CSS和JavaScript的配合,我们实现了课程项的拖拽、放置和显示功能,文中通过实例代码介绍的... 目录1. 效果展示2. 效果分析2.1 关键点2.2 实现方法3. 代码实现3.1 html部分3.2

CSS弹性布局常用设置方式

《CSS弹性布局常用设置方式》文章总结了CSS布局与样式的常用属性和技巧,包括视口单位、弹性盒子布局、浮动元素、背景和边框样式、文本和阴影效果、溢出隐藏、定位以及背景渐变等,通过这些技巧,可以实现复杂... 一、单位元素vm 1vm 为视口的1%vh 视口高的1%vmin 参照长边vmax 参照长边re

CSS3中使用flex和grid实现等高元素布局的示例代码

《CSS3中使用flex和grid实现等高元素布局的示例代码》:本文主要介绍了使用CSS3中的Flexbox和Grid布局实现等高元素布局的方法,通过简单的两列实现、每行放置3列以及全部代码的展示,展示了这两种布局方式的实现细节和效果,详细内容请阅读本文,希望能对你有所帮助... 过往的实现方法是使用浮动加

css渐变色背景|<gradient示例详解

《css渐变色背景|<gradient示例详解》CSS渐变是一种从一种颜色平滑过渡到另一种颜色的效果,可以作为元素的背景,它包括线性渐变、径向渐变和锥形渐变,本文介绍css渐变色背景|<gradien... 使用渐变色作为背景可以直接将渐China编程变色用作元素的背景,可以看做是一种特殊的背景图片。(是作为背

CSS自定义浏览器滚动条样式完整代码

《CSS自定义浏览器滚动条样式完整代码》:本文主要介绍了如何使用CSS自定义浏览器滚动条的样式,包括隐藏滚动条的角落、设置滚动条的基本样式、轨道样式和滑块样式,并提供了完整的CSS代码示例,通过这些技巧,你可以为你的网站添加个性化的滚动条样式,从而提升用户体验,详细内容请阅读本文,希望能对你有所帮助...