一、页面定制CSS

  1 #home {
  2     margin: 0 auto;
  3     width: 80%;/*原始65*/
  4     min-width: 980px;/*页面顶部的宽度*/
  5     background-color: rgba(245, 245, 245, 0.7);
  6     padding: 30px;
  7     margin-top: 50px;
  8     margin-bottom: 50px;
  9     box-shadow: 0 2px 6px rgba(100, 100, 100, 0.3);
 10 }
 11 body {
 12     background: rgba(12, 100, 129, 1) url('http://images.cnblogs.com/cnblogs_com/Penn000/1013849/o_123.jpg') fixed no-repeat;
 13     background-position: 50% 5%;
 14     background-size: cover;
 15 }
 16 #blogTitle {
 17     height: 100px;  /*高度*/
 18     clear: both;
 19     background-color: rgba(245, 245, 245, 0);
 20 }
 21 #blogTitle h1 {
 22     font-size: 36px;
 23     font-weight: bold;
 24     line-height: 1.8em;/*原始 1.6em*/
 25     margin-top: 10px;/*原始 15px */
 26     color: #548B54;
 27 }
 28 #blogTitle h2 {
 29     font-weight: normal;
 30     font-size: 17px;/*原始 16px ;font-size: 1.0rem;*/
 31     line-height: 1.8;
 32     color: #111;
 33     font-weight: bold;
 34     text-align: right;
 35     float: right;
 36 }
 37 #navigator{
 38     background-color: rgba(33, 160, 139, 0.9);
 39 }
 40 #navList a:link, #navList a:visited, #navList a:active{
 41     color: #eee;
 42     font-size: 18px;
 43     font-weight: bold;
 44 }
 45 .blogStats{
 46     color: #eee;
 47 }
 48 .postTitle {
 49     border-left: 8px solid rgba(33, 160, 139, 0.68);
 50     margin-left: 10px;
 51     margin-bottom: 10px;
 52     font-size: 20px;
 53     float: right;
 54     width: 100%;
 55     clear: both;
 56 }
 57 .postTitle a:link, .postTitle a:visited, .postTitle a:active {
 58     color: #21759b;
 59     transition: all 0.4s linear 0s;
 60 }
 61 .postTitle a:hover {
 62     margin-left: 30px;
 63     color: #0f3647;
 64     text-decoration: none;
 65 }
 66 .postCon {
 67     float: right;
 68     line-height: 1.5em;
 69     width: 100%;
 70     clear: both;
 71     padding: 10px 0;
 72 }
 73
 74 .day .postTitle a {
 75     padding-left: 10px;
 76 }
 77 .day {
 78     background: rgba(255, 255, 255, 0.5);
 79 }
 80 /*文章附加信息*/
 81 .postDesc {
 82     background: url(images/posted_time.png) no-repeat 0 1px;
 83     color: #757575;
 84     float: left;
 85     width: 100%;
 86     clear: both;
 87     text-align: left;
 88     font-family: "微软雅黑" , "宋体" , "黑体" ,Arial;
 89     font-size: 13px;
 90     padding-right: 20px;/*5px  padding-left: 90px;posted 发表时间左边距离*/
 91     margin-top: 20px;
 92     line-height: 1.8;
 93     padding-bottom: 35px;
 94 }
 95
 96 .newsItem, .catListEssay, .catListLink, .catListNoteBook, .catListTag, .catListPostCategory,
 97 .catListPostArchive, .catListImageCategory, .catListArticleArchive, .catListView,
 98 .catListFeedback, .mySearch, .catListComment, .catListBlogRank, .catList, .catListArticleCategory ,#blog-calendar
 99 {
100     background: rgba(255, 255, 255, 0.5);
101     margin-bottom: 35px;
102     word-wrap: break-word;
103 }
104
105 .CalTitle{
106     background: rgba(255, 255, 255, 0);
107 }
108 .catListTitle{
109     background-color: rgba(33, 160, 139, 0.9);
110 }
111
112 #topics{
113     background: rgba(255, 255, 255, 0.5);
114 }
115
116 .c_ad_block{
117     display: none;
118 }
119
120 #tbCommentBody{
121     width: 100%;
122     height: 200px;
123     background: rgba(255, 255, 255, 0.5);
124 }
125
126 #q{background: rgba(255, 255, 255, 0);}
127
128 .CalNextPrev{background: rgba(255, 255, 255, 0);}
129
130 .cnblogs_code{
131     background: rgba(255, 255, 255, 0);
132 }
133
134 .cnblogs_code div{
135     background: rgba(255, 255, 255, 0);
136 }
137
138 .cnblogs_code_toolbar{
139     background: rgba(255, 255, 255, 0);
140 }
141
142 .entrylist{
143     background: rgba(255, 255, 255, 0.5);
144 }
145
146 #cnblogs_post_body h2 {
147 background: gray !important;
148 background: #406CA4 !important;
149 border-radius: 4px 4px 4px 4px !important;
150 box-shadow: 0 0 0 1px #5F5A4B, 1px 1px 6px 1px rgba(10, 10, 0, 0.5);
151 color: #FFFFFF;
152 font-family: "微软雅黑", "宋体", "黑体", Arial;
153 font-size: 17px;
154 font-weight: bold;
155 margin: 15px 0 !important;
156 padding: 5px 0 5px 20px;
157 }
158
159 .postBody a:link, .postBody a:visited, .postBody a:active {
160     text-decoration: blink;
161     border-bottom: 1px dashed #406ca4;
162 }
163 .postBody li, .postCon li {
164     list-style-type: disc;
165     margin-bottom: 0.2em;
166 }
167
168 /*生成博客目录的CSS*/
169 #uprightsideBar{
170     font-size:12px;
171     font-family:Arial, Helvetica, sans-serif;
172     text-align:left;
173     position:fixed;/*将div的位置固定到距离top:50px,right:0px的位置,这样div就会处在最右边的位置,距离顶部50px*/
174     top:50px;
175     right:0px;
176     width: auto;
177     height: auto;
178 }
179 #sideBarTab{
180     float:left;
181     width:30px;
182     border:1px solid #e5e5e5;
183     border-right:none;
184     text-align:center;
185     background:#ffffff;
186 }
187
188 #sideBarContents{
189     float:left;
190     overflow:auto;
191     overflow-x:hidden;!important;
192     width:240px;
193     min-height:108px;
194     max-height:660px;
195     border:1px solid #e5e5e5;
196     border-right:none;
197     background:#ffffff;
198 }
199 #sideBarContents dl{
200     margin:0;
201     padding:0;
202 }
203
204 #sideBarContents dt{
205     margin-top:8px;
206     margin-left:5px;
207 }
208
209 #sideBarContents dd, dt {
210     cursor: pointer;
211 }
212
213 #sideBarContents dd:hover, dt:hover {
214     color:#A7995A;
215 }
216 #sideBarContents dd{
217     margin-left:20px;
218 }

