当前位置:网站首页>避免滥用class样式
避免滥用class样式
2022-06-09 13:44:00 【金木杂谈】
多类症
有些初学者给大部分元素都添加类,以便更方便的控制它们,这种现象叫“多类症”,产生了大量无意义的代码。我们应该尽可能少使用类,通过包含框选择器识别元素。
示例:
<div class=“news”><h1>标题新闻</h1><p>新闻内容</p></div>
不要再为<h1> ,<p>标签添加class类,而应该通过选择器识别元素。
news h1{ color:black }
news p{ color:blue }
使用语义化标签
标签都拥有不同的语义,这样就不用为它们定义id和class,也方便CSS选择。
HTML包含丰富的标签,要正确选用它们。
<h1> <h2> <h3> <h4> <h5> <h6>
<p> 定义段落文本
<ul><ol><li> 等:定义信息列表、导航列表、榜单结构等
<table><tr><td>等:定义表格结构
<form><input><textarea>等:定义表单结构
<span>:定义行内包含框
示例:
<header>页眉区域</header>
<section>
<article>1.主体内容区域</article>
<nav>2.导航栏</nav>
<aside>3.其它栏目</aside>
</section>
<header>: 定义section或page的页眉
<section>: 对网站页面上内容进行分区
<article>:定义文章
<nav>:定义导航条
<aside>:定义页面内容之外的内容,如侧边栏、服务栏等
<footer>: 定义section或page的页脚
减少冗余标签
为了减少不必要的标签,应该避免不必要的嵌套。
示例:
<div id=“nav”><ul><li></li><li></li></ul></div>
完全可以将最外层div删除,直接在ul上设置id。过度使用div是结构不合理的一种表现,也容易造成结构复杂化。
边栏推荐
- MySQL数据库(25):外键 foreing key
- Docker-Compose实现Mysql主从
- MySQL事务
- TCP/IP协议(1)
- I haven't published a thesis for 5 years, and I want to give up my doctoral degree? Ten thousand words self narration of the doctoral director of the University of science and technology of China: he
- Uniswap合约学习-- Uniswap UNI Token
- 管理全局变量(二)
- 黄金频段乃第四大运营商杀手锏,农民将获得低价5G服务
- Enter a line of characters (80 at most), start from the location, intercept number characters and output them.
- 5年没发论文,读博想放弃?中科大博导万字自述:曾连收13封拒稿信...
猜你喜欢

从刚入测试界到薪资翻倍:聊聊我的测试进阶历程,值得借鉴

I customized a mechanical keyboard for the InfoQ writing community to celebrate my birthday

< test> basic knowledge interview test site

Leetcode longest sequence

为什么 SQL 语句使用了索引,但却还是慢查询?

ThreadLocal还不会?来看看!

数据科学中的 10 个重要概念和图表的含义

At the age of 26, he published 18 papers and just proved the prime number conjecture of the last century

AI 考生挑战高考作文,平均 1 秒生成 1 篇,水平超 75% 考生

In WinCC, how to use C script to set + reset + negate variables?
随机推荐
【计网】思科 期末选择题复习
UniswapV2周边合约学习(七)-- ExampleSlidingWindowOracle.sol
Meanings of 10 important concepts and charts in Data Science
八股文天花板!(PDF高清下载)
4427 node sum in tree (greedy)
ERC721非同质代币(NFT)介绍
Common image segmentation methods
汇编语言入门-指令与寻址方式
今天19:30 | 图形学专场—中国科学院计算技术研究所高林老师团队
Like the brain, the nano magnet network can be used to perform AI like computing processing, which can reduce energy consumption
多元时间序列分析 —— 因果检验
颠覆认知!数据增强、正则化可导致不易察觉的灾难?
5年没发论文,读博想放弃?中科大博导万字自述:曾连收13封拒稿信...
FFMPEG对HLS切片的支持
Avenue to simplicity | how to configure self attention for vit is the most reasonable?
CNN's performance is even stronger without looking at the whole picture and the parts
发邮件:错排问题的分析
Vscode markdown 添加、粘贴、导入图片
Vscade markdown add, paste and import pictures
软件配置项变更与基线变更