1.布局之前的準(zhǔn)備工作
創(chuàng)新互聯(lián)公司是一家專注于網(wǎng)站設(shè)計(jì)、網(wǎng)站建設(shè)與策劃設(shè)計(jì),納溪網(wǎng)站建設(shè)哪家好?創(chuàng)新互聯(lián)公司做網(wǎng)站,專注于網(wǎng)站建設(shè)10多年,網(wǎng)設(shè)計(jì)領(lǐng)域的專業(yè)建站公司;建站業(yè)務(wù)涵蓋:納溪等地區(qū)。納溪做網(wǎng)站價(jià)格咨詢:18982081108
上一章我們已經(jīng)搭建好了環(huán)境,本站就開始我們的OMinds的開發(fā)吧。
在開始之前,先讓我們來裝點(diǎn)東西,打開cmd,切換到project目錄,輸入命令:
npm install -g supervisor
效果如下圖(由于正在等待安裝只截了一部分):
注意:每次我們更新代碼后,都需要手動(dòng)停止并重啟應(yīng)用,使用 supervisor 模塊可以解決這個(gè)問題,每當(dāng)我們保存修改的文件時(shí),supervisor 都會(huì)自動(dòng)幫我們重啟應(yīng)用。所以這里安裝supervisor ,以便于我們能方便看到自己的布局效果。
在任何你覺得合適的地方,建立一個(gè)文本文檔,寫入內(nèi)容如下:
@echo off cd E:\nworks\OMinds supervisor app.js
其中cd E:\nworks\OMinds 是你的項(xiàng)目目錄,保存之后,重命名為server.bat,以后啟動(dòng)server只需點(diǎn)擊server.bat即可。
注意:假如你的project在e盤,而bat在桌面上,那么需要在以上代碼@echo off后面添加一行代碼:
e:
表示切換到e盤。
OK,準(zhǔn)備工作已經(jīng)做好,讓我們跑一下server看看吧:
2.開始布局(本站只使用chrome瀏覽器做效果,如果你自己的網(wǎng)站布局已做好,可以跳過這一章)
首先實(shí)現(xiàn)導(dǎo)航欄,在public文件夾下建立p_w_picpaths、js兩個(gè)目錄,加上已經(jīng)存在的stylesheets目錄,共3各目錄,打開style.css,清空里面的內(nèi)容,加入以下css:
body{
margin: 0 auto;
padding: 0;
background: url(../p_w_picpaths/bgnoise_lg.png) repeat left top;
font: bold 12px/18px "Helvetica Neue", Helvetica, Arial, sans-serif;
}
ul {
list-style: none;
}
#navigation {
margin: 20px auto;
text-transform: uppercase;
color: #444;
}
#navigation:after {
clear: both;
content: ".";
display: block;
height: 0;
visibility: hidden;
}
#navigation ul {
margin: 0 auto;
padding:0;
}
#navigation li {
float: left;
border-style: solid;
border-width: 1px;
border-color: #BABABA #BABABA #BABABA #FFF;
box-shadow: 0 1px rgba(255,255,255,1) inset;
-webkit-box-shadow: 0 1px rgba(255,255,255,1) inset;
background: #F7F7F7; /* Old browsers */
background: -moz-linear-gradient(top, #F7F7F7 0%, #EDEDED 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#F7F7F7), color-stop(100%,#EDEDED)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #F7F7F7 0%,#EDEDED 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #F7F7F7 0%,#EDEDED 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #F7F7F7 0%,#EDEDED 100%); /* IE10+ */
background: linear-gradient(top, #F7F7F7 0%,#EDEDED 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#F7F7F7', endColorstr='#EDEDED',GradientType=0 ); /* IE6-9 */
}
#navigation li:hover, #navigation li.current {
box-shadow: 0 1px rgba(255,255,255,0.2) inset;
-webkit-box-shadow: 0 1px rgba(255,255,255,0.2) inset;
border-color: #262626 !important;
background: #4D4D4D; /* Old browsers */
background: -moz-linear-gradient(top, #4D4D4D 0%, #262626 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#4D4D4D), color-stop(100%,#262626)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #4D4D4D 0%,#262626 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #4D4D4D 0%,#262626 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #4D4D4D 0%,#262626 100%); /* IE10+ */
background: linear-gradient(top, #4D4D4D 0%,#262626 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#4D4D4D', endColorstr='#262626',GradientType=0 ); /* IE6-9 */
}
#navigation a {
display: block;
padding: 10px 15px;
color: #444;
text-decoration: none;
text-shadow: 0 1px #FFF;
}
#navigation a:hover, #navigation li.current a {
color: #FFF;
text-shadow: 0 1px #000;
}
#navigation li:first-child {
border-left-color: #BABABA;
border-radius: 100px 0 0 100px;
}
#navigation li:last-child {
border-radius: 0 100px 100px 0;
}在p_w_picpaths文件夾里把我們的背景圖片添加進(jìn)去:
打開views下的inde.ejs文件,在此之前,先讓我們調(diào)整一下項(xiàng)目的編碼,在eclipse下,右鍵->properties->resource,text file encoding 選擇utf-8,由于目前不支持gbk,index.ejs內(nèi)容如下(<meta charset="utf-8">是設(shè)置編碼格式的):
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title><%= title %></title>
<!-- begin CSS -->
<link href="/stylesheets/style.css" type="text/css" rel="stylesheet">
<!-- end CSS -->
</head>
<body>
<div id="container" >
<nav id="navigation">
<ul >
<li><a href="#" title="8小時(shí)內(nèi)最新">最新</a></li>
<li><a href="#" title="24小時(shí)內(nèi)評(píng)論最多">精華</a></li>
<li><a href="#" title="無需登錄快速投稿">投稿</a></li>
<li><a href="#">關(guān)于</a></li>
<li><a href="#">博客</a></li>
<li><a href="#">搜索</a></li>
</ul>
<ul >
<li><a href="#">登陸</a></li>
<li><a href="#">注冊(cè)</a></li>
</ul>
</nav>
</div>
</body>
</html>打開瀏覽求看一下導(dǎo)航的效果:
可以看到搜索與登錄之間有一塊留白,這個(gè)可以根據(jù)自己需要進(jìn)行調(diào)整,我的想法是當(dāng)點(diǎn)擊搜索時(shí)向右拉出搜索框,不過暫時(shí)不著急。
其次,實(shí)現(xiàn)內(nèi)容布局,再次打開style.css,添加以下css代碼:
.content {
max-width: 690px;
margin: 20px auto;
}
.cell {
margin: 0 auto;
background-color: #fff;
clear: both;
padding: 18px 20px;
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
margin-bottom: 20px;
border-radius: 4px;
}
.cell_loc{
float:right;
padding:2px 6px;
background:url(../p_w_picpaths/bgnoise_lg.png);
border-radius: 9px;
border-color: #BABABA #BABABA #BABABA #FFF;
box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.2) inset,
0 0 0 1px rgba(0, 0, 0, 0.2) inset;
font-size:6px;
}
.cell_author {
font-size: 14px;
vertical-align: middle;
line-height: 100%;
margin: 0 0 17px;
}
.cell_author img {
border-radius: 20px;
box-shadow: 0 0 6px hsla(0, 27%, 42%, .5);
width: 40px;
height: 40px;
max-width: 100%;
vertical-align: middle;
margin: 0 10px 0 0;
border: 0;
}
.cell_author img:hover{
box-shadow: 0 0 8px hsla(350, 89%, 48%, 0.69);
}
.cell_author a {
color: #9b8878;
}
.cell_author a:hover {
color: #300;
}
.cell_text {
word-break: break-all;
line-height: 160%;
}
.cell_bar {
margin: 15px 0 0 0;
height: 30px;
font-size: 12px;
}
.cell_bar ul li {
float: left;
}
.cell_bar ul li a {
display: block;
height: 28px;
line-height: 30px;
margin-right: 10px;
text-indent: 20px;
color: #BEBEBE;
width: 80px;
font-weight: 500;
}
.cell_bar ul li a:hover {
color: #9e8c7b;
}
.cell_bar_comm {
float: right;
margin: 0;
padding: 0;
}
.cell_bar_comm li {
float: left;
}
.cell_share {
float: right;
}
.share_icon {
display: inline-block;
width: 24px;
height: 24px;
overflow: hidden;
background: url(../p_w_picpaths/share_logo.png) no-repeat;
}
.share_sn {
float: right;
margin-right: 5px;
background-position: -50px 0px;
}
.share_tc {
float: right;
margin-right: 15px;
background-position: -100px 0px;
}
.share_rr {
float: right;
margin-right: 5px;
background-position: -150px 0px;
}打開index.ejs,在</nav>之后添加代碼:
<div class="content">
<div class="cell">
<div class="cell_author" >
<img src="/p_w_picpaths/tem.jpg" title="OMinds">
<a href="/>">OMinds</a>
<span class="cell_loc" title="1樓">1#</span>
</div>
<div class="cell_text" title='' >
OMinds,發(fā)表你的心事,你可以不用登錄,不用在乎是否會(huì)被別人嘲笑,因?yàn)樵谶@里大家都是一樣的沒有誰會(huì)嘲笑你。
</div>
<div class="cell_bar">
<ul >
<li><a id="putgoods" name="putgoods" href="#" title="10個(gè)贊" >贊[10]</a></li>
<li><a id="putbads" name="putbads" href="j#" title="10個(gè)踩">踩[10]</a></li>
</ul>
<ul class="cell_bar_comm">
<li><a href="#" title="10條評(píng)論" >評(píng)[10]</a></li>
<div class="bshare-custom" ><a title="分享到QQ空間" class="bshare-qzone"></a>
<a title="分享到新浪微博" class="bshare-sinaminiblog"></a>
<a title="分享到人人網(wǎng)" class="bshare-renren"></a>
<a title="分享到騰訊微博" class="bshare-qqmb"></a>
<a title="分享到網(wǎng)易微博" class="bshare-neteasemb"></a>
<script type="text/javascript" charset="utf-8" src="http://static.bshare.cn/b/buttonLite.js#style=-1&uuid=;pophcol=2&lang=zh"></script>
<script type="text/javascript" charset="utf-8" src="http://static.bshare.cn/b/bshareC0.js"></script>
<script type="text/javascript" charset="utf-8">
bShare.addEntry({
title:"OMinds分享",
summary:'分享你的心事。' ,
vTag:'OMinds'});
</script>
</ul>
</div>
</div>
</div>
</div>其中p_w_picpaths/tem.jpg為:
好,刷新瀏覽器看看效果如何:
好基本上小站原型已成,下面做一下修剪,在views目錄下新建header.ejs、footer.ejs文件,將index.ejs中</nav>以上的代碼全部拷貝到header.ejs中,并在index.ejs的最頂端添加代碼:
<%- include header%>
將index.ejs中最后一個(gè)</div>及以后的代碼提取到footer.ejs中,并在indes.ejs中添加代碼:
<%- include footer%>
那么,最后index.ejs中應(yīng)該為:
<%- include header%>
<div class="content">
<div class="cell">
<div class="cell_author" >
<img src="/p_w_picpaths/tem.jpg" title="OMinds">
<a href="/>">OMinds</a>
<span class="cell_loc" title="1樓">1#</span>
</div>
<div class="cell_text" title='' >
OMinds,發(fā)表你的心事,你可以不用登錄,不用在乎是否會(huì)被別人嘲笑,因?yàn)樵谶@里大家都是一樣的沒有誰會(huì)嘲笑你。
</div>
<div class="cell_bar">
<ul >
<li><a id="putgoods" name="putgoods" href="#" title="10個(gè)贊" >贊[10]</a></li>
<li><a id="putbads" name="putbads" href="j#" title="10個(gè)踩">踩[10]</a></li>
</ul>
<ul class="cell_bar_comm">
<li><a href="#" title="10條評(píng)論" >評(píng)[10]</a></li>
<div class="bshare-custom" ><a title="分享到QQ空間" class="bshare-qzone"></a>
<a title="分享到新浪微博" class="bshare-sinaminiblog"></a>
<a title="分享到人人網(wǎng)" class="bshare-renren"></a>
<a title="分享到騰訊微博" class="bshare-qqmb"></a>
<a title="分享到網(wǎng)易微博" class="bshare-neteasemb"></a>
<script type="text/javascript" charset="utf-8" src="http://static.bshare.cn/b/buttonLite.js#style=-1&uuid=;pophcol=2&lang=zh"></script>
<script type="text/javascript" charset="utf-8" src="http://static.bshare.cn/b/bshareC0.js"></script>
<script type="text/javascript" charset="utf-8">
bShare.addEntry({
title:"OMinds分享",
summary:'分享你的心事。' ,
vTag:'OMinds'});
</script>
</ul>
</div>
</div>
</div>
</div>
<%- include footer%>以上的首頁是沒什么問題了,有了顯示,就需要有數(shù)據(jù)來源,來源就是通過投稿頁,那么下面來布局投稿頁面,先在header.ejs中把代碼:
<li ><a href="#" title="無需登錄快速投稿">投稿</a></li>
修改為:
<li ><a href="/upminds" title="無需登錄快速投稿">投稿</a></li>
表示我們通過upminds地址訪問投稿頁面,直接拷貝復(fù)制index.ejs文件命名為:upminds.ejs,將header和footer以外的代碼刪除。再次打開style.css添加css:
.upideas_content {
position: relative;
width: 690px;
margin: 0 auto;
padding: 0 10px 0 10px;
}
.clear_fix {
display: block;
}
.clear_fix:after {
content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden;
}
.up_content {
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
background: #fff;
padding: 20px;
margin-bottom: 20px;
margin-top: 20px;
display: block;
border-radius: 4px;
}
.up_bar {
color: #666;
width: 200px;
float: right;
}
.up_bar h4 {
font-size: 16px;
padding: 0 0 20px 0;
margin: 0;
}
.up_bar ol li {
padding: 15px 0;
border-top: 1px solid #efefef;
list-style-position: inside;
list-style-type: decimal;
line-height: 140%;
}
.up_content_text {
width: 422px;
float: left;
}
.up_idea_text {
box-shadow: inset 1px 1px 1px rgba(0, 0, 0, 0.1);
border: 1px solid #ccc;
background: #f9f9f9;
font-size: 14px;
line-height: 18px;
padding: 10px;
resize: none;
width: 400px;
}
.up_idea_err{
float: left;
color:#FF0000;
padding: 10px 0 0 0;
}
.up_idea_btn {
border-radius: 2px;
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
background: #FF8000;
color: #fff;
font-size: 14px;
line-height: 18px;
padding: 10px 20px 10px 20px;
border: 0 none;
float: right;
}upminds.ejs中的代碼:
<%- include header%>
<div class="main">
<div class="upideas_content clear_fix">
<div class="up_content clear_fix">
<div class="up_bar">
<h4>投稿須知</h4>
<ol >
<li>分享自己或朋友的Minds(心事),不浮夸、有意義,不含政治、×××、廣告、誹謗、歧視等內(nèi)容。</li>
<li>分享的Minds(心事),將在審核之后發(fā)布。</li>
<li>轉(zhuǎn)載請(qǐng)注明出處,任何由Minds引發(fā)的法律等糾紛,本站概不負(fù)責(zé)。</li>
<li>不得盜用站內(nèi)其他會(huì)員的Minds。</li>
</ol>
</div>
<div class="up_content_text">
<form method="post" action="putup" >
<textarea id="idea_text" name="idea_text" class="up_idea_text" rows="23" required placeholder="分享你的Minds(心事)..." ></textarea>
<span class="up_idea_err"></span><button type="submit" class="up_idea_btn" id="idea_btn" >投遞</button>
</form>
</div>
</div>
</div>
</div>
<%- include footer%>
打開routes/index.js文件,內(nèi)容最終為:
module.exports = function(app) {
app.get('/', function (req, res) {
res.render('index', { title: 'OMinds' });
});
app.get('/upminds', function (req, res) {
res.render('upminds', { title: 'OMinds' });
});
};打開瀏覽器,點(diǎn)擊投稿導(dǎo)航,效果:
好了,本站的基本布局以及OK了,有些同學(xué)可能會(huì)說了,導(dǎo)航里面不是還有很多東西沒實(shí)現(xiàn)嗎,不要緊,當(dāng)前已經(jīng)能基本滿足需求,別人能投稿,能顯示別人的投稿不就ok了嗎,其他的慢慢來。
下一章將會(huì)鏈接db,來動(dòng)態(tài)顯示內(nèi)容,不然,一直靜態(tài)的多沒意思啊。
注:有些同學(xué)可能回覺得,呀,你做這個(gè)教程干嘛啊,直接把源碼給我們不久ok了嗎,還在這墨跡個(gè)什么啊,我寫的代碼很亂,是之前ideas項(xiàng)目的代碼,現(xiàn)在做的是Ominds,完全是從頭開始做的,一步一步做的,不過,不用擔(dān)心,我一定會(huì)做完的,也沒多少東西,每天一章的話,基本上1周半就完事了。
請(qǐng)關(guān)注我的小站http://oideas.herokuapp.com/,最好是能注冊(cè)一下,當(dāng)然,由于用的是外機(jī),很卡,不能要求什么了。
ideas-ominds交流群:158325682,有想要一起做的,或者有什么不懂的都可以找我哦。
csdn全blog地址:http://blog.csdn.net/joveth/article/category/1862915
網(wǎng)頁標(biāo)題:【Nodejs開發(fā)】第2章網(wǎng)站首頁的布局
網(wǎng)頁URL:http://chinadenli.net/article32/gdgisc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App開發(fā)、移動(dòng)網(wǎng)站建設(shè)、云服務(wù)器、建站公司、品牌網(wǎng)站建設(shè)、網(wǎng)站收錄
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)