View Code

二、自动生成目录代码

需要申请JS权限

页首代码

  1 <script type="text/javascript">
  2 /*
  3     功能:生成博客目录的JS工具
  4     测试:IE8,火狐,google测试通过
  5     孤傲苍狼
  6     2014-5-11
  7 */
  8 var BlogDirectory = {
  9     /*
 10         获取元素位置,距浏览器左边界的距离(left)和距浏览器上边界的距离(top)
 11     */
 12     getElementPosition:function (ele) {
 13         var topPosition = 0;
 14         var leftPosition = 0;
 15         while (ele){
 16             topPosition += ele.offsetTop;
 17             leftPosition += ele.offsetLeft;
 18             ele = ele.offsetParent;
 19         }
 20         return {top:topPosition, left:leftPosition};
 21     },
 22
 23     /*
 24     获取滚动条当前位置
 25     */
 26     getScrollBarPosition:function () {
 27         var scrollBarPosition = document.body.scrollTop || document.documentElement.scrollTop;
 28         return  scrollBarPosition;
 29     },
 30
 31     /*
 32     移动滚动条,finalPos 为目的位置,internal 为移动速度
 33     */
 34     moveScrollBar:function(finalpos, interval) {
 35
 36         //若不支持此方法,则退出
 37         if(!window.scrollTo) {
 38             return false;
 39         }
 40
 41         //窗体滚动时,禁用鼠标滚轮
 42         window.onmousewheel = function(){
 43             return false;
 44         };
 45
 46         //清除计时
 47         if (document.body.movement) {
 48             clearTimeout(document.body.movement);
 49         }
 50
 51         var currentpos =BlogDirectory.getScrollBarPosition();//获取滚动条当前位置
 52
 53         var dist = 0;
 54         if (currentpos == finalpos) {//到达预定位置,则解禁鼠标滚轮,并退出
 55             window.onmousewheel = function(){
 56                 return true;
 57             }
 58             return true;
 59         }
 60         if (currentpos < finalpos) {//未到达,则计算下一步所要移动的距离
 61             dist = Math.ceil((finalpos - currentpos)/10);
 62             currentpos += dist;
 63         }
 64         if (currentpos > finalpos) {
 65             dist = Math.ceil((currentpos - finalpos)/10);
 66             currentpos -= dist;
 67         }
 68
 69         var scrTop = BlogDirectory.getScrollBarPosition();//获取滚动条当前位置
 70         window.scrollTo(0, currentpos);//移动窗口
 71         if(BlogDirectory.getScrollBarPosition() == scrTop)//若已到底部,则解禁鼠标滚轮,并退出
 72         {
 73             window.onmousewheel = function(){
 74                 return true;
 75             }
 76             return true;
 77         }
 78
 79         //进行下一步移动
 80         var repeat = "BlogDirectory.moveScrollBar(" + finalpos + "," + interval + ")";
 81         document.body.movement = setTimeout(repeat, interval);
 82     },
 83
 84     htmlDecode:function (text){
 85         var temp = document.createElement("div");
 86         temp.innerHTML = text;
 87         var output = temp.innerText || temp.textContent;
 88         temp = null;
 89         return output;
 90     },
 91
 92     /*
 93     创建博客目录,
 94     id表示包含博文正文的 div 容器的 id,
 95     mt 和 st 分别表示主标题和次级标题的标签名称(如 H2、H3,大写或小写都可以!),
 96     interval 表示移动的速度
 97     */
 98     createBlogDirectory:function (id, mt, st, interval){
 99          //获取博文正文div容器
100         var elem = document.getElementById(id);
101         if(!elem) return false;
102         //获取div中所有元素结点
103         var nodes = elem.getElementsByTagName("*");
104         //创建博客目录的div容器
105         var divSideBar = document.createElement('DIV');
106         divSideBar.className = 'uprightsideBar';
107         divSideBar.setAttribute('id', 'uprightsideBar');
108         var divSideBarTab = document.createElement('DIV');
109         divSideBarTab.setAttribute('id', 'sideBarTab');
110         divSideBar.appendChild(divSideBarTab);
111         var h2 = document.createElement('H2');
112         divSideBarTab.appendChild(h2);
113         var txt = document.createTextNode('目录导航');
114         h2.appendChild(txt);
115         var divSideBarContents = document.createElement('DIV');
116         divSideBarContents.style.display = 'none';
117         divSideBarContents.setAttribute('id', 'sideBarContents');
118         divSideBar.appendChild(divSideBarContents);
119         //创建自定义列表
120         var dlist = document.createElement("dl");
121         divSideBarContents.appendChild(dlist);
122         var num = 0;//统计找到的mt和st
123         mt = mt.toUpperCase();//转化成大写
124         st = st.toUpperCase();//转化成大写
125         //遍历所有元素结点
126         for(var i=0; i<nodes.length; i++)
127         {
128             if(nodes[i].nodeName == mt|| nodes[i].nodeName == st)
129             {
130                 //获取标题文本
131                 var nodetext = nodes[i].innerHTML.replace(/<\/?[^>]+>/g,"");//innerHTML里面的内容可能有HTML标签,所以用正则表达式去除HTML的标签
132                 nodetext = nodetext.replace(/ /ig, "");//替换掉所有的
133                 nodetext = BlogDirectory.htmlDecode(nodetext);
134                 //插入锚
135                 nodes[i].setAttribute("id", "blogTitle" + num);
136                 var item;
137                 switch(nodes[i].nodeName)
138                 {
139                     case mt:    //若为主标题
140                         item = document.createElement("dt");
141                         break;
142                     case st:    //若为子标题
143                         item = document.createElement("dd");
144                         break;
145                 }
146
147                 //创建锚链接
148                 var itemtext = document.createTextNode(nodetext);
149                 item.appendChild(itemtext);
150                 item.setAttribute("name", num);
151                 item.onclick = function(){        //添加鼠标点击触发函数
152                     var pos = BlogDirectory.getElementPosition(document.getElementById("blogTitle" + this.getAttribute("name")));
153                     if(!BlogDirectory.moveScrollBar(pos.top, interval)) return false;
154                 };
155
156                 //将自定义表项加入自定义列表中
157                 dlist.appendChild(item);
158                 num++;
159             }
160         }
161
162         if(num == 0) return false;
163         /*鼠标进入时的事件处理*/
164         divSideBarTab.onmouseenter = function(){
165             divSideBarContents.style.display = 'block';
166         }
167         /*鼠标离开时的事件处理*/
168         divSideBar.onmouseleave = function() {
169             divSideBarContents.style.display = 'none';
170         }
171
172         document.body.appendChild(divSideBar);
173     }
174
175 };
176
177 window.οnlοad=function(){
178     /*页面加载完成之后生成博客目录*/
179     BlogDirectory.createBlogDirectory("cnblogs_post_body","h2","h3",20);
180 }
181 </script>

