您现在的位置是:首页 > cms教程 > 帝国CMS教程帝国CMS教程
帝国cms高亮代码添加行号前端显示Mac OS风格
小张2025-09-18帝国CMS教程已有人查阅
导读在我们使用codesnippet插件实现高亮代码后,但有又发现,不太美观和不便于查看,于是就给高亮代码加上行号,怎么给code snippet添加行号。思路:使用js代码增加给高亮代码增加ul和li的无序列表结构,实现行。
在我们使用codesnippet插件实现高亮代码后,但有又发现,不太美观和不便于查看,于是就给高亮代码加上行号,和更好看的Mac OS风格。
这里我贴出css,自己命名然后在头部引用。
步骤一:添加js代码
把以下代码添加到内容模板文件的head之中js文件中,使用js文件引入;
1. 一定要使用引入的形式,不能直接写在模板里,帝国cms会转义反斜杆,造成代码错乱。
2. 一定要在网站的jquery库下面,否则不起作用
步骤二:在高亮代码样式中写入css代码
这里我贴出css,自己命名然后在头部引用。
code[class*="language-"],
pre[class*="language-"] {
color: #f8f8f2;
background: none;
text-shadow: 0 1px rgba(0, 0, 0, 0.3);
font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;
text-align: left;
white-space: pre;
word-spacing: normal;
word-break: normal;
word-wrap: normal;
line-height: 1.6;
-moz-tab-size: 4;
-o-tab-size: 4;
tab-size: 4;
-webkit-hyphens: none;
-moz-hyphens: none;
-ms-hyphens: none;
hyphens: none;
}
/* Code blocks */
pre[class*="language-"] {
padding: 1em;
margin: .5em 0;
overflow: auto;
border-radius: 0.3em;
}
:not(pre) > code[class*="language-"],
pre[class*="language-"] {
background: #272822;
}
/* Inline code */
:not(pre) > code[class*="language-"] {
padding: .1em;
border-radius: .3em;
white-space: normal;
}
.token.comment,
.token.prolog,
.token.doctype,
.token.cdata {
color: slategray;
}
.token.punctuation {
color: #f8f8f2;
}
.namespace {
opacity: .7;
}
.token.property,
.token.tag,
.token.constant,
.token.symbol,
.token.deleted {
color: #f92672;
}
.token.boolean,
.token.number {
color: #ae81ff;
}
.token.selector,
.token.attr-name,
.token.string,
.token.char,
.token.builtin,
.token.inserted {
color: #a6e22e;
}
.token.operator,
.token.entity,
.token.url,
.language-css .token.string,
.style .token.string,
.token.variable {
color: #f8f8f2;
}
.token.atrule,
.token.attr-value,
.token.function,
.token.class-name {
color: #e6db74;
}
.token.keyword {
color: #66d9ef;
}
.token.regex,
.token.important {
color: #fd971f;
}
.token.important,
.token.bold {
font-weight: bold;
}
.token.italic {
font-style: italic;
}
.token.entity {
cursor: help;
}
pre[class*="language-"].line-numbers {
position: relative;
padding-left: 3.8em;
counter-reset: linenumber;
}
pre[class*="language-"].line-numbers > code {
position: relative;
white-space: inherit;
}
.line-numbers .line-numbers-rows {
position: absolute;
pointer-events: none;
top: 0;
font-size: 100%;
left: -3.8em;
width: 3em; /* works for line-numbers below 1000 lines */
letter-spacing: -1px;
border-right: 1px solid #999;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.line-numbers-rows > span {
pointer-events: none;
display: block;
counter-increment: linenumber;
}
.line-numbers-rows > span:before {
content: counter(linenumber);
color: #999;
display: block;
padding-right: 0.8em;
text-align: right;
}
div.code-toolbar {
position: relative;
}
div.code-toolbar > .toolbar {
position: absolute;
top: .3em;
right: .2em;
transition: opacity 0.3s ease-in-out;
opacity: 0;
width: auto;
background: transparent;
}
div.code-toolbar:hover > .toolbar {
opacity: 1;
}
div.code-toolbar > .toolbar .toolbar-item {
display: inline-block;
margin-right:5px;
}
/*div.code-toolbar > .toolbar a {
cursor: pointer;
}
*/
div.code-toolbar > .toolbar button {
background: none;
border: 0;
color: inherit;
font: inherit;
line-height: normal;
overflow: visible;
padding: 0;
-webkit-user-select: none; /* for button */
-moz-user-select: none;
-ms-user-select: none;
}
div.code-toolbar > .toolbar a,
div.code-toolbar > .toolbar button,
div.code-toolbar > .toolbar span {
color: #F44336;
font-size: .8em;
padding: 0 .5em;
background: #f5f2f0;
background: rgba(224, 224, 224, 0.2);
box-shadow: 0 2px 0 0 rgba(0,0,0,0.2);
border-radius: .5em;
text-decoration:none;
}
div.code-toolbar > .toolbar a:hover,
div.code-toolbar > .toolbar a:focus,
div.code-toolbar > .toolbar button:hover,
div.code-toolbar > .toolbar button:focus,
div.code-toolbar > .toolbar span:hover,
div.code-toolbar > .toolbar span:focus {
color: #FAFAFA;
/*color: inherit;*/
text-decoration: none;
}
/**/
pre[class*="language-"].line-numbers {
padding-top:40px;
/*为了加语言导航条*/
line-height:1.6;
background: #21252b;
box-shadow: 0 10px 30px 0px rgba(0,0,0,.4);
font: 12px "Microsoft YaHei", Arial, Sans-Serif;
margin-bottom: 10px;
max-width: 100%;
overflow: auto;
text-shadow: none;
color: #000;
padding-top: 30px;
box-shadow: 0 10px 30px 0 rgba(0, 0, 0, .4);
}
.pure-highlightjs[class*="language-"]:before {
text-transform: uppercase;
color:#ffffff;
height: 38px;
line-height: 38px;
font-size: 14px;
position: absolute;
top: 0;
left: 0;
font-family: 'Source Sans Pro', sans-serif;
font-weight: 700;
padding: 0 80px;
text-indent: 15px;
float: left;
}
.pure-highlightjs[class*="language-"]:after {
content: " ";
position: absolute;
-webkit-border-radius: 50%;
border-radius: 50%;
background: #fc625d;
width: 12px;
height: 12px;
top: 0;
left: 20px;
margin-top: 13px;
-webkit-box-shadow: 20px 0 #fdbc40, 40px 0 #35cd4b;
box-shadow: 20px 0 #fdbc40, 40px 0 #35cd4b;
}
.try-code-btn {
display: block;
margin: 10px 0;
padding: 8px 15px;
background: #4CAF50;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 14px;
}
.try-code-btn:hover {
background: #45a049;
box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}
如果行号不显示,也可以按下面的步骤进行。步骤一:添加js代码
把以下代码添加到内容模板文件的head之中js文件中,使用js文件引入;
$(function () {
$("code").each(function () {
$(this).html("<ul id=\'codeblock'><li>" + $(this).html().replace(/\n/g, "\n</li><li>") + "\n</li></ul>");
});
});
注意:1. 一定要使用引入的形式,不能直接写在模板里,帝国cms会转义反斜杆,造成代码错乱。
2. 一定要在网站的jquery库下面,否则不起作用
步骤二:在高亮代码样式中写入css代码
.hljs {
display: block;
padding: 0.5em 0 0.5em 0.5em;
background: #fff;
border: solid 1px #DEE1E6;
border-radius: 3px;
white-space: pre-wrap;
word-break: break-all;
}
/*add line number start*/
.hljs ul {
margin-left: 40px;
}
.hljs ul li {
border-left: solid 1px #DEE1E6;
padding: 3px;
list-style: decimal-leading-zero;/*0开头的数字标记。(01, 02, 03, 等。)*/
}
.hljs ul li:nth-child(even) {/*偶数行的背景颜色*/
background-color: #F7F7F7;
}
/*add line number end*/
注意注意事项:高亮样如果是monokai_sublime,大家把我的代码复制过去只用修改颜色就行了。
本文标签:帝国建站
很赞哦! ()
图文教程
帝国cms商城优惠码phome_enewsshop_precode数据表Ctrl+G查询
下面是帝国cms商城优惠码phome_enewsshop_precode数据表字段名和类型说明Ctrl+G查询
帝国灵动标签获取当前栏目下面的子栏目的方法
<?php $bclassid=$GLOBALS[navclassid]; //取得本栏目id 这里加想循环的子栏目信息
解决帝国CMS官方结合项插件自定义字段不支持0和静态页classid为空
帝国官方出的帝国官方结合项插件功能非常的不错,但了难免会出现一些小BUG,这不广大的站长们经过不段的试用,还是发现了一些错误,正是有了这些辛苦的站长,帝国的明天相信才会越来越好
帝国CMS提示登录超时的解决方法
帝国CMS网站管理系统一直以安全系数高,而被广大帝友认可。安全系数太高也会有副作用,比如下面要为大家解决的帝国CMS提示登录超时的问题
相关源码
-
(自适应)刷卡pos机数据移动支付设备电子科技pbootcms模板下载本模板为POS机设备制造商、移动支付终端服务商和科技企业设计,基于PbootCMS系统开发,提供完整的在线展示平台解决方案,满足支付设备行业特有的展示需求。查看源码 -
帝国CMS游戏应用APP推广下载站模板免费下载本模板为移动应用推广、手机游戏推广行业设计,集成H5游戏平台与APP下载功能,支持PC端与移动端自适应访问。专注于为应用开发商、游戏发行商提供专业的线上推广展示平台。查看源码 -
(自适应)WordPress主题SEO自媒体博客资讯模板RabbitV2.0Rabbit v2.0主题专注于网站搜索引擎优化需求,为博客、自媒体及资讯类网站提供专业的SEO技术解决方案。该主题从架构设计到功能实现均围绕搜索引擎优化理念展开。查看源码 -
帝国cms7.5模板生活常识美食女性时尚综合资讯门户源码本模板为帝国cms7.5生活资讯类网站设计,以天奇生活网为参考原型,涵盖生活常识、美食烹饪、女性时尚等多元化内容板块。采用响应式布局设计,适配各种终端设备,为访客提供优质的阅读体验。模板结构清晰合理,内容展示层次分明,符合生活类网站的用户需求。查看源码 -
(自适应)物流运输快递仓储货运网站模板免费下载基于PbootCMS内核开发的物流运输行业专用模板,深度适配仓储货运企业的业务展示需求。前端采用响应式布局,自动适配手机端访问,后台数据实时同步更新,帮助企业高效展示运输网络、仓储设施、服务流程等核心业务模块。查看源码 -
(自适应)宽屏农业机械农耕设备类网站pbootcms模板免费下载为农机企业打造的现代化响应式网站模板,自动适配电脑、平板和手机,浏览体验一致,独立页面SEO设置,提升搜索引擎可见度。查看源码
| 分享笔记 (共有 篇笔记) |

