【Go web开发之revel+mgo】第5章 样式与留言板的设计

joveth · · 3480 次点击 · · 开始浏览    
这是一个创建于 的文章,其中的信息可能已经有所发展或是发生改变。

演示地址   http://gblog-revel.herokuapp.com/


1.样式

这是整个项目的css,为了减少麻烦我们把它全部放出来 styles.css:


body{
	margin: 0 auto;
	padding: 0;
	background: url('../img/section_bg.png');
	font: 14px "Hiragino Sans GB", "Microsoft YaHei", Arial, sans-serif;
	line-height: 20px;
	letter-spacing: 0.02em;
	color: #666;
	background-attachment:fixed;
}
a{
	color: #1abc9c;
	text-decoration: none;
	-webkit-transition: 0.25s;
	-moz-transition: 0.25s;
	-o-transition: 0.25s;
	transition: 0.25s;
	-webkit-backface-visibility: hidden;
}
.main-nav{
	margin: 0 auto;
	width: 692px;
	padding:0;
}
.top-bar{
	width:100%;
	background: #34495e;
	border-bottom-right-radius: 6px;
	border-bottom-left-radius: 6px;
	box-shadow:  0 2px rgba(0,0,0,0.075),0 0 6px #7aba7b;
	-webkit-box-shadow:0 2px  rgba(0,0,0,0.075),0 0 6px #7aba7b;
	-moz-box-shadow:0 2px  rgba(0,0,0,0.075),0 0 6px #7aba7b;
	margin-bottom:28px;
}
.top-bar-inner{
	min-height: 48px;
	padding:0 4px;
}
.ul-nav{
	position: relative;
	left: 0;
	display: block;
	float: left;
	margin: 0 10px 0 0;
	list-style: none;
	font-size: 18px;
	padding:0;
}
.ul-nav>li {
	position: relative;
	float: left;
	line-height: 20px;
}
.ul-nav>li>a{
	padding: 14px 24px 17px;
	text-decoration: none;
	display: block;
	color: white;
	text-shadow: 0 -1px 0 rgba(0,0,0,0.25);
}
.ul-nav>li>a:hover,.ul-nav>li>a:focus{
	color: #1abc9c;
}
.navbar-news {
	background-color: #e74c3c;
	border-radius: 30px;
	color: white;
	display: block;
	font-size: 12px;
	font-weight: 500;
	line-height: 18px;
	min-width: 8px;
	padding: 0 5px;
	position: absolute;
	right: -7px;
	text-align: center;
	text-shadow: none;
	top: 8px;
	z-index: 10;
}
.ul-nav .active > a, .ul-nav .active > a:hover, .ul-nav .active > a:focus {
  background-color: transparent;
  color: #1abc9c;
  -webkit-box-shadow: none;
  -moz-box-shadow: none;
  box-shadow: none; 
}
.cell{
	background-color:#1bc6a5;
	color: #cff3ec;
	font-size: 15px;
	border-radius: 4px;
	-webkit-border-radius: 4px;
	-moz-border-radius: 4px;
	-o-border-radius: 4px;
	-khtml-border-radius: 4px;
	padding: 18px 20px 0px 20px; 
	margin-bottom: 30px;
	box-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);

}
.cell-subject{
	margin: 0;
}
.cell-subject-title{
	color: #34495e;
	font-size: 24px;
	font-weight: 700;
	text-decoration: none;
}
a.cell-subject-title:hover{
	text-decoration: underline;
}
.subject-infor{
	color:#34495e;
	line-height: 19px;
	padding: 2px 0;
	font-size: 13px;
	margin:2px 0;
}
.cell-text{
	padding: 4px 0;
	word-break: break-all;
}
.comment-num{
	float:right;
	border: 5px solid #d7dce0;
	border-radius: 50px;
	font-size: 14px;
	line-height: 16px;
	padding: 0 4px;
	-webkit-transition: background 0.2s ease-out, border-color 0s ease-out, color 0.2s ease-out;
	-moz-transition: background 0.2s ease-out, border-color 0s ease-out, color 0.2s ease-out;
	-o-transition: background 0.2s ease-out, border-color 0s ease-out, color 0.2s ease-out;
	transition: background 0.2s ease-out, border-color 0s ease-out, color 0.2s ease-out;
	-webkit-backface-visibility: hidden;
	background-color: white;
	border-color: white;
	border-width: 2px;
	color: #BBB6B6;
}
.write-nav{
	padding: 10px;
	background-color: #f9f9f9;
	border: 1px solid #e4e4e4;
	border-radius: 5px;
}
.footer{
	margin:20px 0 10px 0;
	text-align: center;
	min-height: 20px;
}
.comment-nav,.history-nav{
	background-color: white;
	border: 1px solid #DDD;
	border-radius: 4px;
}
.comment-title,.history-title{
	padding: 10px 20px;
	border-bottom: 1px solid #e2e2e2;
	font-size: 15px;
	font-weight: bold;
}
.comment-cell{
	padding: 10px 10px;
	border-top: 2px solid #fff;
	border-bottom: 1px solid #e2e2e2;
}
.comment-inputbox{
	background-color: #E7E7D8;
	border: 1px solid #d6d6c6;
	padding:5px 10px;
	border-radius: 8px;
	height: 224px;

}
.comment-input-infor{
	float: left;
	width: 180px;
	height: 200px;
	display: inline;
	overflow: hidden;
	margin:5px 0  0 0;
	list-style: none;
	padding:0;
}