View Code

页脚代码

 1 <script language="javascript" type="text/javascript">
 2
 3 // 生成目录索引列表
 4 // ref: http://www.cnblogs.com/wangqiguo/p/4355032.html
 5 // modified by: zzq
 6 function GenerateContentList()
 7 {
 8     var mainContent = $('#cnblogs_post_body');
 9     var h2_list = $('#cnblogs_post_body h2');//如果你的章节标题不是h2,只需要将这里的h2换掉即可
10
11     if(mainContent.length < 1)
12         return;
13
14     if(h2_list.length>0)
15     {
16         var content = '<a name="_labelTop"></a>';
17         content += '<div id="navCategory">';
18         content += '<p style="font-size:18px"><b>目录</b></p>';
19         content += '<ul>';
20         for(var i=0; i<h2_list.length; i++)
21         {
22             var go_to_top = '<div style="text-align: right"><a href="#_labelTop">回到顶部</a><a name="_label' + i + '"></a></div>';
23             $(h2_list[i]).before(go_to_top);
24
25             var h3_list = $(h2_list[i]).nextAll("h3");
26             var li3_content = '';
27             for(var j=0; j<h3_list.length; j++)
28             {
29                 var tmp = $(h3_list[j]).prevAll('h2').first();
30                 if(!tmp.is(h2_list[i]))
31                     break;
32                 var li3_anchor = '<a name="_label' + i + '_' + j + '"></a>';
33                 $(h3_list[j]).before(li3_anchor);
34                 li3_content += '<li><a href="#_label' + i + '_' + j + '">' + $(h3_list[j]).text() + '</a></li>';
35             }
36
37             var li2_content = '';
38             if(li3_content.length > 0)
39                 li2_content = '<li><a href="#_label' + i + '">' + $(h2_list[i]).text() + '</a><ul>' + li3_content + '</ul></li>';
40             else
41                 li2_content = '<li><a href="#_label' + i + '">' + $(h2_list[i]).text() + '</a></li>';
42             content += li2_content;
43         }
44         content += '</ul>';
45         content += '</div><p>&nbsp;</p>';
46         content += '<p style="font-size:18px"><b>正文</b></p>';
47         if($('#cnblogs_post_body').length != 0 )
48         {
49             $($('#cnblogs_post_body')[0]).prepend(content);
50         }
51     }
52
53     var qqinfo =  '<p style="color:navy;font-size:12px">浏览器右上角查看导航按钮>>>></p>';
54     $(mainContent[0]).prepend(qqinfo);
55 }
56
57 GenerateContentList();
58 </script>

