当前位置: 首页 > article >正文

CSS 嵌套语法最佳实践:从入门到精通的完整指南

CSS 嵌套语法最佳实践从入门到精通的完整指南CSS 是流动的韵律JS 是叙事的节奏。而 CSS 嵌套是让这份韵律更加优雅、结构更加清晰的魔法。一、CSS 嵌套现代样式表的革命CSS 嵌套Nesting是 CSS 原生支持的特性让我们能够以更直观、更结构化的方式编写样式。不再需要重复的类名前缀不再需要深层的选择器链代码变得像诗歌一样流畅。1.1 为什么需要嵌套传统 CSS 的问题/* 没有嵌套时我们必须重复写前缀 */ .card {} .card .card-header {} .card .card-header .card-title {} .card .card-header .card-subtitle {} .card .card-body {} .card .card-footer {} .card:hover {} .card:hover .card-header {}使用嵌套后/* 结构清晰一目了然 */ .card { .card-header { .card-title {} .card-subtitle {} } .card-body {} .card-footer {} :hover { .card-header {} } }记住像素不能偏差 1px选择器的结构清晰同样不能马虎。二、基础语法 符号的奥秘2.1 符号的本质是父选择器的引用符号它代表当前选择器的完整路径。/* 基础嵌套 */ .button { background: blue; /* 会被替换为 .button */ :hover { background: darkblue; /* 编译为 .button:hover */ } /* 没有 后代选择器 */ .icon { margin-right: 8px; /* 编译为 .button .icon */ } }2.2 嵌套的编译规则/* 原始嵌套代码 */ .nav { display: flex; .nav-item { padding: 10px; .active { color: blue; } :hover { background: #f0f0f0; } } } /* 编译后的 CSS */ .nav { display: flex; } .nav .nav-item { padding: 10px; } .nav .nav-item.active { color: blue; } .nav .nav-item:hover { background: #f0f0f0; }2.3 复杂选择器的嵌套/* 属性选择器嵌套 */ [data-themedark] { --bg-color: #1a1a1a; --text-color: #ffffff; .card { background: var(--bg-color); color: var(--text-color); [data-highlight] { border-color: #4a9eff; } } } /* 伪类组合 */ .form-input { border: 1px solid #ccc; :focus, :focus-visible { border-color: blue; outline: none; } :not(:placeholder-shown) { background: #f9f9f9; } :is(:hover, :focus) { box-shadow: 0 0 0 3px rgba(0, 0, 255, 0.1); } }三、实战技巧让嵌套发挥最大价值3.1 BEM 嵌套的黄金组合/* 传统 BEM */ .block {} .block__element {} .block__element--modifier {} .block--modifier {} /* BEM 嵌套更优雅的写法 */ .block { /* 块的基础样式 */ padding: 20px; /* 元素 */ __element { margin-bottom: 10px; /* 元素的修饰符 */ --modifier { color: red; } } /* 块的修饰符 */ --modifier { background: #f0f0f0; /* 修饰符下的元素 */ .block__element { font-weight: bold; } } } /* 编译结果 */ .block { padding: 20px; } .block__element { margin-bottom: 10px; } .block__element--modifier { color: red; } .block--modifier { background: #f0f0f0; } .block--modifier .block__element { font-weight: bold; }3.2 组件化开发实践/* 按钮组件 */ .btn { --btn-bg: #007bff; --btn-color: white; --btn-padding: 10px 20px; --btn-radius: 4px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: var(--btn-padding); background: var(--btn-bg); color: var(--btn-color); border: none; border-radius: var(--btn-radius); cursor: pointer; transition: all 0.2s ease; /* 图标 */ .btn__icon { width: 16px; height: 16px; /* 图标在右侧时的间距 */ :last-child { margin-left: 4px; } /* 图标在左侧时的间距 */ :first-child { margin-right: 4px; } } /* 文字 */ .btn__text { font-size: 14px; font-weight: 500; } /* 状态 */ :hover { --btn-bg: #0056b3; transform: translateY(-1px); } :active { transform: translateY(0); } :disabled { opacity: 0.6; cursor: not-allowed; transform: none; } /* 尺寸变体 */ --sm { --btn-padding: 6px 12px; .btn__text { font-size: 12px; } } --lg { --btn-padding: 14px 28px; .btn__text { font-size: 16px; } } /* 颜色变体 */ --secondary { --btn-bg: #6c757d; :hover { --btn-bg: #545b62; } } --danger { --btn-bg: #dc3545; :hover { --btn-bg: #c82333; } } --outline { background: transparent; border: 1px solid var(--btn-bg); color: var(--btn-bg); :hover { background: var(--btn-bg); color: white; } } }3.3 响应式布局中的嵌套/* 卡片组件的响应式设计 */ .card-grid { display: grid; gap: 20px; /* 移动端单列 */ grid-template-columns: 1fr; /* 平板双列 */ media (min-width: 768px) { grid-template-columns: repeat(2, 1fr); } /* 桌面三列 */ media (min-width: 1024px) { grid-template-columns: repeat(3, 1fr); } /* 大屏四列 */ media (min-width: 1440px) { grid-template-columns: repeat(4, 1fr); } /* 卡片 */ .card { display: flex; flex-direction: column; background: white; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1); transition: transform 0.3s ease, box-shadow 0.3s ease; :hover { transform: translateY(-4px); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15); } /* 卡片图片 */ .card__image { aspect-ratio: 16 / 9; overflow: hidden; img { width: 100%; height: 100%; object-fit: cover; transition: transform 0.5s ease; } /* 悬停时图片放大 */ .card:hover img { transform: scale(1.05); } } /* 卡片内容 */ .card__content { flex: 1; padding: 20px; media (min-width: 768px) { padding: 24px; } } .card__title { font-size: 18px; font-weight: 600; margin-bottom: 8px; media (min-width: 768px) { font-size: 20px; } /* 标题链接 */ a { color: inherit; text-decoration: none; :hover { color: #007bff; } } } .card__description { color: #666; line-height: 1.6; /* 多行省略 */ display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; } /* 卡片底部 */ .card__footer { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-top: 1px solid #eee; media (min-width: 768px) { padding: 20px 24px; } } } }四、高级技巧嵌套的进阶玩法4.1 layer 与嵌套的结合/* 使用 layer 管理嵌套层级 */ layer reset, base, components, utilities; layer base { /* 基础样式 */ body { font-family: system-ui, sans-serif; line-height: 1.5; /* 嵌套基础链接样式 */ a { color: #007bff; text-decoration: none; :hover { text-decoration: underline; } } } } layer components { /* 导航组件 */ .navbar { display: flex; align-items: center; padding: 1rem 2rem; background: #fff; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); .navbar__brand { font-size: 1.5rem; font-weight: bold; a { color: #333; :hover { color: #007bff; } } } .navbar__nav { display: flex; gap: 2rem; margin-left: auto; .nav-link { color: #666; transition: color 0.2s; :hover, .active { color: #007bff; } } } } } layer utilities { /* 工具类也可以使用嵌套 */ .text-center { text-align: center; * { margin-left: auto; margin-right: auto; } } }4.2 :has() 与嵌套的强强联合/* 智能表单样式 */ .form-group { margin-bottom: 20px; label { display: block; margin-bottom: 8px; font-weight: 500; color: #333; /* 必填标记 */ .form-group:has([required]) ::after { content: *; color: #dc3545; } } input, textarea, select { width: 100%; padding: 10px 12px; border: 1px solid #ddd; border-radius: 4px; transition: border-color 0.2s, box-shadow 0.2s; :focus { border-color: #007bff; box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.1); outline: none; } /* 错误状态 */ .form-group:has(.error-message) { border-color: #dc3545; :focus { box-shadow: 0 0 0 3px rgba(220, 53, 69, 0.1); } } /* 成功状态 */ .form-group:has(.success-message) { border-color: #28a745; } } /* 错误提示 */ .error-message { display: none; margin-top: 6px; font-size: 14px; color: #dc3545; .form-group:has([aria-invalidtrue]) { display: block; } } /* 帮助文本 */ .help-text { margin-top: 6px; font-size: 14px; color: #666; } }4.3 容器查询中的嵌套/* 响应式卡片 */ .product-card { container-type: inline-size; container-name: product; .product-card__inner { display: flex; flex-direction: column; gap: 16px; /* 小容器垂直布局 */ container product (max-width: 400px) { .product-card__image { aspect-ratio: 1; } .product-card__title { font-size: 16px; } .product-card__description { display: none; } } /* 中等容器水平布局 */ container product (min-width: 401px) and (max-width: 700px) { flex-direction: row; .product-card__image { width: 40%; aspect-ratio: 1; } .product-card__content { flex: 1; } } /* 大容器完整展示 */ container product (min-width: 701px) { .product-card__image { aspect-ratio: 16 / 9; } .product-card__title { font-size: 24px; } .product-card__actions { display: flex; gap: 12px; } } } }五、避免的陷阱嵌套的注意事项5.1 过度嵌套的问题/* 不好的过度嵌套导致选择器过长 */ .page { .section { .container { .row { .col { .card { .card-body { .card-title { span { color: red; /* .page .section .container .row .col .card .card-body .card-title span */ } } } } } } } } } /* 好的保持扁平使用类名 */ .card-title { span { color: red; /* .card-title span */ } }5.2 选择器特异性管理/* 问题特异性难以预测 */ .list { .item { color: blue; /* 特异性: 0,2,0 */ } } /* 覆盖困难 */ .item.active { color: red; /* 特异性: 0,2,0 - 相同 */ } /* 解决方案使用 :where() 降低特异性 */ .list { :where(.item) { color: blue; /* 特异性: 0,1,0 */ } } /* 现在可以轻易覆盖 */ .item.active { color: red; /* 特异性: 0,2,0 - 更高 */ }5.3 符号的正确使用/* 常见错误忘记 导致后代选择器 */ .button { color: blue; /* 错误这会选择 .button 内的所有 .primary 元素 */ .primary { background: green; /* .button .primary */ } } /* 正确使用 组合选择器 */ .button { color: blue; .primary { background: green; /* .button.primary */ } /* 或者使用 BEM */ --primary { background: green; /* .button--primary */ } }六、实战项目完整的组件库/* Component Library with CSS Nesting */ /* --- Alert 组件 --- */ .alert { --alert-bg: #f8f9fa; --alert-border: #dee2e6; --alert-color: #212529; display: flex; align-items: flex-start; gap: 12px; padding: 16px; background: var(--alert-bg); border: 1px solid var(--alert-border); border-radius: 8px; color: var(--alert-color); .alert__icon { flex-shrink: 0; width: 20px; height: 20px; } .alert__content { flex: 1; } .alert__title { font-weight: 600; margin-bottom: 4px; } .alert__message { font-size: 14px; opacity: 0.9; } .alert__close { flex-shrink: 0; background: none; border: none; cursor: pointer; opacity: 0.5; transition: opacity 0.2s; :hover { opacity: 1; } } /* 变体 */ --success { --alert-bg: #d4edda; --alert-border: #c3e6cb; --alert-color: #155724; } --warning { --alert-bg: #fff3cd; --alert-border: #ffeeba; --alert-color: #856404; } --error { --alert-bg: #f8d7da; --alert-border: #f5c6cb; --alert-color: #721c24; } --info { --alert-bg: #d1ecf1; --alert-border: #bee5eb; --alert-color: #0c5460; } } /* --- Modal 组件 --- */ .modal { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; padding: 20px; background: rgba(0, 0, 0, 0.5); opacity: 0; visibility: hidden; transition: opacity 0.3s, visibility 0.3s; .is-open { opacity: 1; visibility: visible; .modal__content { transform: scale(1) translateY(0); } } .modal__content { width: 100%; max-width: 500px; max-height: 90vh; background: white; border-radius: 12px; overflow: hidden; transform: scale(0.95) translateY(-10px); transition: transform 0.3s; } .modal__header { display: flex; align-items: center; justify-content: space-between; padding: 20px; border-bottom: 1px solid #eee; } .modal__title { font-size: 18px; font-weight: 600; } .modal__body { padding: 20px; overflow-y: auto; } .modal__footer { display: flex; justify-content: flex-end; gap: 12px; padding: 16px 20px; border-top: 1px solid #eee; background: #f8f9fa; } } /* --- Tab 组件 --- */ .tabs { .tabs__list { display: flex; gap: 4px; border-bottom: 2px solid #e9ecef; margin-bottom: 20px; } .tabs__tab { padding: 12px 20px; background: none; border: none; border-bottom: 2px solid transparent; margin-bottom: -2px; cursor: pointer; font-size: 14px; font-weight: 500; color: #6c757d; transition: all 0.2s; :hover { color: #495057; background: #f8f9fa; } .is-active { color: #007bff; border-bottom-color: #007bff; } :focus { outline: none; box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.1); } } .tabs__panel { display: none; .is-active { display: block; animation: fadeIn 0.3s ease; } } } keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }七、浏览器兼容性与降级策略/* 使用 PostCSS 嵌套插件前的原始代码 */ /* 原生嵌套语法现代浏览器 */ .component { color: blue; :hover { color: red; } .child { font-size: 14px; } } /* PostCSS 编译后的代码兼容旧浏览器 */ .component { color: blue; } .component:hover { color: red; } .component .child { font-size: 14px; } /* 渐进增强策略 */ /* 基础样式所有浏览器 */ .card { } .card-header { } .card-body { } /* 增强样式支持嵌套的浏览器 */ supports (selector()) { .card { .card-header { } .card-body { } } }八、结语CSS 嵌套不仅是一种语法糖更是一种思维方式的转变。它让我们的样式代码更加结构化、可读性更强、维护成本更低。CSS 是流动的韵律JS 是叙事的节奏。CSS 嵌套是让这份韵律更加和谐、结构更加优雅的魔法。记住像素不能偏差 1px选择器的层级也不应超过必要的深度。愿你在 CSS 的世界里写出如诗如画的代码。参考资源CSS Nesting ModuleCan I Use - CSS NestingMDN - CSS Nesting

相关文章:

CSS 嵌套语法最佳实践:从入门到精通的完整指南

CSS 嵌套语法最佳实践:从入门到精通的完整指南 CSS 是流动的韵律,JS 是叙事的节奏。而 CSS 嵌套,是让这份韵律更加优雅、结构更加清晰的魔法。 一、CSS 嵌套:现代样式表的革命 CSS 嵌套(Nesting)是 CSS 原…...

volatile、内存屏障与 CPU 缓存机制详解

一、前置认知:CPU 缓存模型——并发可见性问题的根源 要理解 volatile,首先要搞懂 CPU 缓存模型。在计算机系统中,CPU 的运算速度远高于内存的读写速度,为了弥补两者之间的性能差距,CPU 厂商在 CPU 和内存之间引入了缓…...

Zemax优化别再乱点‘锤子’了!一个光学新手的真实踩坑与避坑指南

Zemax优化实战:从新手误区到高效操作的进阶指南 刚接触Zemax的光学设计师们,往往会被软件中那个神秘的"锤形优化"按钮所吸引——看似简单的点击就能自动改善设计,这种诱惑难以抗拒。但很快就会发现,盲目依赖这个功能可能…...

InnoDB 事务 undo log 与 MVCC 可视化讲解(画流程图+伪代码)

InnoDB 事务 undo log 与 MVCC 可视化讲解(画流程图+伪代码) 前言 在MySQL的InnoDB存储引擎中,事务的四大特性(ACID)是其核心能力之一。其中,隔离性(Isolation)和一致性(Consistency)的实现离不开undo log与MVCC(多版本并发控制)的精妙设计。 本文将从底层原理出…...

(论文速读)HyperFusion-DEIM:遥感影像中多路径关注与尺度感知融合的精确物体检测

论文题目:遥感影像中多路径关注与尺度感知融合的精确物体检测(Multi path attention and scale aware fusion for accurate object detection in remote sensing imagery)期刊:Scientific Reports摘要:在遥感图像中追求…...

3种方案彻底解决Windows系统APK安装难题:APK Installer技术解析

3种方案彻底解决Windows系统APK安装难题:APK Installer技术解析 【免费下载链接】APK-Installer An Android Application Installer for Windows 项目地址: https://gitcode.com/GitHub_Trending/ap/APK-Installer 多场景痛点直击:传统Android应用…...

如何快速实现Obsidian插件本地化:obsidian-i18n完整实践指南

如何快速实现Obsidian插件本地化:obsidian-i18n完整实践指南 【免费下载链接】obsidian-i18n 项目地址: https://gitcode.com/gh_mirrors/ob/obsidian-i18n 你是否曾因Obsidian插件全是英文界面而苦恼?作为中文用户,面对"Backli…...

Win11下用VMware16安装UOS服务器版全流程(附镜像+序列号)

Win11环境下VMware 16安装UOS服务器版实战指南 在数字化转型浪潮中,国产操作系统正逐步成为企业IT基础设施的新选择。统信UOS作为国内领先的服务器操作系统,凭借其稳定性与安全性,正在金融、政务等领域获得广泛应用。本文将手把手指导Windows…...

TouchGal:打造纯净Galgame社区的5个简单步骤

TouchGal:打造纯净Galgame社区的5个简单步骤 【免费下载链接】kun-touchgal-next TouchGAL是立足于分享快乐的一站式Galgame文化社区, 为Gal爱好者提供一片净土! 项目地址: https://gitcode.com/gh_mirrors/ku/kun-touchgal-next TouchGal是一个专为视觉小说…...

Cursor规则太多跑得慢?手把手教你优化.cursor配置,给VSCode插件‘减负’提速

Cursor性能优化实战:让智能编码助手重获流畅体验 当你的指尖在键盘上飞舞时,最令人沮丧的莫过于等待工具响应。作为深度集成AI能力的现代编码环境,Cursor在提供智能补全和代码建议的同时,也可能因为规则膨胀而逐渐变得迟缓。我曾见…...

解锁B站资源:BilibiliDown高效视频下载全方案

解锁B站资源:BilibiliDown高效视频下载全方案 【免费下载链接】BilibiliDown (GUI-多平台支持) B站 哔哩哔哩 视频下载器。支持稍后再看、收藏夹、UP主视频批量下载|Bilibili Video Downloader 😳 项目地址: https://gitcode.com/gh_mirrors/bi/Bilibi…...

大学物理(上)-期末实战解析(5)——刚体力学核心:从转动惯量到角动量守恒的解题秘籍

1. 刚体力学入门:为什么转动惯量是解题钥匙 刚体力学是大学物理中最让人头疼的章节之一,尤其是当题目里出现"转动惯量"这个名词时,很多同学就开始手心冒汗。记得我第一次做这类题目时,盯着那个积分符号看了半小时愣是没…...

实战调试:段页式内存管理中的首次页故障剖析

1. 段页式内存管理基础概念 段页式内存管理是现代操作系统的核心机制之一,它巧妙结合了分段和分页两种技术的优势。简单来说,就像我们整理衣柜时既按季节(分段)又用收纳盒(分页)来管理衣物。CPU看到的线性地…...

告别环境变量噩梦:一键批处理脚本详解,让QGIS在Windows下的编译配置自动化

告别环境变量噩梦:一键批处理脚本详解,让QGIS在Windows下的编译配置自动化 在GIS开发领域,QGIS作为开源地理信息系统的代表,其灵活性和可扩展性吸引了大量开发者。然而,每次从源码编译QGIS都像是一场与环境变量的搏斗—…...

解锁7大加密场景:Cryptii离线工具全攻略

解锁7大加密场景:Cryptii离线工具全攻略 【免费下载链接】cryptii Web app and framework offering modular conversion, encoding and encryption 项目地址: https://gitcode.com/gh_mirrors/cr/cryptii 在数字化时代,数据安全与格式转换成为开发…...

CentOS 6下OpenSSH从5.3升级到8.0的完整避坑指南(附Telnet备用方案)

CentOS 6环境下OpenSSH安全升级全流程:从风险规避到应急通道搭建 当一台运行CentOS 6的服务器在安全扫描中被标记出OpenSSH 5.3的高危漏洞时,任何有经验的运维工程师都会感到脊背发凉——这就像发现自家大门用的还是二十年前的挂锁。但更令人焦虑的是&am…...

别再乱接Type-C了!手把手教你设计一个5V/5A的稳定电源模块(附电路图)

5V/5A Type-C电源模块实战设计指南:从选型到避坑全解析 Type-C接口凭借其正反插拔的便利性,已成为现代电子设备的标配。但许多DIY爱好者在自制Type-C电源模块时,常遇到供电不稳、接口烧毁甚至设备损坏的问题。本文将带你从零设计一个稳定可靠…...

OpenTelemetry Operator快速入门:5分钟搞定K8s集群中的分布式追踪系统搭建

OpenTelemetry Operator快速入门:5分钟搞定K8s集群中的分布式追踪系统搭建 在云原生时代,微服务架构的复杂性让分布式追踪成为刚需。想象一下,当某个电商平台的订单服务出现延迟,你需要快速定位是支付网关、库存系统还是物流接口的…...

为什么你的USB摄像头总掉帧?深入UVC协议Alternate Setting配置避坑指南

为什么你的USB摄像头总掉帧?深入UVC协议Alternate Setting配置避坑指南 工业视觉检测线上,一台标称30fps的USB摄像头突然掉到15帧,导致传送带上的缺陷品漏检;手术内窥镜画面在关键时刻出现卡顿,医生不得不暂停操作——…...

从需求到SQL:手把手教你将‘住院管理系统’的ER图转化为可运行的数据表(附建表语句)

从需求到SQL:住院管理系统数据库设计实战指南 在医疗信息化快速发展的今天,一套设计良好的住院管理系统数据库不仅能提高医院运营效率,更能为患者提供更精准的医疗服务。本文将带你从零开始,完整实现一个住院病人信息管理系统的数…...

本地部署开源直播视频平台 Owncast 并实现外部访问

Owncast 是一款开源的、自托管的直播和视频平台,它允许用户完全掌控自己的直播基础设施、数据和观众互动,避免依赖 Twitch 、YouTube 等大型中心化平台,为内容创作者提供一个独立、去中心化的直播解决方案。本文将详细介绍如何利用 Docker 在…...

你的电机仿真结果靠谱吗?聊聊Maxwell瞬态分析里那些容易被忽略的‘坑’

电机仿真精度提升指南:Maxwell瞬态分析中的关键细节与验证方法 当你在凌晨三点盯着屏幕上那条波动异常的转矩曲线时,是否曾怀疑过自己的仿真模型在说谎?作为从业十五年的电磁仿真专家,我见过太多工程师在项目验收前夜才发现仿真结…...

Shell脚本新手必看:6种方法彻底解决Undefined Variable报错(附代码示例)

Shell脚本变量报错终极指南:从根源解决Undefined Variable问题 在Linux系统管理和自动化运维中,Shell脚本是不可或缺的工具。但许多初学者在编写脚本时,经常会遇到"Undefined Variable"这类看似简单却令人头疼的报错。这种错误不仅…...

革新性跨系统应用运行方案:APK Installer实现Windows原生Android应用体验

革新性跨系统应用运行方案:APK Installer实现Windows原生Android应用体验 【免费下载链接】APK-Installer An Android Application Installer for Windows 项目地址: https://gitcode.com/GitHub_Trending/ap/APK-Installer 当您急需在Windows电脑上运行某个…...

告别繁琐权限,uTools hosts插件一键切换与管理的效率革命

1. 为什么我们需要更优雅的hosts管理方案 每次修改hosts文件都要经历这样的痛苦循环:先要回忆文件藏在系统哪个角落,接着得用管理员身份打开文本编辑器,小心翼翼地修改内容,最后还要担心格式错误导致系统异常。作为经常需要切换开…...

3大维度解析BGE向量技术:从原理到检索增强实践

3大维度解析BGE向量技术:从原理到检索增强实践 【免费下载链接】FlagEmbedding Dense Retrieval and Retrieval-augmented LLMs 项目地址: https://gitcode.com/GitHub_Trending/fl/FlagEmbedding 文本嵌入技术是现代AI系统的核心组件,而检索增强…...

PingFangSC字体全栈应用指南:从技术原理到性能优化

PingFangSC字体全栈应用指南:从技术原理到性能优化 【免费下载链接】PingFangSC PingFangSC字体包文件、苹果平方字体文件,包含ttf和woff2格式 项目地址: https://gitcode.com/gh_mirrors/pi/PingFangSC 解析字体技术原理:为什么格式选…...

基于麻雀优化算法(SSA)优化shared TCN-Transformer模型超参数,实现时间...

基于麻雀优化算法(SSA)优化shared TCN-Transformer模型超参数,实现时间序列预测。[1]模型采用共享TCN结构,用于提取Encoder Embedding和Decoder Embedding 的因果特征,在尽可能保证模型复杂度不变的情况下,…...

FPGA实战:单总线协议解析与DHT11温湿度数据采集

1. 从零认识DHT11温湿度传感器 第一次拿到DHT11这个白色小方块时,我完全没想到这么便宜的传感器能有如此实用的功能。作为一款经典的数字温湿度复合传感器,DHT11通过单总线协议输出校准后的数字信号,省去了传统模拟传感器需要的ADC转换环节。…...

解决Windows远程桌面连接Ubuntu时xrdp闪退的配置技巧

1. 问题现象与排查思路 最近在帮同事配置Windows远程连接Ubuntu时遇到了一个典型问题:用Windows自带的远程桌面连接工具输入账号密码后,界面闪退无法进入桌面。这种情况在Ubuntu 18.04/20.04/22.04各版本中都可能出现,特别是使用GNOME桌面环…...