我是靠谱客的博主 秀丽信封,最近开发中收集的这篇文章主要介绍HTML元素的分类,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

查看参考链接:https://www.w3.org/TR/html5/dom.html#phrasing-content
在这里插入图片描述

<!doctype html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <meta name="Generator" content="EditPlus®">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
  <title>HTML元素的分类</title>
 </head>
 <body>
	<header>
		<h1>HTML元素的分类</h2>
	</header>
	<article>
		<h2>HTML按默认样式分</h2>
		<p>块级:block</p>
		<p>行内/内联元素:inline(跟文本相关的元素em,span,strong)</p>
		<p>内联块级元素:inline-block(表单元素input)</p>
	</article>
	<article>
		<h2>HTML5中可以按内容分</h2>
		<img src="./HTML5根据内容模型区分.jpg">
		<p>
			flow是文档流,是一些可视元素
		</p>
		<p>
			(1)metaData有一部分在flow外的主要是
			meta,title,script和style标签不占据文档流
		</p>
		<p>
			(2)heading元素是从h1-h6还有一些是hgroup元素
		</p>
		<p>
			(3)Sectioning分区元素:header,article,和footer等
		</p>
		<p>
			
			(4)interactive互动元素,如a标签等
		</p>
		<p>
			(5)pharsing 短语 em
		</p>
		<p>
			(6)emembed嵌入其他的元素 img video等标签
		</p>
		
	</article>
 </body>
</html>

最后

以上就是秀丽信封为你收集整理的HTML元素的分类的全部内容,希望文章能够帮你解决HTML元素的分类所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(43)

相关文章