View Code

转载于:https://www.cnblogs.com/bopo/p/9219285.html

cnblog博客CSS定制相关推荐

  1. 博客园定制CSS代码

    博客园定制CSS代码步骤 禁用模板默认 CSS . CSS 代码框中,填写定制 CSS 代码. 定制的 CSS 代码中,如果缺少 home 项,需要进行添加,home 项范例如下: 其中 width ...

  2. 博客园定制页面(一)——博客园设置相关参考

    一.博客设置相关 1.1.博客园主页设置 参考其他大佬的博客设置: 博客园博客美化相关文章目录(非本人整理) 博客园主页CSS元素名汇总(非本人整理) 1.2.Windows Live Writer客 ...

  3. 1024程序员节,博客专家“定制勋章”名单出炉

    1024征文还在进行中,投稿链接:https://marketing.csdn.net/p/525a311bc5086ebdd33071b3338702b9​​​​​​​ 10月24日当天,博客专家发 ...

  4. cnblog博客停用

    本博客从今日起停止更新,后续的文章将会发布在新的博客mrbackkom.github.io 转载于:https://www.cnblogs.com/MrBackKom/p/3531730.html

  5. Hexo博客icarus主题定制篇

    本文基于Hexo和Icarus4.1.1版本,对博客主题定制过程做一个记录.在icarus4.0版本中,主题npm方式安装的话,本地将不会有主题相关的文件,需要定制的话,可以通过修改node_modu ...

  6. 自定义css样式美化博客园

    写在前面 csdn的markdown放到博客园里感觉风格迥异,所以还是找个好点的css吧,css这个我没有深入了解,拼凑了一个css.对于有python代码,而且需要自动生成目录的博文很有帮助,其他的 ...

  7. vue论坛网站的文章自动排版_基于 VuePress 定制个人博客网站

    VuePress 简单来说,VuePress 是 Vue 驱动的静态网站生成器.VuePress 简单易上手,同时也有足够强大的定制能力,尤其对熟悉 Vue 的前端开发人员而言.相比于知名的博客生成器 ...

  8. 写好CSS代码的70个专业建议-前端开发博客

    写好CSS代码的70个专业建议-前端开发博客 CSS 并不总是容易处理. 在你的能力和经验不够的时候,CSS编程会成为一个噩梦,特别是你不确定为页面元素中选择哪种选择器的时候.使用一个不常见的CSS属 ...

  9. 一文搞定scrapy爬取众多知名技术博客文章保存到本地数据库,包含:cnblog、csdn、51cto、itpub、jobbole、oschina等

    本文旨在通过爬取一系列博客网站技术文章的实践,介绍一下scrapy这个python语言中强大的整站爬虫框架的使用.各位童鞋可不要用来干坏事哦,这些技术博客平台也是为了让我们大家更方便的交流.学习.提高 ...