.comment-input-text{
	float: left;
	width: 458px;
	height: 150px;
	margin:5px 0  0 10px;
}
.ctextarea {
	height: 142px !important;
	resize: vertical;
}
.comment-input-text-btn{
	float:right;
	margin-top:20px;
}
.func-color{
	color: #F70246;
}
.func-name{
	color: #24C54B;
}
.func-str{
	color:#C29916;
}
.func-type{
	color:rgb(0, 173, 255);
}
.pln-w{
	color:white;
}
.pln-b{
	color:white;
}
.history-cell{
	padding: 10px 20px;
	border-top: 2px solid #fff;
	border-bottom: 1px solid #e2e2e2;
}
li time{
	margin-right: 8px;
	font-size: 13px;
}
.history-auth{
	padding-left: 8px;
	color: #cfcfcf;
	font-size: 13px;
	font-family: 'Microsoft Yahei';
}
.email-other{
	background-color: #f9f9f9;
	border: 1px solid #e4e4e4;
	border-radius: 5px;
	padding: 5px 20px;
	margin-bottom: 10px;
}
.email-title{
	margin: 0 0 22px;
	padding-top: 21px;
	color: white;
	font-family: 'Microsoft Yahei';
}
.email-nav ul{
	list-style-type: none;
	margin: 0 0 26px;
	padding:0;
}
.email-nav ul li:first-child {
	border-top: none;
	padding-top: 1px;
}
.email-nav ul li {
	border-top: 1px solid #1bc6a5;
	line-height: 19px;
	padding: 6px 0;
}
.email-tag{
	border-radius: 4px;
	background: #1abc9c;
	color: white;
	cursor: pointer;
	margin-right: 5px;
	margin-bottom: 5px;
	overflow: hidden;
	padding: 6px 13px 6px 19px;
	position: relative;
	vertical-align: middle;
	display: inline-block;
	zoom: 1;
	-webkit-transition: 0.14s linear;
	-moz-transition: 0.14s linear;
	-o-transition: 0.14s linear;
	transition: 0.14s linear;
	-webkit-backface-visibility: hidden;
}
.email-tag span{
	color: white;
	cursor: pointer;
	zoom: 1;
}
.email-nav{
	background: white;
	border: 2px solid #1abc9c;
	border-radius: 6px;
	padding: 6px 1px 1px 6px;
	overflow-y: auto;
	text-align: left;
	margin-bottom: 15px;
}
.email-tag:hover {
	background-color: #16a085;
	padding-left: 12px;
	padding-right: 20px;
}
.erro{
	color:red;
}
.infor-content,.comments{
	margin-bottom: 20px;
	padding: 10px 20px;
	background-color: white;
	border: 1px solid #DDD;
	border-radius: 4px;
	-webkit-border-radius: 4px;
	-moz-border-radius: 4px;
	-o-border-radius: 4px;
	-khtml-border-radius: 4px;
}
.infor-header{
	padding-bottom: 9px;
	margin: 0 0 20px;
	border-bottom: 1px solid #eee;
}
.infor-header h3{
	margin-top:10px;
}
.infor-body{
	padding-bottom: 9px;
}
hr {
	margin: 9px 0;
}
dl.the-comments dd{
	margin-left: 0;
	padding-top: 10px;
	padding-bottom: 10px;
	border-bottom: 1px dashed #CCC;
}
.user-comment p{
	margin:5px 0 0 0;
}

2.留言板设计

在views/App下新建Message.html 内容:

