• 博客系统页面设计


    目录

    前言

    1.预期效果

    1.1博客列表页效果

    1.2博客详情页效果

    1.3博客登陆页效果

    2.实现博客列表页

    2.1实现导航栏

    2.2实现版心

    2.3实现个人信息

    2.4实现博客列表

    3.实现博客正文页

    3.1引入导航栏

    3.2引入版心

    3.3引入个人信息

    3.4实现博客正文

    4.实现博客登陆页

    4.1引入导航栏

    4.2实现版心

    4.3实现登陆框

    5.实现博客编辑页

    5.1引入导航栏

    5..2实现编辑区

    5.3引入 editor.md


    前言

    实现一个简单的博客系统.
    当前先完成页面设计的部分. 通过前面学习的前端知识来构建出网页.
    主要分成四个页面:
            博客列表页
            博客正文页
            博客登陆页
            博客编辑页

    1.预期效果

    1.1博客列表页效果

    1.2博客详情页效果

    1.3博客登陆页效果

    2.实现博客列表页

    创建 blog_list.html, 编写博客列表页.

    2.1实现导航栏

    编辑 blog_list.html, 创建导航栏的 html 代码.
    导航栏里面包含 logo, 标题, 以及一些按钮(跳转链接).
    为了实现左右排列, 在 logo 和 按钮 之间加一个 spacer 作为占位器.

    1. <div class="nav">
    2.   <img src="img/logo2.jpg" alt="">
    3.   <span class="title">我的博客系统span>
    4.   
    5.   <span class="spacer">span>
    6.   <a href="blog_list.html">主页a>
    7.   <a href="blog_edit.html">写博客a>
    8.   <a href="logout">注销a>
    9. div>

    准备一个 logo2.jpg, 放到 img 目录中.

    创建 common.css .
    对于导航栏来说, 每个页面都需要, 因此把样式提取出来.
    先清除浏览器默认样式
    准备一个 cat.jpg 作为背景图.
    需要把 html 和 body 高度都设为 100%, 使背景的高度和浏览器窗口高度一样.
    导航栏 nav 内部使用 flex 布局, 用来排列 logo 和一些按钮.

    1. * {
    2.   margin: 0;
    3.   padding: 0;
    4.   box-sizing: border-box;
    5. }
    6. /* 设置整体页面高度 */
    7. html, body {
    8.   height: 100%;
    9.   background-image: url(../img/cat.jpg);
    10.   background-position: center center;
    11.   background-size: cover;
    12.   background-repeat: no-repeat;
    13. }
    14. /* 上方导航栏 */
    15. .nav {
    16.   width: 100%;
    17.   height: 50px;
    18.   background-color: rgba(51, 51, 51, 0.4);
    19.   color: #fff;
    20.   display: flex;
    21.   justify-content: left;
    22.   align-items: center;
    23. }
    24. /* 导航栏中的图标 */
    25. .nav img {
    26.   width: 40px;
    27.   height: 40px;
    28.   margin-left: 30px;
    29.   margin-right: 10px;
    30.   border-radius: 50%;
    31. }
    32. /* 导航栏中的占位器 */
    33. .nav .spacer {
    34.   width: 70%;
    35. }
    36. /* 导航栏中的按钮 */
    37. .nav a {
    38.   color: #fff;
    39.   text-decoration: none;
    40.   padding: 0 10px;
    41. }

    引入 common.css

    <link rel="stylesheet" href="css/conmmon.css">

    2.2实现版心

    编辑 blog_list.html
    container 作为版心, 实现居中对齐的效果.
    左侧放用户信息
    右侧放博客列表

    1. <div class="container">
    2.   
    3.   <div class="container-left">
    4.   div>
    5.   
    6.   <div class="container-right">
    7.   div>
    8. div>

    编辑 common.css

    1. /* 页面内容容器, 版心 */
    2. .container {
    3.   /* 使用 calc 计算高度 */
    4.   height: calc(100% - 50px);
    5.   /* 设置版心宽度 */
    6.   width: 1000px;
    7.   /* 水平居中 */
    8.   margin: 0 auto;
    9.   /* 使用弹性布局 */
    10.   display: flex;
    11.   justify-content: space-between;
    12.   align-items: center;
    13. }
    14. /* 左侧部分, 用来放置用户信息 */
    15. .container-left {
    16.   height: 100%;
    17.   width: 200px;
    18. }
    19. /* 右侧部分, 用来放置正文 */
    20. .container-right {
    21.   height: 100%;
    22.   /* 和左侧部分中间留出 5px 间隙 */
    23.   width: 795px;
    24.   /* 如果内容溢出就自动加上滚动条 */
    25.   overflow: auto;
    26.   background-color: rgba(255, 255, 255, 0.8);
    27.   border-radius: 10px;
    28. }

    2.3实现个人信息

    编辑 blog_list.html
    把个人信息放到一个 .card div 中.
    个人信息中包含 头像 (img), 用户名 (h3), 用户的 github (a), 用户的文章数量和分类数量.

    1. <div class="container-left">
    2.   <div class="card">
    3.     <img src="img/doge.jpg" class="avtar" alt="">
    4.     <h3>小林h3>
    5.     <a href="http:www.github.com">github 地址a>
    6.     <div class="counter">
    7.       <span>文章span>
    8.       <span>分类span>
    9.     div>
    10.     <div class="counter">
    11.       <span>2span>
    12.       <span>1span>
    13.     div>
    14.   div>
    15. div>

    编辑 common.css

    1. /* 展示用户信息的卡片 */
    2. .card {
    3.   background-color: rgba(255, 255, 255, 0.8);
    4.   border-radius: 10px;
    5.   padding: 30px;
    6. }
    7. /* 用户头像 */
    8. .card img {
    9.   width: 140px;
    10.   height: 140px;
    11.   border-radius: 50%;
    12. }
    13. /* 用户名 */
    14. .card h3 {
    15.   text-align: center;
    16.   padding: 10px;
    17. }
    18. /* 用户 github 链接 */
    19. .card a {
    20.   display: block;
    21.   text-align: center;
    22.   color: #999;
    23.   text-decoration: none;
    24.   padding: 10px;
    25. }
    26. /* 展示文章数目的面板 */
    27. .card .counter {
    28.   padding: 5px;
    29.   display: flex;
    30.   justify-content: space-around;
    31. }

    2.4实现博客列表

    编辑 blog_list.html
    每个博客使用 div.blog 来表示.
    每个博客中包含标题, 发布时间, 描述, 查看全文按钮.

    1. <div class="container-right">
    2. <div class="blog">
    3. <div class="title">我的第一篇博客div>
    4. <div class="date">2023-10-15div>
    5. <div class="desc">
    6. 从今天起, 我要认真敲代码. Lorem ipsum, dolor sit amet consectetur
    7. adipisicing elit. Cum distinctio ullam eum ut
    8. veroab laborum numquam tenetur est in dolorum a sint, assumenda
    9. adipisci similique quaerat vel.Facere,et.
    10. div>
    11. <a href="content.html" class="detail">查看全文>>a>
    12. <div class="title">我的第二篇博客div>
    13. <div class="date">2023-10-15div>
    14. <div class="desc">
    15. 从今天起, 我要认真敲代码. Lorem ipsum, dolor sit amet consectetur
    16. adipisicing elit. Cum distinctio ullam eum ut
    17. veroab laborum numquam tenetur est in dolorum a sint, assumenda
    18. adipisci similique quaerat vel.Facere,et.
    19. div>
    20. <a href="content.html" class="detail">查看全文>>a>
    21. div>
    22. div>

    创建 blog_list.css
    这部分内容不再是公共部分了, 放到单独的 css 中.
    使用伪类选择器 .blog .detail:hover , 实现光标悬停时修改样式的功能.
    给 .blog .detail 中加上过度效果 transition: all 0.3s; 使悬停的样式改变更 逼真 .

    1. /* 表示第一篇博客 */
    2. .blog {
    3. width: 100%;
    4. padding: 10px 20px;
    5. }
    6. /* 博客的标题 */
    7. .blog .title {
    8. color: black;
    9. font-size: 20px;
    10. font-weight: 700;
    11. text-align: center;
    12. padding: 10px 0;
    13. }
    14. /* 博客的摘要 */
    15. .blog .desc {
    16. color: #000;
    17. text-indent: 2em;
    18. margin-top: 10px;
    19. }
    20. /* 博客的日期 */
    21. .blog .date {
    22. color: #008000;
    23. margin-top: 10px;
    24. text-align: center;
    25. }
    26. /* 查看详情按钮 */
    27. .blog .detail {
    28. display: block;
    29. width: 120px;
    30. height: 40px;
    31. line-height: 40px;
    32. color: black;
    33. text-align: center;
    34. text-decoration: none;
    35. margin: 10px auto 0 auto;
    36. border: 2px solid black;
    37. /* 给颜色加上过渡效果 */
    38. transition: all 0.3s;
    39. }
    40. /* 查看详情按钮的鼠标hover效果 */
    41. .blog .detail:hover {
    42. background-color: #000;
    43. color: #fff;
    44. }

    引入 blog_list.css

    <link rel="stylesheet" href="css/blog_content.css">

    3.实现博客正文页

    创建 blog_content.html

    3.1引入导航栏

    编辑 blog_content.html
    这部分代码和 blog_list.html 中相同, 直接复制即可.

    1. <div class="nav">
    2.   <img src="img/logo2.jpg" alt="">
    3.   <span class="title">我的博客系统span>
    4.   
    5.   <span class="spacer">span>
    6.   <a href="blog_list.html">主页a>
    7.   <a href="blog_edit.html">写博客a>
    8.   <a href="logout">注销a>
    9. div>

    引入样式 common.css

    <link rel="stylesheet" href="css/conmmon.css">

    3.2引入版心

    编辑 blog_content.html
    这部分代码和 blog_list.html 相同, 直接复制

    1. <div class="container">
    2.   
    3.   <div class="container-left">
    4.   div>
    5.   <div class="container-right">
    6.    
    7.   div>
    8. div>

    3.3引入个人信息

    编辑 blog_content.html
    这部分代码和 blog_list.html 相同, 直接复制

    1. <div class="container-left">
    2.   <div class="card">
    3.     <img src="img/doge.jpg" class="avtar" alt="">
    4.     <h3>小林h3>
    5.     <a href="http:www.github.com">github 地址a>
    6.     <div class="counter">
    7.       <span>文章span>
    8.       <span>分类span>
    9.     div>
    10.     <div class="counter">
    11.       <span>2span>
    12.       <span>1span>
    13.     div>
    14.   div>
    15. div>

    3.4实现博客正文

    编辑 blog_content.html
    博客内容整体放到 div.blog-content 中.
    博客内容中包含博客标题 (h3), 博客时间(div.date), 博客正文(p)

    1. <div class="blog-content">
    2.   
    3.   <h3>我的第一篇博客h3>
    4.   
    5.   <div class="date">2021-06-02div>
    6.   
    7.   <p>
    8.    从今天起我要好好敲代码.
    9.    Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aut recusandae
    10. omnis natus ut! Autem alias
    11.    ullam sit facilis ipsa dolore, molestiae neque aperiam in a facere dolor
    12. mollitia dolorum animi.
    13.    Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aut recusandae
    14. omnis natus ut! Autem alias
    15.    ullam sit facilis ipsa dolore, molestiae neque aperiam in a facere dolor
    16. mollitia dolorum animi.
    17.    Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aut recusandae
    18. omnis natus ut! Autem alias
    19.    ullam sit facilis ipsa dolore, molestiae neque aperiam in a facere dolor
    20. mollitia dolorum animi.
    21.   p>
    22.   <p>
    23.    Lorem ipsum dolor sit amet consectetur adipisicing elit. Laudantium sint
    24. accusantium, enim iste
    25.    corrupti itaque, omnis alias maiores nemo quae rerum deleniti facere
    26. officiis iure velit. Blanditiis
    27.    pariatur delectus perferendis.
    28.    Lorem ipsum dolor sit amet consectetur adipisicing elit. Laudantium sint
    29. accusantium, enim iste
    30.    corrupti itaque, omnis alias maiores nemo quae rerum deleniti facere
    31. officiis iure velit. Blanditiis
    32.    pariatur delectus perferendis.
    33.   p>
    34. div>

    创建 blog_content.css

    1. /* 博客正文容器 */
    2. .blog-content {
    3.   padding: 30px;
    4. }
    5. /* 博客标题 */
    6. .blog-content h3 {
    7.   text-align: center;
    8.   padding: 20px 0;
    9. }
    10. /* 博客日期 */
    11. .blog-content .date {
    12.   color: #008000;
    13.   padding: 10px 0;
    14.   text-align: center;
    15. }
    16. /* 博客内容段落 */
    17. .blog-content p {
    18.   text-indent: 2em;
    19.   padding: 10px 0;
    20. }

    引入 blog_content.css

    <link rel="stylesheet" href="css/blog_content.css">

    4.实现博客登陆页

    4.1引入导航栏

    编辑 login.html
    这部分代码和 blog_list.html 中相同, 直接复制即可.

    1. <div class="nav">
    2.   <img src="img/logo2.jpg" alt="">
    3.   <span class="title">我的博客系统span>
    4.   
    5.   <span class="spacer">span>
    6.   <a href="blog_list.html">主页a>
    7.   <a href="blog_edit.html">写博客a>
    8.   <a href="logout">注销a>
    9. div>

    引入样式 common.css

    <link rel="stylesheet" href="css/conmmon.css">

    4.2实现版心

    编辑 login.html
    使用 flex 使登陆对话框能够在页面中水平垂直居中.

    1. <div class="login-container">
    2.  
    3. div>

    创建 login.css

    1. .login-container {
    2.   width: 100%;
    3.   height: calc(100% - 50px);
    4.   display: flex;
    5.   justify-content: center;
    6.   align-items: center;
    7. }

    引入 login.css

    <link rel="stylesheet" href="css/login.css">

    4.3实现登陆框

    编辑 login.html
    登陆框整体放到 div.login-dialog 中.
    内部包含三个行, 使用 div.row 表示.
    每个行里分别包含, 用户名输入框, 密码输入框, 提交按钮.

    编辑 login.css
    使用 #submit:active 伪类选择器, 实现点击按钮时样式切换的效果.

    1. .login-dialog {
    2.   width: 400px;
    3.   height: 400px;
    4.   background-color: rgba(255, 255, 255, 0.8);
    5.   border-radius: 10px;
    6. }
    7. .login-dialog h3 {
    8.   padding: 50px 0;
    9.   text-align: center;
    10. }
    11. .login-dialog .row {
    12.   height: 50px;
    13.   display: flex;
    14.   justify-content: center;
    15.   align-items: center;
    16. }
    17. .login-dialog .row span {
    18.   display: block;
    19.   width: 100px;
    20.   font-weight: 700;
    21. }
    22. #username,
    23. #password {
    24.   width: 200px;
    25.   height: 40px;
    26.   line-height: 40px;
    27.   font-size: 24px;
    28.   border-radius: 10px;
    29.   border: none;
    30.   outline: none;
    31.   text-indent: 10px;
    32. }
    33. #submit {
    34.   width: 300px;
    35.   height: 50px;
    36.   color: white;
    37.   background-color: green;
    38.   border: none;
    39.   border-radius: 10px;
    40. }
    41. #submit:active {
    42.   background-color: #666;
    43. }

    5.实现博客编辑页

    创建 blog_edit.html

    5.1引入导航栏

    编辑 blog_edit.html
    这部分代码和 blog_list.html 中相同, 直接复制即可.

    1. <div class="nav">
    2.   <img src="img/logo2.jpg" alt="">
    3.   <span class="title">我的博客系统span>
    4.   
    5.   <span class="spacer">span>
    6.   <a href="blog_list.html">主页a>
    7.   <a href="blog_edit.html">写博客a>
    8.   <a href="logout">注销a>
    9. div>

    引入样式 common.css

    <link rel="stylesheet" href="css/conmmon.css">

    5..2实现编辑区

    编辑 blog_edit.html
    整个编辑区放到 div.blog-edit-container 中.
    里面包含一个标题编辑区, 和内容编辑区.
    标题编辑区, 包含一个 input, 用来填写标题, 以及一个 button 按钮用于提交.
    内容编辑区先创建一个 div#editor, 后面将使用 editor.md 进行初始化.

    1. <div class="blog-edit-container">
    2.   
    3.   <div class="title">
    4.     <input type="text" placeholder="在这里写下文章标题" id="title">
    5.     <button id="submit">发布文章button>
    6.   div>
    7.   
    8.   <div id="editor">div>
    9. div>

    创建 blog_edit.css
    #editor 需要使用 opacity: 80%; 设置透明度. 如果直接使用 background-color 后面会被
    editor.md 给覆盖掉.

    1. .blog-edit-container {
    2.   width: 1000px;
    3.   height: calc(100% - 50px);
    4.   margin: 0 auto;
    5. }
    6. .blog-edit-container .title {
    7.   width: 100%;
    8.   height: 50px;
    9.   display: flex;
    10.   justify-content: space-between;
    11.   align-items: center;
    12. }
    13. #title {
    14.   height: 40px;
    15.   width: 890px;
    16.   text-indent: 10px;
    17.   border-radius: 10px;
    18.   outline: none;
    19.   border: none;
    20.   background-color:rgba(255, 255, 255, 0.8);
    21. }
    22. #submit {
    23.   height: 40px;
    24.   width: 100px;
    25.   color: white;
    26.   background-color: orange;
    27.   border: none;
    28.   outline: none;
    29.   border-radius: 10px;
    30. }
    31. #editor {
    32.   border-radius: 10px;
    33.   /* 针对 #editor 用 bgc 属性无法设置半透明了. 里面包含的内容带了背景色 */
    34.   /* background-color:rgba(255, 255, 255, 0.8); */
    35.   /* 可以使用 opacity 属性实现 */
    36.   opacity: 80%;
    37. }

    5.3引入 editor.md

    editor.md 是一个开源的页面 markdown 编辑器组件.
    官网参见: https://pandao.github.io/editor.md/
    用法可以参考代码中的 examples 目录中的示例. 非常丰富.

    1) 下载 editor.md
    从官网上下载到压缩包. 放到目录中. 目录结构如下:

    2) 引入 editor.md

    1. <link rel="stylesheet" href="editor.md/css/editormd.min.css" />
    2. <script src="js/jquery.min.js">script>
    3. <script src="editor.md/lib/marked.min.js">script>
    4. <script src="editor.md/lib/prettify.min.js">script>
    5. <script src="editor.md/editormd.js">script>

    3) 初始化 editor.md
    编辑 blog_edit.html

     

    1. // 初始化编辑器
    2. var editor = editormd("editor", {
    3.   // 这里的尺寸必须在这里设置. 设置样式会被 editormd 自动覆盖掉.
    4.   width: "100%",
    5.   // 高度 100% 意思是和父元素一样高. 要在父元素的基础上去掉标题编辑区的高度
    6.   height: "calc(100% - 50px)",
    7.   // 编辑器中的初始内容
    8.   markdown: "# 在这里写下一篇博客",
    9.   // 指定 editor.md 依赖的插件路径
    10.   path: "editor.md/lib/"
    11. });

  • 相关阅读:
    LeetCode_279_完全平方数
    筛选图片,写JSON文件和复制
    Scala中文unicode互转
    UE5 C++ 发射子弹发射(Projectile)
    一个示例学习C语言到汇编层面
    三相PFC电流不平衡的解决方法---记录一次问题的现象和解决办法
    学习笔记——七周成为数据分析师《第一周:数据分析思维》
    C++ lower_bound() upper_bound() 函数用法详解(深入了解,一文学会)
    四种质数筛选算法总结(c++)
    docker学习(十三)docker安装dejavu
  • 原文地址:https://blog.csdn.net/qq_65307907/article/details/133829180