最新文章

  1. BTC震荡调整后的新一轮爆发将要开启,BCH姿态逐渐明显
  2. 使用Git 管理heroku的项目(windows)
  3. 【测试】小龟小车A2裸板下载arduino程序
  4. java-类的结构及使用
  5. [转载] 说说JSON和JSONP,也许你会豁然开朗
  6. c语言中结束本次循环的语句是什么
  7. 移植memtester到android平台
  8. [置顶] Oracle学习经验谈
  9. Pannellum:实例之通过全景图游览
  10. 字节跳动斥巨资开发出《Python知识手册》
  11. 电力载波通信了解笔记
  12. coreldraw橙子怎么画_CDR X6(CorelDRAW X6)怎么画一杯满满的橙汁?
  13. matlab在故障诊断中的应用,Matlab在发动机故障诊断中的应用研究
  14. dplayer + m3u8+ p2p加速
  15. 驭势领读 | 《让大象飞》:资本寒冬正好能让市场回归理性
  16. 短视频无尽流前端开发指南
  17. [Golang] json.Marshal问题总结
  18. surfacepro4黑苹果触屏_surface pro4 黑苹果(macos)体验
  19. 听见丨特斯拉电动卡车售价公布:100万元起 朱啸虎:ofo和摩拜会合并 但还要再经历一战
  20. Dictionary和IDictionary

热门文章

  1. python开发需要掌握哪些知识-Python后端开发如何入门,要学习那些系统性的知识?...
  2. python从入门到精通pdf下载清华大学出版社-python从入门到精通 清华大学出版社...
  3. 如何用python画数据图-用Python绘制地理图
  4. python编程基础语法-Python编程入门基础语法详解
  5. python 命令行参数-Python3之命令行参数处理
  6. python读取excel画散点图-python学习之matplotlib绘制散点图实例
  7. python与excel的应用-python基础之类与对象的应用-操作excel
  8. python序列类型-什么是序列,Python序列详解(包括序列类型和常用操作)
  9. python编程能干什么-Python编程一般可以用来做什么
  10. python的特点和优点-【Python面试】 Python 的特点和优点是什么?