如何簡單美化自己的部落格(二)——主介面樣式及點選特效
阿新 • • 發佈:2020-12-09
部落格主體樣式更改
- 首先選一個框架模板,在此模板基礎上進行樣式調整。這裡我選擇darkgreentrip
- 在頁面定製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); border-radius: 12px; /*調節邊框圓度*/ } /*boby調節背景圖片*/ body { background:url("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1606476513478&di=92fdb162c0020c2b43d20fa5ffae2159&imgtype=0&src=http%3A%2F%2Fimage.biaobaiju.com%2Fuploads%2F20191015%2F15%2F1571124483-pUBXSkAZba.jpg"); /*背景圖片連結*/ background-position:center left; background-size: cover; background-repeat: no-repeat; background-attachment:fixed; } #blogTitle { height: 100%; /*高度*/ border-radius: 12px; clear: both; background-color: #cccccc69; /*部落格標題的背景*/ } #blogTitle h1 { font-size: 36px; color::#fae4e4; font-weight: bold; line-height: 1.8em;/*原始 1.6em*/ margin-top: 10px;/*原始 15px */ } #blogTitle h2 { font-weight: normal; font-size: 17px; /*原始 16px ;font-size: 1.0rem;*/ line-height: 1.8; color: #462b2e; font-weight: bold; text-align: right; float: right; margin-top: auto; } #navigator{ border-radius: 7px; background-color: rgba(201, 49, 49, 0.6); /*標題欄下的顏色*/ } #navList a:link, #navList a:visited, #navList a:active{ color: #FFFFFF; font-size: 18px; font-weight: bold; } .blogStats{ color: #eee; } .postTitle { border-left: 8px solid rgba(132,112,255, 0); 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: #ac0e0e; transition: all 0.4s linear 0s; } .postTitle a:hover { margin-left: 30px; color: #ac0e0e; 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: gray no-repeat 0 1px; */ color: #852222; float: left; width: 90%; clear: both; text-align: left; font-family: "微軟雅黑" , "宋體" , "黑體" ,Arial; font-size: 13px; /*padding-right: 20px;5px padding-left: 90px;posted 發表時間左邊距離*/ margin-right:20px; /* 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: 25px; word-wrap: break-word; } .CalTitle{ background: rgba(255, 255, 255, 0); } .catListTitle{ margin-top: auto; margin-bottom: auto; background-color: rgba(201, 49, 49, 0.6); /*欄目的條紋顏色*/ border-bottom: none; } #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,#google_q{ background: rgba(255, 255, 255, 0); } .CalNextPrev{ background: rgba(255, 255, 255, 0); } .cnblogs_code{ background: rgba(255, 255, 255, 0); } .dayTitle{ display: none; font-size: 18px; } .cnblogs_code div{ background: rgba(255, 255, 255, 0); } .cnblogs_code_toolbar{ background: rgba(255, 255, 255, 0); } #main{ min-width: 640px; } .entrylist{ background: rgba(255, 255, 255, 0.5); min-height: 60px; } .CalTodayDay{ font-weight: 700; color: rgba(201, 49, 49, 0.8); background: #f533; } a.entrylistItemTitle{ color: #ac0e0e; } .entrylistTitle,.entrylistDescription{ display:none; } .entrylistItem{ margin-bottom: auto; } .entrylistItemPostDesc, .entrylistItem>.entrylistItemPostDesc>a:nth-child(1){ color: #852222; } .entrylistPostSummary{ color: #666; } .comment_textarea{ background: rgba(255, 255, 255, 0.5); border-radius: 7px; } td>a>u{ /*text-decoration:none;*/ color: #852222; } div>ul{ margin-bottom: auto; }
大家可以根據自己的喜好,更改對應的顏色配置、介面寬度、主題背景(可以百度搜索到喜歡的圖片後,點選複製圖片地址,替換程式碼中的地址)等。
PS:給一些小建議,如果有想要更改的樣式,而找不到的話,建議在自己的部落格下開啟F12,出現控制檯後,點選如下圖的按鈕
然後去頁面中點選自己想要更改的內容,如下圖:
點選後,控制檯就會出現相應的HTML及css程式碼,如下圖:
可以先在控制檯對選擇的CSS程式碼中更改,預覽效果,然後再來後臺更改。
滑鼠效果
- 滑鼠圖案效果
在頁面定製CSS如下程式碼片段中,插入下列(最後一行)程式碼:
/*boby調節背景圖片*/ body { background:url("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1606476513478&di=92fdb162c0020c2b43d20fa5ffae2159&imgtype=0&src=http%3A%2F%2Fimage.biaobaiju.com%2Fuploads%2F20191015%2F15%2F1571124483-pUBXSkAZba.jpg"); /*背景圖片連結*/ background-position:center left; background-size: cover; background-repeat: no-repeat; background-attachment:fixed; cursor: url(https://files.cnblogs.com/files/wkfvawl/cursor.ico),auto; /*滑鼠效果*/ }
展示效果如圖:
2. 滑鼠點選效果
- 點選文字
將下面的程式碼複製到首頁HTML程式碼塊:
<script type="text/javascript"> /* 滑鼠點選特效 */ var a_idx = 0; jQuery(document).ready(function($) { $("body").click(function(e) { /* 內容可以更換為自己喜歡的 */ var a = new Array("✌富強✌","❤民主❤","✌文明✌","❤和諧❤","✌自由✌","❤平等❤","✌公正✌","❤法治❤","✌愛國✌","❤敬業❤","✌誠信✌","❤友善❤"); var $i = $("<span></span>").text(a[a_idx]); a_idx = (a_idx + 1) % a.length; var x = e.pageX, y = e.pageY; $i.css({ "z-index": 999, "top": y - 20, "left": x, "position": "absolute", "font-weight": "bold", "color": "rgb("+~~(255*Math.random())+","+~~(255*Math.random())+","+~~(255*Math.random())+")" /* 隨機顏色 */ }); $("body").append($i); $i.animate({ "top": y - 180, "opacity": 0 }, 1500, function() { $i.remove(); }); }); }); </script>
- 煙花效果
將下列程式碼複製到頁尾HTML程式碼中去:
<script src="https://files.cnblogs.com/files/nthforsth/mouse-click.js"></script>
<canvas width="1777" height="841" style="position: fixed; left: 0px; top: 0px; z-index: 2147483647; pointer-events: none;"></canvas>
如果已經有了雪花特效的程式碼,需要放到和雪花特效的script同級,如下:
最終效果圖如下: