Web第二次方向考核复盘

一、简答题

1. (1)为什么要清除浮动?

        答:当子元素浮动时会脱离文档流,父元素无法正确计算子元素高度导致高度、边框异常显示。同时会影响后续文档流布局。

<style>.box1 {border: solid 2px #000;}.child1 {float: left;height: 200px;width: 200px;background-color: aqua;}.child2 {float: left;height: 200px;width: 200px;background-color: blue;}.box2 {height: 200px;width: 300px;background-color: pink;}</style><body><div class="box1">box1<div class="child1">child1</div><div class="child2">child2</div></div><div class="box2">box2</div>
</body>

1.(2)清除浮动的方法有哪些? 

  1. 额外标签法,给父盒子添加标签:<div class="clear"></div>>,标签定义为

    .clear{
    clear:both;
    }

    该标签必须是块级元素。清除后,父盒子可以根据子盒子的高度调整高度。

  2. 父级添加-overflow

    overflow:hidden/auto/scroll;

    注意:无法清除溢出部分

  3. after伪元素-额外标签法升级版

    .clearfix:after{content:"";display: block;height:0;clear:both;visibility:hidden;}
    .clearfix{ /* IE6、7 专有 */   *zoom:1;}

    再给父元素增加类型clearfix即可

  4. 双伪元素

    .clearfix:before,.clearfix:after {content:"";display:table;}
    .clearfix:after {clear:both;}
    .clearfix {*zoom:1;}

    再给父元素增加类型clearfix即可

2.怎么实现左边宽度固定右边宽度自适应的布局?

  1. 传统布局:左固定高度+右margin(不推荐)
  2. flex布局:给父盒子添加display:flex;属性,为其左边的子元素设置好固定宽度,为右边子元素设置flex:1属性
  3. grid布局(更现代)

    .container {display: grid;grid-template-columns: 200px 1fr; /* 第一列固定,第二列自适应 */
    }
    .left { background: #f00; }
    .right { background: #0f0; }

3. 讲讲flex:1;

        答:flex:1为该项目在含有display:flex属性的父盒子内,在主轴上在剩余空间(父盒子宽/高-主轴固定宽/高)所占有的份数为1。

<style>.box1 {display: flex;height: 500px;border: solid 2px #000;}.child1 {height: 200px;width: 200px;ackground-color: aqua;}.child2 {height: 200px;flex: 1;background-color: blue;}
</style><body><div class="box1"><div class="child1">child1</div><div class="child2">child2</div></div>
</body>

child1固定宽度,child2占主轴剩余空间1份: 

        .child3{flex:2;height: 200px;background-color: pink;}
<body><div class="box1"><div class="child1">child1</div><div class="child2">child2</div><div class="child3">child3</div></div>
</body>

 child2占据主轴剩余空间1份,child3占据两份。

4.怎么实现移动端适配不同设备?

方案1:媒体查询+rem布局

        1. 设置基准(以750px为例)

        假设设计稿宽度为 750px,约定 1rem = 100px(LESS)

/* 默认基准(适用于320px~750px屏幕) */
html {font-size: calc(100vw / 7.5); /* 750px设计稿:100px = 1rem */
}

        2. 媒体查询

/* 超小屏幕(小于320px) */
@media screen and (max-width: 320px) {html {font-size: 42.6667px; /* 320/7.5 */}
}/* 大屏幕(大于750px)限制最大缩放 */
@media screen and (min-width: 750px) {html {font-size: 100px; /* 固定最大值 */}
}

        3. 尺寸设置使用rem

.header {height: 0.88rem;  /* 设计稿88px → 0.88rem */font-size: 0.32rem; /* 设计稿32px → 0.32rem */margin: 0 0.2rem;  /* 设计稿20px → 0.2rem */
}
方案2:Viewport单位(vw/vh)(使用LESS)
/* 设计稿750px下:1vw = 7.5px */
.box {width: 13.333vw; /* 100px / 7.5 */font-size: calc(16 / 7.5 * 1vw); /* 16px */
}
方案3:媒体查询(Media Queries)
@media screen and (max-width: 320px) {body { font-size: 12px; }
}
@media screen and (min-width: 414px) {body { font-size: 18px; }
}

二、实践题

1.题目:

代码: 

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><style>.w {margin: 0 auto;}ul {padding: 0;}li {list-style: none;}.box {width: 960px;height: 400px;}header {color: #fff;font-size: 15px;width: 100%;height: 40px;background-color: #313531;border-radius: 6px;line-height: 40px;}.test {float: left;margin-left: 20px;}.imfor ul li {float: right;margin-right: 25px;}section {display: flex;justify-content: space-between;}.content {padding: 15px;background-color: #fff;height: 252px;width: 275px;border-radius: 10px;margin: 20px 0;box-shadow: 1px 2px 5px #9d9d9d;}.pic {box-sizing: border-box;height: 120px;width: 270px;background-color: #c9cdc9;border-radius: 6px;}.word {font-size: 13px;width: 270px;display: -webkit-box;-webkit-box-orient: vertical;-webkit-line-clamp: 2;line-clamp: 2;overflow: hidden;}.date {margin-top: 10px;font-size: 10px;color: #9d9d9d;}footer {line-height: 49px;text-align: center;width: 100%;height: 49px;background-color: #ecf0ec;border-radius: 12px;color: #898989;font-size: 13px;}</style>
</head><body><div class="box w"><header><div class="test">考核</div><div class="imfor"><ul><li>关于我们</li><li>文章</li><li>首页</li></ul></div></header><section><div class="content"><div class="pic"></div><h1>标题1</h1><div class="word">这是一段摘要内容,描述当前文章的简要信息。这是一段摘要内容,描述当前文章的简要信息。这是一段摘要内容,描述当前文章的简要信息。</div><div class="date">发布于2026-06-01·阅读123</div></div><div class="content"><div class="pic"></div><h1>标题1</h1><div class="word">这是一段摘要内容,描述当前文章的简要信息。这是一段摘要内容,描述当前文章的简要信息。这是一段摘要内容,描述当前文章的简要信息。</div><div class="date">发布于2026-06-01·阅读123</div></div><div class="content"><div class="pic"></div><h1>标题1</h1><div class="word">这是一段摘要内容,描述当前文章的简要信息。这是一段摘要内容,描述当前文章的简要信息。这是一段摘要内容,描述当前文章的简要信息。</div><div class="date">发布于2026-06-01·阅读123</div></div></section><footer>web第一次方向考核</footer></div>
</body></html>

效果:

注意点:

  1. 头部盒子使用左右浮动
  2. 中间盒子使用flex布局更易使内容居中对齐
  3.  文本溢出文字省略号显示:
    1. 单行
             .word{/*先强制一行内显示文本*/white-space: nowrap;/*超出部分隐藏*/overflow:hidden;/*省略号代替超出部分*/text-overflow:ellipsis;}
    2. 多行
       .word {text-overflow:ellipsis;overflow: hidden;/*弹性伸缩盒子模型显示*/display: -webkit-box;/*设置或检索伸缩盒子的子元素的排列方式*/-webkit-box-orient: vertical;/*限制在一个块元素的文本行数*/-webkit-line-clamp: 2;line-clamp: 2;}
      

2.题目:

 代码:

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><style>.box {top: 0;height: 100px;width: 70px;background-color: aquamarine;border-radius: 6px;text-align: center;font-size: 60px;overflow: hidden;}.content{position: relative;top: 0;transition: all 1s;}.box:hover .content{position: relative;top: -690px;}</style>
</head><body><div class="box"><div class="content"><div>1</div><div>2</div><div>3</div><div>4</div><div>5</div><div>6</div><div>7</div><div>8</div><div>9</div></div></div>
</body></html>

 效果:

思路:

        大盒子套小盒子,小盒子里装数字,并为小盒子添加过渡属性。当光标移至大盒子处时,小盒子向上走。

3.题目:

代码:

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><style>@keyframes change {0% {transform: scaleY(0.08);}50% {transform: scaleY(1);}100% {transform: scaleY(0.08);}}.box {display: flex;justify-content: center;align-items: center;margin: 100px auto;height: 200px;width: 100px;background-color: #fff;}div {margin-left: 2px;height: 100px;width: 5px;background-color: blue;border-radius: 3px;transition: all 1s;animation: change 2s linear infinite;}div:nth-child(n+2) {animation-delay: 0.2s;}div:nth-child(n+3) {animation-delay: 0.4s;}div:nth-child(n+4) {animation-delay: 0.6s;}div:nth-child(n+5) {animation-delay: 0.8s;}div:nth-child(n+6) {animation-delay: 1s;}div:nth-child(n+7) {animation-delay: 1.2s;}div:nth-child(n+8) {animation-delay: 1.4s;}div:nth-child(n+9) {animation-delay: 1.6s;}div:nth-child(n+10) {animation-delay: 1.8s;}div:nth-child(n+11) {animation-delay: 2s;}div:nth-child(n+12) {animation-delay: 2.2s;}</style>
</head><body><header class="box"><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div></header>
</body></html>

效果:

思路:

        给所有子盒子添加缩放动画,并按照顺序添加animation-delay属性,若要图像向右走,则delay随盒子顺序递增,若要图像向左走,delay随盒子顺序递减。

4.题目:

代码

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><style>.w {margin: 0 auto;}div:nth-child(1) {transition-delay: 0s;}div:nth-child(2) {transition-delay: 0.2s;}div:nth-child(3) {transition-delay: 0.4s;}div:nth-child(4) {transition-delay: 0.6s;}div:nth-child(5) {transition-delay: 0.8s;}div:nth-child(6) {transition-delay: 1s;}div:nth-child(7) {transition-delay: 1.2s;}div:nth-child(8) {transition-delay: 1.4s;}div:nth-child(9) {transition-delay: 1.6s;}section {display: flex;justify-content: center;align-items: center;height: 200px;width: 200px;background-color: aqua;}div {margin-left: 5px;height: 5px;width: 5px;background-color: blue;border-radius: 3px;transition: all 0.5s;}section:hover div:nth-child(1) {height: 15px;}section:hover div:nth-child(2) {height: 30px;}section:hover div:nth-child(3) {height: 45px;}section:hover div:nth-child(4) {height: 45px;margin-top: 10px;}section:hover div:nth-child(5) {height: 50px;margin-top: 25px;}section:hover div:nth-child(6) {height: 45px;margin-top: 10px;}section:hover div:nth-child(7) {height: 45px;}section:hover div:nth-child(8) {height: 30px;}section:hover div:nth-child(9) {height: 15px;}</style>
</head><body><section class="w"><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div></section>
</body></html>

 效果:

思路:

        要求元素做到hover响应,并在光标移开时相应元素也有相应的延迟过渡,如果响应设置为动画并添加到hover伪类中,光标移开动画属性即撤销,要做到撤销后仍保留动画还原的推迟,这是html和css范围内的基础动画无法实现的,考虑使用过渡。

        我们知道光标移开后hover属性撤销,想要实现撤销后仍然有延迟过渡,我们需要该元素本身就有延迟过渡的属性,所以先为各元素设置其自身的延迟过渡:

        div:nth-child(1) {transition-delay: 0s;}div:nth-child(2) {transition-delay: 0.2s;}div:nth-child(3) {transition-delay: 0.4s;}div:nth-child(4) {transition-delay: 0.6s;}div:nth-child(5) {transition-delay: 0.8s;}div:nth-child(6) {transition-delay: 1s;}div:nth-child(7) {transition-delay: 1.2s;}div:nth-child(8) {transition-delay: 1.4s;}div:nth-child(9) {transition-delay: 1.6s;}

        然后设置hover的变化:

        section:hover div:nth-child(1) {height: 15px;}section:hover div:nth-child(2) {height: 30px;}section:hover div:nth-child(3) {height: 45px;}section:hover div:nth-child(4) {height: 45px;margin-top: 10px;}section:hover div:nth-child(5) {height: 50px;margin-top: 25px;}section:hover div:nth-child(6) {height: 45px;margin-top: 10px;}section:hover div:nth-child(7) {height: 45px;}section:hover div:nth-child(8) {height: 30px;}section:hover div:nth-child(9) {height: 15px;}

         效果实现,针对想要的特殊情况再进行特别修改即可。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.pswp.cn/news/909534.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Linux入门(十八)read函数

read 读取控制台输入 基本语法 read 选项 参数 选项 -p 指定读取值时的提示符 -t 指定读取值时等待的时间&#xff08;秒&#xff09;&#xff0c;如果没有在指定的时间内输入&#xff0c;就不再等待了 参数 变量&#xff1a;指定读取值的变量名 实例&#xff1a; 1、读取控制…

Python 文件操作详解

文章目录 Python 文件操作详解一、文件操作的基本流程二、文件打开模式详解1. 基本模式2. 扩展模式3. 模式组合示例 三、文件操作方法大全1. 打开和关闭文件2. 读取文件内容3. 写入文件内容4. 文件指针操作 四、文件编码处理五、二进制文件操作六、常见文件操作场景1. 文件内容…

用AI配合MCP快速生成n8n工作流

在数字化时代的浪潮中&#xff0c;AI技术正以前所未有的速度改变着我们的生活和工作方式。从智能家居到智能办公&#xff0c;从数据分析到自动化流程&#xff0c;AI的应用场景无处不在。今天&#xff0c;我们将带你走进一个充满创新与效率的世界&#xff0c;探索如何通过AI大眼…

ArkUI-X框架LogInterface使用指南

ArkUI-X框架支持日志拦截能力&#xff0c;Android侧提供原生接口&#xff0c;用于注入LogInterface接口&#xff0c;框架日志及ts日志通过该接口输出&#xff0c;本文的核心内容是介绍如何在Android平台上有效利用ArkUI-X框架的LogInterface拦截日志。 Android平台创建ArkUI-X…

函数重载与函数模板

函数重载与函数模板 函数重载 函数组成 返回类型 函数名称(参数列表){函数体}函数签名&#xff1a;函数名称(参数列表) C 允许定义同名函数&#xff0c;前提是它们具有不同的签名。这被称为函数重载 。 C 编译器通过检查调用中参数的数量、类型和顺序来选择要调用的适当函…

NLP学习路线图(四十六):可解释性

在自然语言处理(NLP)技术重塑人机交互、信息检索甚至司法决策的今天,一个尖锐的问题愈发凸显:当模型在文本分类中判定你的贷款申请被拒,或在简历筛选中将你排除,你是否有权追问一句——“为什么?” 一、黑箱迷雾:NLP模型的不透明困境 现代NLP的核心驱动力——深度神经…

uniapp的app项目,在华为pad上运行,页面显示异常

最开始为了好调试&#xff0c;运行成h5在浏览器调试的&#xff0c;调完以后&#xff0c;放到pad上。。。天塌了&#xff0c;所有页面异常&#xff0c;感觉被放大了好多&#xff0c;而且页面很乱。。。 查了很多资料&#xff0c;说把px改为rpx&#xff0c;好&#xff0c;全部改…

Linux中的连接符

Linux中的&&连接符 和其它语言类似&#xff0c;在Shell中&#xff0c;&&是一个逻辑运算符&#xff0c;表示逻辑AND&#xff0c;用于连接多个条件表达式 不同的是&#xff0c;在Linux系统中&#xff0c;&&不仅可以连接条件表达式&#xff0c;而且还能连…

装饰模式Decorator Pattern

模式定义 动态地给对象增加额外的职责 对象结构型模式 模式结构 Component&#xff1a;抽象构件 ConcreteComponent&#xff1a; 具体构件 Decorator&#xff1a;抽象装饰类 ConcreteDecorator&#xff1a; 具体装饰类 抽象装饰类代码 public class Decorator extends Compo…

https说明

http是无状态的&#xff0c;https是在http应用层协议和tcp传输控制层之间加了一层&#xff0c;主要功能包括加密传输内容&#xff0c;校验信息是否完整&#xff0c;信息是否被篡改等。http的网络传输&#xff0c;源端应用层发送http请求&#xff0c;传输到源端的控制层&#xf…

实时操作系统(FreeRTOS、RT-Thread)RISC-V

FreeRTOS&#xff1a;FreeRTOS™ - FreeRTOS™ RT-Thread&#xff1a;rt-thread.org VxWorks&#xff1a; QNX Neutrino RTOS&#xff1a; RT-Linux&#xff1a; 一、 实时操作系统介绍 实时操作系统&#xff08;Real Time Operating System&#xff0c;简称RTOS&#xff…

Python3除标准库外更全面的XML解析方案

一、扩展解析库方案 lxml高性能解析 from lxml import etree doc etree.parse(data.xml) # XPath 2.0增强查询 nodes doc.xpath(//student[score>90]/name/text())优势&#xff1a;支持XPath 2.0语法和XSLT转换&#xff0c;比标准库快5-10倍 BeautifulSoup混合解析 fr…

同时装两个MySQL, 我在MySQL5的基础上, 安装MySQL8

目录 1. 前言 2. 下载MySQL 3. 安装MySQL 3.1 第一步:选择MySQL ​编辑 3.2 第二步:存储地址 3.3 第三步 3.4 第四步:完成基础配置 3.5 第五步 3.6 第六步:数据库密码 3.7 第七部:服务名 4. 环境变量 4.1 复制MySQL的bin地址 4.2 进入高级系统设置 4.3 PATH 4.4 更改…

Visual Studio 2022打包程序流程

Visual Studio 2022打包程序流程 打开管理拓展 安装Microsoft Visual Studio Installer Projects 关闭软件才能继续安装 安装完成后点击&#xff0c;解决方案&#xff0c;创建新项目 添加&#xff1a;setup project 打开软件的路径 复制路径 添加文件 粘贴刚才复制的路径&…

web3方法详解

web3.py 是一个功能强大的 Python 库,用于与以太坊区块链交互。它提供了多种模块和功能,涵盖账户管理、智能合约交互、交易发送、区块链数据查询等。以下是 web3.py 的主要功能模块及其用途: 1. Web3 核心模块 功能:提供基础连接、工具函数和核心功能。 常用方法: Web3(…

HTML5+JS实现一个简单的SVG 贝塞尔曲线可视化设计器,通过几个点移动位置,控制曲线的方向

三次贝塞尔曲线,二次贝塞尔曲线有什么区别 https://blog.csdn.net/xiaoyao961/article/details/148678265 SVG 贝塞尔曲线可视化设计器 下面是一个简单的贝塞尔曲线可视化设计器&#xff0c;使用 HTML5 和 JavaScript 实现。这个设计器允许你通过拖动控制点来实时调整贝塞尔曲…

Pytorch框架——自动微分和反向传播

一、自动微分概念 自动微分&#xff08;Automatic Differentiation&#xff0c;AD&#xff09;是一种利用计算机程序自动计算函数导数的技术&#xff0c;它是机器学习和优化算法中的核心工具&#xff08;如神经网络的梯度下降&#xff09;&#xff0c;通过反向传播计算并更新梯…

【Linux手册】进程的状态:从创建到消亡的“生命百态”

目录 前言 操作系统进程状态 运行状态 阻塞状态 挂起状态 Linux中具体的进程状态 R(running)运行状态 S(sleeping)阻塞状态 D(disk sleep)磁盘休眠状态 T(stopped)和t(tracing stop) X(dead)终止状态 Z(zombie)僵尸状态 僵尸进程的危害 前言 我们在运行可执行程序…

李沐--动手学深度学习 LSTM

1.从零开始实现LSTM #从零开始实现长短期记忆网络 import torch from torch import nn from d2l import torch as d2l#加载时光机器数据集 batch_size,num_steps 32,35 train_iter,vocab d2l.load_data_time_machine(batch_size,num_steps)#1.定义和初始化模型参数&#xff…

面经的疑难杂症

1.介绍一下虚拟地址&#xff0c;虚拟地址是怎么映射到物理地址的&#xff1f; 虚拟地址是指在采用虚拟存储管理的操作系统中&#xff0c;进程访问内存时所使用的地址。每个进程都有独立的虚拟地址空间&#xff0c;虚拟地址通过操作系统和硬件&#xff08;如MMU&#xff0c;内存…