{{set . "title" "Message - GBlog"}}
{{set . "mess" "active" }}
{{template "header.html" .}}
<div class="content">
    <div class="comment-nav">
       <div class="comment-title">
         留言板
         <span style="float:right" title="Total messages">[100]</span>
       </div>
       <div class="comment-cell">
         <div class="comment-inputbox">
            <form action="/putmessage" method="post" >
                  <ul class="comment-input-infor">
                    {{with $field := field "message.Email" .}}
                    <li>
                      EMAIL
                      <input type="email"  id="{{$field.Id}}" name="{{$field.Name}}" class="form-control " required value="{{if $field.Error}}{{$field.Error}}{{else}}{{$field.Value}}{{end}}"/>
                    </li>
                     {{end}}
                    <li>
                      QQ
                      {{with $field := field "message.QQ" .}}
                      <input type="text"  id="{{$field.Id}}" name="{{$field.Name}}" class="form-control" value="{{if $field.Error}}{{$field.Error}}{{else}}{{$field.Value}}{{end}}" />
                      {{end}}
                    </li>
                    <li>
                      个人主页
                      {{with $field := field "message.Url" .}}
                      <input type="text"  id="{{$field.Id}}" name="{{$field.Name}}" class="form-control" placeholder="Don't with http://  " value="{{if $field.Error}}{{$field.Error}}{{else}}{{$field.Value}}{{end}}"/>
                      {{end}}
                    </li>
                  </ul>
                  <div class="comment-input-text">
                    MESSAGE
                    <div>
                      {{with $field := field "message.Content" .}}
                      <textarea class="form-control ctextarea" id="{{$field.Id}}" name="{{$field.Name}}" required>{{if $field.Error}}{{$field.Error}}{{else}}{{$field.Value}}{{end}}</textarea>
                      {{end}}
                    </div>
                  </div>
                  <button type="submit" class="btn btn-success comment-input-text-btn">SUBMIT</button>
            </form>
         </div>
       </div>
       <div class="comment-cell">
         <pre ><code><span class="func-color">func</span><span class="func-name"> UserMessage</span><span class="pln">() </span><span class="pun">{</span><span class="pln">
    </span><span class="func-color">var</span><span class="pun"> </span><span class="pln">email </span><span class="func-type">string </span><span class="pun">=</span><span class="pln"> </span><span class="func-str">"jov123@163.com"</span><span class="pun">;</span><span class="pln-w">
    </span><span class="func-color">var</span><span class="pln-w"> </span><span class="pln">url </span><span class="pln">=</span><span class="pln-w"> </span><a href="http://jov.herokuapp.com" class="func-str" target="_blank">http://jov.herokuapp.com</a><span class="pln-w">;</span><span class="pln">
    </span><span class="lit">Date </span><span class="func-color">:=</span><span class="pln"> </span><span class="func-str">"2014-04-15 12:50"</span><span class="pun">;</span><span class="pln">
    </span><span class="func-color">var </span><span class="lit">Message</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="func-str">"nice!"</span><span class="pln">;
</span><span class="pun">}</span><span class="pln">
</code></pre>
       </div>
        <div class="comment-cell">
         <pre style="background:#2d2d2d;"><code><span class="func-color">func</span><span class="func-name"> UserMessage</span><span class="pln-w">() </span><span class="pln-w">{</span><span class="pln-w">
    </span><span class="func-color">var</span><span class="pln-w"> </span><span class="pln-w">email </span><span class="func-type">string </span><span class="pln-w">=</span><span class="pln-w"> </span><span class="func-str">"jov123@163.com"</span><span class="pln-w">;</span><span class="pln-w">
    </span><span class="func-color">var</span><span class="pln-w"> </span><span class="pln-w">url </span><span class="pln-w">=</span><span class="pln-w"> </span><a href="http://jov.herokuapp.com" class="func-str" target="_blank">http://jov.herokuapp.com</a><span class="pln-w">;</span><span class="pln-w">
    </span><span class="pln-w">Date </span><span class="func-color">:=</span><span class="pln-w"> </span><span class="func-str">"2014-04-15 12:50"</span><span class="pln-w">;</span><span class="pln-w">
    </span><span class="func-color">var </span><span class="pln-w">Message</span><span class="pln-w"> </span><span class="pln-w">=</span><span class="pln-w"> </span><span class="func-str">"nice!"</span><span class="pln-w">;
</span><span class="pln-w">}</span><span class="pln-w">
</code></pre>
       </div>
  </div>
</div>
{{template "footer.html" .}}

虽然后面的块很乱,不要在意那么多了。

在conf/routes添加;

GET     /message                                App.Message

在app/controllers/app.go添加方法:
func (c App) Message() revel.Result {
	return c.Render()
}

好的,点击留言链接看看效果:



下一章我们来实现它。



有疑问加站长微信联系(非本文作者)

本文来自:CSDN博客

感谢作者:joveth

查看原文:【Go web开发之revel+mgo】第5章 样式与留言板的设计

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

3480 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传