html常用语义化元素和全局属性整理WWW<HTML>元素全局属性<id>全局属性<class>全局属性<title>全局属性<lang>全局属性标签与元素<link>外部资源链接元素<a>内联元素<artice>块级元素<section>块级元素<nav>块级元素<aside>块级元素<h1~h6>块级元素<header>块级元素<footer>块级元素<address>块级元素<p>块级元素<hr>块级元素<pre>块级元素<blockquote>块级元素<ol>块级元素<ul>块级元素<l
html常用语义化元素和全局属性整理WWW元素全局属性全局属性全局属性全局属性<lang>全局属性标签与元素<link>外部资源链接元素<a>内联元素<artice>块级元素<section>块级元素<nav>块级元素<aside>块级元素<h1~h6>块级元素<header>块级元素<footer>块级元素<address>块级元素<p>块级元素<hr>块级元素<pre>块级元素<blockquote>块级元素<ol>块级元素<ul>块级元素<l</a></h5> </div> <div class="col-sm-3 col-xs-6"> <a href="/article/k-p-k_14_uzo_6_fx_13_z_2_5.html" class="img-zoom"> <div class="embed-responsive embed-responsive-4by3"> <img src="/uploads/reation/bcimg6.png" alt="HTML5学习笔记-常用标记" class="embed-responsive-item"> </div> </a> <h5 class="text-center"><a href="/article/k-p-k_14_uzo_6_fx_13_z_2_5.html">HTML5学习笔记-常用标记</a></h5> </div> <div class="col-sm-3 col-xs-6"> <a href="/article/k-p-k_14_uzo_6_fx_13_zcw.html" class="img-zoom"> <div class="embed-responsive embed-responsive-4by3"> <img src="/uploads/reation/bcimg7.png" alt="HTML元素的分类" class="embed-responsive-item"> </div> </a> <h5 class="text-center"><a href="/article/k-p-k_14_uzo_6_fx_13_zcw.html">HTML元素的分类</a></h5> </div> <div class="col-sm-3 col-xs-6"> <a href="/article/k-p-k_14_uzo_6_fx_13_zcx.html" class="img-zoom"> <div class="embed-responsive embed-responsive-4by3"> <img src="/uploads/reation/bcimg8.png" alt="HTML5所有常用元素和属性HTML5所有常用元素和属性" class="embed-responsive-item"> </div> </a> <h5 class="text-center"><a href="/article/k-p-k_14_uzo_6_fx_13_zcx.html">HTML5所有常用元素和属性HTML5所有常用元素和属性</a></h5> </div> <div class="col-sm-3 col-xs-6"> <a href="/article/k-p-k_14_uzo_6_fx_13_zcy.html" class="img-zoom"> <div class="embed-responsive embed-responsive-4by3"> <img src="/uploads/reation/bcimg9.png" alt="HTML5元素类型" class="embed-responsive-item"> </div> </a> <h5 class="text-center"><a href="/article/k-p-k_14_uzo_6_fx_13_zcy.html">HTML5元素类型</a></h5> </div> <div class="col-sm-3 col-xs-6"> <a href="/article/k-p-k_14_uzo_6_fx_13_zcz.html" class="img-zoom"> <div class="embed-responsive embed-responsive-4by3"> <img src="/uploads/reation/bcimg10.png" alt="H5学习笔记之元素分类" class="embed-responsive-item"> </div> </a> <h5 class="text-center"><a href="/article/k-p-k_14_uzo_6_fx_13_zcz.html">H5学习笔记之元素分类</a></h5> </div> <!-- E 相关文章 --> </div> </div> <div class="clearfix"></div> </div> </div> <div class="panel panel-default" id="comments"> <div class="panel-heading"> <h3 class="panel-title">评论列表<small>共有 <span>0</span> 条评论</small></h3> </div> <div class="panel-body"> <div id="comment-container"> <!-- S 发表评论 --> <div id="postcomment"> <h3>发表评论 <a href="javascript:;"> <small>取消回复</small> </a></h3> <form action="/comment/post.html" method="post" id="postform"> <input type="hidden" name="__token__" value="d0f489d50ab301d8ad1aca03b406822d" /> <input type="hidden" name="type" value="archives"/> <input type="hidden" name="artid" value="351770"/> <input type="hidden" name="pid" id="pid" value="0"/> <div class="form-group"> <textarea name="content" class="form-control" disabled placeholder="请登录后再发表评论" id="commentcontent" cols="6" rows="5" tabindex="4"></textarea> </div> <div class="form-group"> <a href="/index/user/login.html" class="btn btn-primary">登录</a> <a href="/index/user/register.html" class="btn btn-outline-primary">注册新账号</a> </div> </form> </div> <!-- E 发表评论 --> </div> </div> </div> </main> <aside class="col-xs-12 col-md-4"> <!--@formatter:off--> <!-- S 关于作者 --> <div class="panel panel-default about-author no-padding" data-id="36502" itemProp="author" itemscope="" itemType="http://schema.org/Person"> <meta itemProp="name" content="秀丽信封"/> <meta itemProp="image" content="/assets/img/avatar.png"/> <meta itemProp="url" content="/u/k-p-k_14_uzo_2_f1_14__23__18__27_.html"/> <div class="panel-body no-padding"> <div class="author-card"> <div class="author-head" style="background-image:url('/assets/img/author-head.jpeg');"></div> <div class="author-avatar"> <a href="/u/k-p-k_14_uzo_2_f1_14__23__18__27_.html"> <img src="/assets/img/avatar.png"> </a> </div> <div class="author-basic"> <div class="author-nickname"> <a href="/u/k-p-k_14_uzo_2_f1_14__23__18__27_.html">秀丽信封</a> </div> <span class="text-muted"></span> </div> <div class="row author-statistics"> <div class="col-xs-4"> <div class="statistics-text">文章</div> <div class="statistics-nums"><a href="/u/k-p-k_14_uzo_2_f1_14__23__18__27_.html">6</a></div> </div> <div class="col-xs-4"> <div class="statistics-text">资源</div> <div class="statistics-nums"><a href="/u/k-p-k_14_uzo_2_f1_14__23__18__27_.html?type=soft">0</a></div> </div> <div class="col-xs-4"> <div class="statistics-text">加入时间</div> <div class="statistics-nums">2年前</div> </div> </div> </div> </div> </div> <!-- E 关于作者 --> <!--@formatter:on--> <div class="panel panel-blockimg"> </div> <!-- S 热门文章 --> <div class="panel panel-default hot-article"> <div class="panel-heading"> <h3 class="panel-title">热门文章</h3> </div> <div class="panel-body"> <div class="media media-number"> <div class="media-left"> <span class="num tag">1</span> </div> <div class="media-body"> <a class="link-dark" href="/article/k-p-k_12_u_23_ogfz_13_jk_27_.html" title="JavaScript 一道字符串分解的题目">JavaScript 一道字符串分解的题目</a> </div> </div> <div class="media media-number"> <div class="media-left"> <span class="num tag">2</span> </div> <div class="media-body"> <a class="link-dark" href="/article/k-p-k_14_u_7_o_22_fx_13_j_10_w.html" title="mysql注入导库脚本代码">mysql注入导库脚本代码</a> </div> </div> <div class="media media-number"> <div class="media-left"> <span class="num tag">3</span> </div> <div class="media-body"> <a class="link-dark" href="/article/k-p-k_14_ujokfw_13__7__26_2.html" title="STM32之数据采集和心率检测仪(原理图、PCB、程序源码等)超详细!!!1.系统硬件设计2.系统软件设计3.系统测试">STM32之数据采集和心率检测仪(原理图、PCB、程序源码等)超详细!!!1.系统硬件设计2.系统软件设计3.系统测试</a> </div> </div> <div class="media media-number"> <div class="media-left"> <span class="num tag">4</span> </div> <div class="media-body"> <a class="link-dark" href="/article/k-p-k_14_uzo_18_f1_12__23_gz.html" title="包管理器概述一、包管理器概述">包管理器概述一、包管理器概述</a> </div> </div> <div class="media media-number"> <div class="media-left"> <span class="num tag">5</span> </div> <div class="media-body"> <a class="link-dark" href="/article/k-p-k_14_uzo_6_fx_13_zcw.html" title="HTML元素的分类">HTML元素的分类</a> </div> </div> <div class="media media-number"> <div class="media-left"> <span class="num tag">6</span> </div> <div class="media-body"> <a class="link-dark" href="/article/k-p-k_14_uzokf2_14_z_26_2.html" title="PAT乙级1006 换个格式输出整数 (15分)(C语言版)及解析">PAT乙级1006 换个格式输出整数 (15分)(C语言版)及解析</a> </div> </div> </div> </div> <!-- E 热门文章 --> <!-- S 热门资讯 --> <div class="panel panel-default hot-article"> <div class="panel-heading"> <h3 class="panel-title">推荐资讯</h3> </div> <div class="panel-body"> <div class="media media-number"> <div class="media-left"> <span class="num tag">1</span> </div> <div class="media-body"> <a class="link-dark" href="/news/k-p-k_13_u_7_ogf1_14_j_18__27_.html" title="李想公布四季度目标:预计交付量将达到16-17万辆">李想公布四季度目标:预计交付量将达到16-17万辆</a> </div> </div> <div class="media media-number"> <div class="media-left"> <span class="num tag">2</span> </div> <div class="media-body"> <a class="link-dark" href="/news/k-p-k_13_u_7_ogfz_13_zk_27_.html" title="下载次数破39万,CMU、Meta联合发布VQAScore文生图优化方案:Imagen3已采用背景介绍VQAScore:一种简单有效的评估指标VQAScore实验结果GenAI-Bench:由设计师收集的高难度文生图基准GenAI-Rank:用VQAScore来提升文生图表现">下载次数破39万,CMU、Meta联合发布VQAScore文生图优化方案:Imagen3已采用背景介绍VQAScore:一种简单有效的评估指标VQAScore实验结果GenAI-Bench:由设计师收集的高难度文生图基准GenAI-Rank:用VQAScore来提升文生图表现</a> </div> </div> <div class="media media-number"> <div class="media-left"> <span class="num tag">3</span> </div> <div class="media-body"> <a class="link-dark" href="/news/k-p-k_13_u_7_ogfx_14_z_14__27_.html" title="日本将迎来最强大AI超算!NVIDIA+软银联手打造">日本将迎来最强大AI超算!NVIDIA+软银联手打造</a> </div> </div> <div class="media media-number"> <div class="media-left"> <span class="num tag">4</span> </div> <div class="media-body"> <a class="link-dark" href="/news/k-p-k_13_u_7_ogfx_14_j_14__27_.html" title="李子柒终于回归,4小时涨粉超200万">李子柒终于回归,4小时涨粉超200万</a> </div> </div> <div class="media media-number"> <div class="media-left"> <span class="num tag">5</span> </div> <div class="media-body"> <a class="link-dark" href="/news/k-p-k_13_u_7_ogf2_14__23__6__27_.html" title="暖气费别忘交 国家气候中心:今年冬天较易出现强降温、强降雪">暖气费别忘交 国家气候中心:今年冬天较易出现强降温、强降雪</a> </div> </div> <div class="media media-number"> <div class="media-left"> <span class="num tag">6</span> </div> <div class="media-body"> <a class="link-dark" href="/news/k-p-k_13_u_7_ogf1_13_j_14__27_.html" title="苹果喊话iPhone 13和14钉子户换机 宋紫薇:苹果营销真接地气苹果向 iPhone 13 和 14 用户发出升级呼吁">苹果喊话iPhone 13和14钉子户换机 宋紫薇:苹果营销真接地气苹果向 iPhone 13 和 14 用户发出升级呼吁</a> </div> </div> <div class="media media-number"> <div class="media-left"> <span class="num tag">7</span> </div> <div class="media-body"> <a class="link-dark" href="/news/k-p-k_13_u_7_ogfx_14_j_10__27_.html" title="李子柒粉丝过亿 停更期间拜访了许多非遗传人">李子柒粉丝过亿 停更期间拜访了许多非遗传人</a> </div> </div> <div class="media media-number"> <div class="media-left"> <span class="num tag">8</span> </div> <div class="media-body"> <a class="link-dark" href="/news/k-p-k_13_u_7_ogfx_14_j_6__27_.html" title="撞劳斯莱斯货车司机儿子发声被指不感恩 女车主三天涨粉超90万">撞劳斯莱斯货车司机儿子发声被指不感恩 女车主三天涨粉超90万</a> </div> </div> <div class="media media-number"> <div class="media-left"> <span class="num tag">9</span> </div> <div class="media-body"> <a class="link-dark" href="/news/k-p-k_13_u_7_okf1_14__7_g_27_.html" title="2024 广州国际车展展位图公布,11 月 15 日开幕">2024 广州国际车展展位图公布,11 月 15 日开幕</a> </div> </div> <div class="media media-number"> <div class="media-left"> <span class="num tag">10</span> </div> <div class="media-body"> <a class="link-dark" href="/news/k-p-k_13_u_7_ogfz_13_jg_27_.html" title="ChatGPT搜索?也就那样">ChatGPT搜索?也就那样</a> </div> </div> </div> </div> <!-- E 热门资讯 --> <div class="panel panel-blockimg"> <a href="https://www.aliyun.com/daily-act/ecs/activity_selection?userCode=2qwpuaqd" rel="nofollow" title="推荐企业服务器" target="_blank"> <img src="/uploads/store/aliyun-sidebar.png" class="img-responsive" alt=""> </a> </div> <!-- S 热门标签 --> <div class="panel panel-default hot-tags"> <div class="panel-heading"> <h3 class="panel-title">热门标签</h3> </div> <div class="panel-body"> <div class="tags"> <a href="/u/k-p-k_14_uzo_2_f1_14__23__18__27_/category/k-p-k_14_u_7_o_22_f3_12__23__14_4.html" class="tag"> <span>系统进程</span></a> <a href="/u/k-p-k_14_uzo_2_f1_14__23__18__27_/category/k-p-k_14_uzo_2_f0_14_j_18_y.html" class="tag"> <span>JavaScript</span></a> <a href="/u/k-p-k_14_uzo_2_f1_14__23__18__27_/category/k-p-k_14_uzogfz_13__23__2_w.html" class="tag"> <span>安全攻防</span></a> <a href="/u/k-p-k_14_uzo_2_f1_14__23__18__27_/category/k-p-k_13_u_7_o_14_f4_14_zc3.html" class="tag"> <span>单片机</span></a> <a href="/u/k-p-k_14_uzo_2_f1_14__23__18__27_/category/k-p-k_13_u_7_ocfz_13__23_kx.html" class="tag"> <span>包管理器</span></a> <a href="/u/k-p-k_14_uzo_2_f1_14__23__18__27_/category/k-p-k_13_u_7_okf4_12__7_c2.html" class="tag"> <span>HTML+CSS</span></a> <a href="/u/k-p-k_14_uzo_2_f1_14__23__18__27_/category/k-p-k_13_ujo_10_fy_13__23__10_5.html" class="tag"> <span>PAT乙级真题</span></a> </div> </div> </div> <!-- E 热门标签 --> <!-- S 推荐下载 --> <div class="panel panel-default recommend-article"> <div class="panel-heading"> <h3 class="panel-title">推荐下载</h3> </div> <div class="panel-body"> <div class="media media-number"> <div class="media-left"> <span class="num tag">1</span> </div> <div class="media-body"> <a href="/soft/k-p-k_12_u_7_o_10_fy_13_w_27__27_.html" title="VMware Workstation Pro 17.5.2 纯天然绿色完整版下载">VMware Workstation Pro 17.5.2 纯天然绿色完整版下载</a> </div> </div> <div class="media media-number"> <div class="media-left"> <span class="num tag">2</span> </div> <div class="media-body"> <a href="/soft/k-p-k_12_u_7_o_10_fz_14_w_27__27_.html" title="PhpStudy8.1小皮面板">PhpStudy8.1小皮面板</a> </div> </div> <div class="media media-number"> <div class="media-left"> <span class="num tag">3</span> </div> <div class="media-body"> <a href="/soft/k-p-k_12_u_7_o_10_fy_14_w_27__27_.html" title="火焰纹章 无双|官方中文|本体+1.5.0升补+5DLC | [NSP]">火焰纹章 无双|官方中文|本体+1.5.0升补+5DLC | [NSP]</a> </div> </div> <div class="media media-number"> <div class="media-left"> <span class="num tag">4</span> </div> <div class="media-body"> <a href="/soft/k-p-k_12_u_7_o_10_fz_14__10__27__27_.html" title="视频音频编辑软件 Adobe Premiere Pro 2020 绿色便携免费版">视频音频编辑软件 Adobe Premiere Pro 2020 绿色便携免费版</a> </div> </div> <div class="media media-number"> <div class="media-left"> <span class="num tag">5</span> </div> <div class="media-body"> <a href="/soft/k-p-k_12_u_7_o_10_fz_14__26__27__27_.html" title="Photoshop CS6 中文汉化精简版">Photoshop CS6 中文汉化精简版</a> </div> </div> <div class="media media-number"> <div class="media-left"> <span class="num tag">6</span> </div> <div class="media-body"> <a href="/soft/k-p-k_12_u_7_o_10_fy_13__10__27__27_.html" title="Adobe Fireworks CS6绿色精简版下载">Adobe Fireworks CS6绿色精简版下载</a> </div> </div> <div class="media media-number"> <div class="media-left"> <span class="num tag">7</span> </div> <div class="media-body"> <a href="/soft/k-p-k_12_u_7_o_10_fy_12__10__27__27_.html" title="Photoshop CS6 Extend 绿色增强版">Photoshop CS6 Extend 绿色增强版</a> </div> </div> <div class="media media-number"> <div class="media-left"> <span class="num tag">8</span> </div> <div class="media-body"> <a href="/soft/k-p-k_12_u_7_o_10_fy_13__26__27__27_.html" title="Adobe FireWorks cs5【FW cs5 】中文绿色版下载">Adobe FireWorks cs5【FW cs5 】中文绿色版下载</a> </div> </div> <div class="media media-number"> <div class="media-left"> <span class="num tag">9</span> </div> <div class="media-body"> <a href="/soft/k-p-k_12_u_7_o_10_fy_12__26__27__27_.html" title="Photoshop CS6中文精简版">Photoshop CS6中文精简版</a> </div> </div> <div class="media media-number"> <div class="media-left"> <span class="num tag">10</span> </div> <div class="media-body"> <a href="/soft/k-p-k_12_u_7_o_10_fz_12__10__27__27_.html" title="古龙风云录|中字-国语|Build.14142398-重要更新-狂雷陨落-剑破苍穹+DLC+修改器|解压即玩">古龙风云录|中字-国语|Build.14142398-重要更新-狂雷陨落-剑破苍穹+DLC+修改器|解压即玩</a> </div> </div> </div> </div> <!-- E 推荐下载 --> <div class="panel panel-blockimg"> <a href="/" target="_blank"><img src="/uploads/store/enterprisehost.png" class="img-responsive"/></a> </div> <div class="panel panel-blockimg"> <!-- You may also like --> </div> </aside> </div> </div> </main> <footer> <!-- S 底部版权 --> <div id="footer"> <div class="container"> <div class="row footer-inner"> <div class="col-xs-12"> <div class="pull-left"> <p>网站内容,均来自于用户原创和互联网,若有侵犯到您的权益请联系我们,核实删除。</p> <p>本站为非营利性网站,靠谱客的资源均来自网络收集整理,个人纯属学习交流之用,如有侵犯您的版权请与我联系(wx:kaopuke),我们会马上改正并在下载24小时内删除!</p> <p>Copyright © 2023 All Rights Reserved. <a href="https://beian.miit.gov.cn" rel="nofollow" target="_blank">黔ICP备17011320号-2</a> <a href="https://beian.mps.gov.cn/#/query/webSearch?code=52272602002071" rel="noreferrer" target="_blank">贵公网安备52272602002071</a></p> </div> </div> </div> </div> </div> <script> var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); hm.src = "https://hm.baidu.com/hm.js?e749fb7b04b857116f3a8b682641b74d"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); </script> <!-- E 底部版权 --> </footer> <div id="floatbtn"> <!-- S 浮动按钮 --> <a class="hover" href="/index/user/addarticle.html" target="_blank"> <i class="fa fa-paint-brush fa-lg"></i> <em>立即<br>投稿</em> </a> <div class="floatbtn-item floatbtn-share"> <i class="fa fa-share-alt fa-lg"></i> <div class="floatbtn-wrapper" style="height:50px;top:0"> <div class="social-share" data-initialized="true" data-mode="prepend"> <a href="#" class="social-share-icon icon-weibo" target="_blank"></a> <a href="#" class="social-share-icon icon-qq" target="_blank"></a> <a href="#" class="social-share-icon icon-qzone" target="_blank"></a> <a href="#" class="social-share-icon icon-wechat"></a> </div> </div> </div> <a id="back-to-top" class="hover" href="javascript:;"> <i class="fa fa-reply fa-lg"></i> <em>返回<br>顶部</em> </a> <!-- E 浮动按钮 --> </div> <script type="text/javascript" src="/assets/libs/jquery/dist/jquery.min.js?v=1.0.2"></script> <script type="text/javascript" src="/assets/libs/bootstrap/dist/js/bootstrap.min.js?v=1.0.2"></script> <script type="text/javascript" src="/assets/libs/fastadmin-layer/dist/layer.js?v=1.0.2"></script> <script type="text/javascript" src="/assets/libs/art-template/dist/template-native.js?v=1.0.2"></script> <script type="text/javascript" src="/assets/js/jquery.autocomplete.js?v=1.0.2"></script> <script type="text/javascript" src="/assets/js/swiper.min.js?v=1.0.2"></script> <script type="text/javascript" src="/assets/js/share.min.js?v=1.0.2"></script> <script type="text/javascript" src="/assets/js/cms.js?v=1.0.2"></script> <script type="text/javascript" src="/assets/js/common.js?v=1.0.2"></script> <script type="text/javascript"> (window.slotbydup = window.slotbydup || []).push({ id: "u6850766", container: "_upguagn2t8", async: true }); (window.slotbydup = window.slotbydup || []).push({ id: "u6850838", container: "_12s5gcmjcvx", async: true }); </script> <script type="text/javascript" src="//cpro.baidustatic.com/cpro/ui/cm.js" async="async" defer="defer" ></script> <!-- 复制 --> <script src="/static/tool/clipboard.min.js"></script> <script> //代码高亮溢出显示滚动条 $('.main-content pre').each(function(){ var code = $(this).text(); $(this).wrap('<div class="auto" style="overflow:auto; position:relative;"></div>'); $(this).before('<span class="copyCode">复制代码</span><textarea style="display:none;">'+code+'</textarea>'); $(this).removeAttr("style",""); // $(this).wrap('<pre><code></code></pre>'); }); $('.main-content .codebody').each(function(){ var code = $(this).text(); $(this).wrap('<div class="auto" style="overflow:auto; position:relative;"></div>'); $(this).before('<span class="copyCode">复制代码</span><textarea style="display:none;">'+code+'</textarea>'); // $(this).wrap('<pre><code></code></pre>'); }); function unescapeSpecialChars(str) { return str .replace(/</g, '<') .replace(/>/g, '>') .replace(/&/g, '&') .replace(/ /g, ' ') .replace(/"/g, '"') .replace(/'/g, '\''); } //复制代码 $('.copyCode').on('click',function(){ var txt = $(this).next().html(); txt = unescapeSpecialChars(txt); new ClipboardJS('.copyCode', {text: function() {return txt;}}); layer.msg('复制成功',{time:1000,offset:'100px'}); }); </script> <script> document.addEventListener("DOMContentLoaded", function() { const preElements = document.querySelectorAll("pre"); // 获取所有 <pre> 元素 preElements.forEach(pre => { const codeText = pre.innerHTML.trim(); // 获取代码块的内容 const lines = codeText.split("\n").length; // 计算代码行数 // 创建行号容器 const lineNumbers = document.createElement("div"); lineNumbers.className = 'line-numbers'; // 生成行号内容 let lineNumbersHtml = ''; for (let i = 1; i <= lines; i++) { lineNumbersHtml += i + '<br>'; } // 插入行号容器到 pre 元素中 lineNumbers.innerHTML = lineNumbersHtml; pre.appendChild(lineNumbers); // 保持代码块的格式化 pre.innerHTML = `<div class="line-numbers">${lineNumbersHtml}</div>` + `<div style="padding-left:40px;">${codeText}</div>`; }); }); </script> <style> .copyCode{ position:absolute; right:1px; z-index:999; background:rgba(255,255,255,0.5); border-bottom:1px solid #ddd; padding:2px 8px; font-size:11px !important; border-radius:4px; line-height:24px; cursor:pointer; } .copyCode:hover{ background:#fff; } pre code{ font-family: consolas, Menlo, "PingFang SC", "Microsoft YaHei", monospace; } .hljs { border-radius:4px; padding: 8px !important; } .hljs-ln td { padding: 2px 8px; } .hljs-ln-numbers { text-align: center; color: #abb2bf; background-color: #282c34; border-right: 1px solid #c5c5c5; vertical-align: top; } /* for block of code */ td .hljs-ln-code { padding-left: 5px; } pre { position: relative; padding-left: 5px; /* 为行号留出空间 */ background-color: #f8f9fa; border: 1px solid #e1e1e1; border-radius: 4px; font-size: 14px; line-height: 1.5; overflow-x: auto; } /* 设置行号样式 */ pre .line-numbers { position: absolute; left: 0; top: 0; padding: 10px 10px; background-color: #f1f1f1; border-right: 1px solid #e1e1e1; text-align: right; user-select: none; color: #888; } </style> </body> </html>