cnblog博客CSS定制
一、页面定制CSS
- #home {
- margin: 0 auto;
- width: 80%;/*原始65*/
- min-width: 980px;/*页面顶部的宽度*/
- background-color: rgba(245, 245, 245, 0.7);
- padding: 30px;
- margin-top: 50px;
- margin-bottom: 50px;
- box-shadow: 0 2px 6px rgba(100, 100, 100, 0.3);
- }
- body {
- background: rgba(12, 100, 129, 1) url('http://images.cnblogs.com/cnblogs_com/Penn000/1013849/o_123.jpg') fixed no-repeat;
- background-position: 50% 5%;
- background-size: cover;
- }
- #blogTitle {
- height: 100px; /*高度*/
- clear: both;
- background-color: rgba(245, 245, 245, 0);
- }
- #blogTitle h1 {
- font-size: 36px;
- font-weight: bold;
- line-height: 1.8em;/*原始 1.6em*/
- margin-top: 10px;/*原始 15px */
- color: #548B54;
- }
- #blogTitle h2 {
- font-weight: normal;
- font-size: 17px;/*原始 16px ;font-size: 1.0rem;*/
- line-height: 1.8;
- color: #111;
- font-weight: bold;
- text-align: right;
- float: right;
- }
- #navigator{
- background-color: rgba(33, 160, 139, 0.9);
- }
- #navList a:link, #navList a:visited, #navList a:active{
- color: #eee;
- font-size: 18px;
- font-weight: bold;
- }
- .blogStats{
- color: #eee;
- }
- .postTitle {
- border-left: 8px solid rgba(33, 160, 139, 0.68);
- margin-left: 10px;
- margin-bottom: 10px;
- font-size: 20px;
- float: right;
- width: 100%;
- clear: both;
- }
- .postTitle a:link, .postTitle a:visited, .postTitle a:active {
- color: #21759b;
- transition: all 0.4s linear 0s;
- }
- .postTitle a:hover {
- margin-left: 30px;
- color: #0f3647;
- text-decoration: none;
- }
- .postCon {
- float: right;
- line-height: 1.5em;
- width: 100%;
- clear: both;
- padding: 10px 0;
- }
- .day .postTitle a {
- padding-left: 10px;
- }
- .day {
- background: rgba(255, 255, 255, 0.5);
- }
- /*文章附加信息*/
- .postDesc {
- background: url(images/posted_time.png) no-repeat 0 1px;
- color: #757575;
- float: left;
- width: 100%;
- clear: both;
- text-align: left;
- font-family: "微软雅黑" , "宋体" , "黑体" ,Arial;
- font-size: 13px;
- padding-right: 20px;/*5px padding-left: 90px;posted 发表时间左边距离*/
- margin-top: 20px;
- line-height: 1.8;
- padding-bottom: 35px;
- }
- .newsItem, .catListEssay, .catListLink, .catListNoteBook, .catListTag, .catListPostCategory,
- .catListPostArchive, .catListImageCategory, .catListArticleArchive, .catListView,
- .catListFeedback, .mySearch, .catListComment, .catListBlogRank, .catList, .catListArticleCategory ,#blog-calendar
- {
- background: rgba(255, 255, 255, 0.5);
- margin-bottom: 35px;
- word-wrap: break-word;
- }
- .CalTitle{
- background: rgba(255, 255, 255, 0);
- }
- .catListTitle{
- background-color: rgba(33, 160, 139, 0.9);
- }
- #topics{
- background: rgba(255, 255, 255, 0.5);
- }
- .c_ad_block{
- display: none;
- }
- #tbCommentBody{
- width: 100%;
- height: 200px;
- background: rgba(255, 255, 255, 0.5);
- }
- #q{background: rgba(255, 255, 255, 0);}
- .CalNextPrev{background: rgba(255, 255, 255, 0);}
- .cnblogs_code{
- background: rgba(255, 255, 255, 0);
- }
- .cnblogs_code div{
- background: rgba(255, 255, 255, 0);
- }
- .cnblogs_code_toolbar{
- background: rgba(255, 255, 255, 0);
- }
- .entrylist{
- background: rgba(255, 255, 255, 0.5);
- }
- #cnblogs_post_body h2 {
- background: gray !important;
- background: #406CA4 !important;
- border-radius: 4px 4px 4px 4px !important;
- box-shadow: 0 0 0 1px #5F5A4B, 1px 1px 6px 1px rgba(10, 10, 0, 0.5);
- color: #FFFFFF;
- font-family: "微软雅黑", "宋体", "黑体", Arial;
- font-size: 17px;
- font-weight: bold;
- margin: 15px 0 !important;
- padding: 5px 0 5px 20px;
- }
- .postBody a:link, .postBody a:visited, .postBody a:active {
- text-decoration: blink;
- border-bottom: 1px dashed #406ca4;
- }
- .postBody li, .postCon li {
- list-style-type: disc;
- margin-bottom: 0.2em;
- }
- /*生成博客目录的CSS*/
- #uprightsideBar{
- font-size:12px;
- font-family:Arial, Helvetica, sans-serif;
- text-align:left;
- position:fixed;/*将div的位置固定到距离top:50px,right:0px的位置,这样div就会处在最右边的位置,距离顶部50px*/
- top:50px;
- right:0px;
- width: auto;
- height: auto;
- }
- #sideBarTab{
- float:left;
- width:30px;
- border:1px solid #e5e5e5;
- border-right:none;
- text-align:center;
- background:#ffffff;
- }
- #sideBarContents{
- float:left;
- overflow:auto;
- overflow-x:hidden;!important;
- width:240px;
- min-height:108px;
- max-height:660px;
- border:1px solid #e5e5e5;
- border-right:none;
- background:#ffffff;
- }
- #sideBarContents dl{
- margin:;
- padding:;
- }
- #sideBarContents dt{
- margin-top:8px;
- margin-left:5px;
- }
- #sideBarContents dd, dt {
- cursor: pointer;
- }
- #sideBarContents dd:hover, dt:hover {
- color:#A7995A;
- }
- #sideBarContents dd{
- margin-left:20px;
- }
二、自动生成目录代码
需要申请JS权限
页首代码
- <script type="text/javascript">
- /*
- 功能:生成博客目录的JS工具
- 测试:IE8,火狐,google测试通过
- 孤傲苍狼
- 2014-5-11
- */
- var BlogDirectory = {
- /*
- 获取元素位置,距浏览器左边界的距离(left)和距浏览器上边界的距离(top)
- */
- getElementPosition:function (ele) {
- var topPosition = 0;
- var leftPosition = 0;
- while (ele){
- topPosition += ele.offsetTop;
- leftPosition += ele.offsetLeft;
- ele = ele.offsetParent;
- }
- return {top:topPosition, left:leftPosition};
- },
- /*
- 获取滚动条当前位置
- */
- getScrollBarPosition:function () {
- var scrollBarPosition = document.body.scrollTop || document.documentElement.scrollTop;
- return scrollBarPosition;
- },
- /*
- 移动滚动条,finalPos 为目的位置,internal 为移动速度
- */
- moveScrollBar:function(finalpos, interval) {
- //若不支持此方法,则退出
- if(!window.scrollTo) {
- return false;
- }
- //窗体滚动时,禁用鼠标滚轮
- window.onmousewheel = function(){
- return false;
- };
- //清除计时
- if (document.body.movement) {
- clearTimeout(document.body.movement);
- }
- var currentpos =BlogDirectory.getScrollBarPosition();//获取滚动条当前位置
- var dist = 0;
- if (currentpos == finalpos) {//到达预定位置,则解禁鼠标滚轮,并退出
- window.onmousewheel = function(){
- return true;
- }
- return true;
- }
- if (currentpos < finalpos) {//未到达,则计算下一步所要移动的距离
- dist = Math.ceil((finalpos - currentpos)/10);
- currentpos += dist;
- }
- if (currentpos > finalpos) {
- dist = Math.ceil((currentpos - finalpos)/10);
- currentpos -= dist;
- }
- var scrTop = BlogDirectory.getScrollBarPosition();//获取滚动条当前位置
- window.scrollTo(0, currentpos);//移动窗口
- if(BlogDirectory.getScrollBarPosition() == scrTop)//若已到底部,则解禁鼠标滚轮,并退出
- {
- window.onmousewheel = function(){
- return true;
- }
- return true;
- }
- //进行下一步移动
- var repeat = "BlogDirectory.moveScrollBar(" + finalpos + "," + interval + ")";
- document.body.movement = setTimeout(repeat, interval);
- },
- htmlDecode:function (text){
- var temp = document.createElement("div");
- temp.innerHTML = text;
- var output = temp.innerText || temp.textContent;
- temp = null;
- return output;
- },
- /*
- 创建博客目录,
- id表示包含博文正文的 div 容器的 id,
- mt 和 st 分别表示主标题和次级标题的标签名称(如 H2、H3,大写或小写都可以!),
- interval 表示移动的速度
- */
- createBlogDirectory:function (id, mt, st, interval){
- //获取博文正文div容器
- var elem = document.getElementById(id);
- if(!elem) return false;
- //获取div中所有元素结点
- var nodes = elem.getElementsByTagName("*");
- //创建博客目录的div容器
- var divSideBar = document.createElement('DIV');
- divSideBar.className = 'uprightsideBar';
- divSideBar.setAttribute('id', 'uprightsideBar');
- var divSideBarTab = document.createElement('DIV');
- divSideBarTab.setAttribute('id', 'sideBarTab');
- divSideBar.appendChild(divSideBarTab);
- var h2 = document.createElement('H2');
- divSideBarTab.appendChild(h2);
- var txt = document.createTextNode('目录导航');
- h2.appendChild(txt);
- var divSideBarContents = document.createElement('DIV');
- divSideBarContents.style.display = 'none';
- divSideBarContents.setAttribute('id', 'sideBarContents');
- divSideBar.appendChild(divSideBarContents);
- //创建自定义列表
- var dlist = document.createElement("dl");
- divSideBarContents.appendChild(dlist);
- var num = 0;//统计找到的mt和st
- mt = mt.toUpperCase();//转化成大写
- st = st.toUpperCase();//转化成大写
- //遍历所有元素结点
- for(var i=0; i<nodes.length; i++)
- {
- if(nodes[i].nodeName == mt|| nodes[i].nodeName == st)
- {
- //获取标题文本
- var nodetext = nodes[i].innerHTML.replace(/<\/?[^>]+>/g,"");//innerHTML里面的内容可能有HTML标签,所以用正则表达式去除HTML的标签
- nodetext = nodetext.replace(/ /ig, "");//替换掉所有的
- nodetext = BlogDirectory.htmlDecode(nodetext);
- //插入锚
- nodes[i].setAttribute("id", "blogTitle" + num);
- var item;
- switch(nodes[i].nodeName)
- {
- case mt: //若为主标题
- item = document.createElement("dt");
- break;
- case st: //若为子标题
- item = document.createElement("dd");
- break;
- }
- //创建锚链接
- var itemtext = document.createTextNode(nodetext);
- item.appendChild(itemtext);
- item.setAttribute("name", num);
- item.onclick = function(){ //添加鼠标点击触发函数
- var pos = BlogDirectory.getElementPosition(document.getElementById("blogTitle" + this.getAttribute("name")));
- if(!BlogDirectory.moveScrollBar(pos.top, interval)) return false;
- };
- //将自定义表项加入自定义列表中
- dlist.appendChild(item);
- num++;
- }
- }
- if(num == 0) return false;
- /*鼠标进入时的事件处理*/
- divSideBarTab.onmouseenter = function(){
- divSideBarContents.style.display = 'block';
- }
- /*鼠标离开时的事件处理*/
- divSideBar.onmouseleave = function() {
- divSideBarContents.style.display = 'none';
- }
- document.body.appendChild(divSideBar);
- }
- };
- window.onload=function(){
- /*页面加载完成之后生成博客目录*/
- BlogDirectory.createBlogDirectory("cnblogs_post_body","h2","h3",20);
- }
- </script>
页脚代码
- <script language="javascript" type="text/javascript">
- // 生成目录索引列表
- // ref: http://www.cnblogs.com/wangqiguo/p/4355032.html
- // modified by: zzq
- function GenerateContentList()
- {
- var mainContent = $('#cnblogs_post_body');
- var h2_list = $('#cnblogs_post_body h2');//如果你的章节标题不是h2,只需要将这里的h2换掉即可
- if(mainContent.length < 1)
- return;
- if(h2_list.length>0)
- {
- var content = '<a name="_labelTop"></a>';
- content += '<div id="navCategory">';
- content += '<p style="font-size:18px"><b>目录</b></p>';
- content += '<ul>';
- for(var i=0; i<h2_list.length; i++)
- {
- var go_to_top = '<div style="text-align: right"><a href="#_labelTop">回到顶部</a><a name="_label' + i + '"></a></div>';
- $(h2_list[i]).before(go_to_top);
- var h3_list = $(h2_list[i]).nextAll("h3");
- var li3_content = '';
- for(var j=0; j<h3_list.length; j++)
- {
- var tmp = $(h3_list[j]).prevAll('h2').first();
- if(!tmp.is(h2_list[i]))
- break;
- var li3_anchor = '<a name="_label' + i + '_' + j + '"></a>';
- $(h3_list[j]).before(li3_anchor);
- li3_content += '<li><a href="#_label' + i + '_' + j + '">' + $(h3_list[j]).text() + '</a></li>';
- }
- var li2_content = '';
- if(li3_content.length > 0)
- li2_content = '<li><a href="#_label' + i + '">' + $(h2_list[i]).text() + '</a><ul>' + li3_content + '</ul></li>';
- else
- li2_content = '<li><a href="#_label' + i + '">' + $(h2_list[i]).text() + '</a></li>';
- content += li2_content;
- }
- content += '</ul>';
- content += '</div><p> </p>';
- content += '<p style="font-size:18px"><b>正文</b></p>';
- if($('#cnblogs_post_body').length != 0 )
- {
- $($('#cnblogs_post_body')[0]).prepend(content);
- }
- }
- var qqinfo = '<p style="color:navy;font-size:12px">浏览器右上角查看导航按钮>>>></p>';
- $(mainContent[0]).prepend(qqinfo);
- }
- GenerateContentList();
- </script>
cnblog博客CSS定制的更多相关文章
- 美化博客CSS
title: 美化博客CSS date: 2019/01/19 14:28:59 --- 美化博客CSS 可以去这里看下好看的样式 修改下文档的css,博客园是在页面定制CSS代码,我这里修改了下标题 ...
- 迁移cnblog博客
title: 迁移cnblog博客 date: 2018-03-18 categories: cnblogs tags: life 写博客最怕就是这种迁来迁去的,太麻烦了 还好老早就使用markdow ...
- 定制博客CSS样式
首先你需要添加页面CSS代码
- 我的博客css得到别人的认可
你好 在吗?? 本消息来自QQ临时会话,如果您收到骚扰信息,可点击以下网址中的"停用服务"关闭临时会话: http://shang.qq.com/widget/set.php 20 ...
- 博客CSS样式 二
预览 可自行更改颜色 背景图 页面定制 CSS 代码中加入: url为背景图地址,可下载心仪背景图后上传到博客园相册后获取地址 body { color: #000; background: url( ...
- 我的博客CSS
这个是按照custom标准模板来做的,博客园已经有模版了,有些细节不是很好,这个是源CSS,喜欢的可以自由DIY,完善更好. @charset "utf-8"; /* CSS Do ...
- 如何更快更好的写出cnblog博客?windows live writer推荐
之前总是会羡慕网上那些技术牛人的博客都写的那么给力,后来一搜发现还是有工具可用的. 这里就推荐一款写博客的"神器",Windows Live Writer (Get It Now! ...
- cnblog博客停用
本博客从今日起停止更新,后续的文章将会发布在新的博客mrbackkom.github.io
- emacs写cnblog博客
emacs的版本 org-mode版本 参考链接: 用Emacs管理博客园博客 用emacs org-mode写cnblogs博客 用emacs org-mode写博客 & 发布到博客 ...
随机推荐
- android prgoressBar setProgressDrawable 在4.0系统式正常,在2.3系统上不能正常使用的问题
上次在做一个电池电量的进度显示时,需要根据背景主题色来切换电池电量的进度的颜色, 但是在对prgoressBar的setProgressDrawable进行设置之后发现,在4.0系统上能够正常,而在2 ...
- js,indexOf()、lastIndexOf()
indexOf() 方法可返回某个指定的字符串值在字符串中首次出现的位置. 提示和注释 注释:indexOf() 方法对大小写敏感! 注释:如果要检索的字符串值没有出现,则该方法返回 -1. 实例 在 ...
- JavaScript验证时间格式
1. 短时间,形如 (13:04:06) function isTime(str) { var a = str.match(/^(\d{1,2})(:)?(\d{1,2})\2(\d{1,2})$/) ...
- pytest使用笔记(二)——pytest+allure配置使用
使用环境及预置条件 开发工具:pycharm 操作系统:win10 开发语言:python3.6 使用库:pytest4.0,pytest-allure-adaptor 注意不要安装allure-py ...
- 修复bug有哪些更快的技术?做好这6点就够了
你有没有想过为什么有时修复错误似乎比它应该花费更长的时间?当你终于找到问题时,事实证明你所需要的只是一个小小的改变.然而,花了很多时间才能找到正在发生的事情.这种情况比我想象的更频繁. 另一方面,当您 ...
- dubbo 多人开发时(即开发环境),版本号不要一致
导致问题:如果版本号相同,会调到别人的服务 不需要修改配置文件.直接改idea配置即可. Configurations ====> 添加parameters ===> dubbo.cons ...
- SSL详解
SSL 1.整体结构 SSL是一个介于HTTP协议与TCP之间的一个可选层,其位置大致如下 SSL:(Secure Socket Layer,安全套接字层),为Netscape所研发,用以保障在Int ...
- linux常用命令总结(含选项参数)
• 用户切换 su 切换到root用户并不切换环境 su - root 切换到root用户并切换环境 su redhat 切换到redhat不切换环境 • cd切换目 ...
- 32bit 天堂2 windows 2000 server架设教程
服务器的软件要求: Microsoft Windows 2000 Server or advanced Server license 100 Microsoft SQL Server 2000 Ent ...
- 备份win10的驱动程序
目录 折腾历程 怎么备份驱动 备份的驱动如何使用 关于驱动程序的OS兼容性 驱动程序的其他安装方式 1.折腾历程 从闲鱼上收了一个INSIGNIA的二合一笔记本,w7100,因原装win10性能不行自 ...