• 简单博客网页


    目录

    注意事项

    详细解释

    源码部分

    HTML文件:

    CSS文件:

    JS文件:


    跟着自学网的教程,敲的一个自学网的网页。

    先上gif图:

    因为原图太大不能上传,压缩了一下清晰度......

    有导航栏,内容区,侧边栏,按钮动画,还有回到顶部的小事件。

    注意事项

    jQuery可以下载好一起放入文件夹里直接引用的,免得网络问题不能用。

    看起来挺简单的一个页面还是有很多可以注意到的事项,记录一下

    1.导航栏使用ul同时向右浮动时,可以将标签倒着写,这样不会出错;

    2.设置float后,父元素的高度就消失了,如果页面下面还有内容,就会错位,需要将样式清除;

    3.span不能设置高宽,需要将其display设置成inline-block后才能设置,最好还是采用其他可以设置的元素,比如div;

    4.margin和padding:前者是外边距,后者是内边距,若带有背景色,使用padding可以将背景色一同撑大,margin则会留白;

    5.每次写项目前,可以先网上找一份清除浏览器样式的CSS文件复制进去,保证浏览器的样式不会影响自己设置的样式,这里CSS的前30几行就是清除浏览器样式用的;

    6.CSS中>,+,~,空格,逗号等符号连着选择器一起使用还挺多,需要大量练习才行;

    7.按钮的动画CSS就能完成,CSS3提供了好多动画啊,还有好多参数……

    详细解释

    实现步骤如下:

    1.整个页面分成了三部分:头部、内容区、尾部
    2.整个的包裹id定义为wrap,内容区的class定义为content,尾部的class定义为footer
    3.紧跟着的mask为整个页面设置遮罩:当右侧菜单栏弹出时,整个页面加上遮罩
    4.slider为侧边栏菜单
    5.top为右下角"回到顶部"的按钮

    最后面有源码,前面截图的为了讲解用的,复制部分代码太烦了,要不停改格式,我懒得改。

    先来讲头部header。 

    头部包括导航栏和第0个透明介绍部分:

    按钮是有动画的,我做了个GIF图,不能浪费,这里生硬的放进来。

     如图显示,整个的背景为wrap,

    1. /*整个页面最外层的包裹*/
    2. #wrap {
    3. /*背景使用banner的图片,不重复的显示,居中,固定在页面上,就可以不随滚动条而变化*/
    4. /*同时设置整个页面的文字*/
    5. background: url("./img/banner.jpeg") no-repeat;
    6. background-position: center center;
    7. background-attachment: fixed;
    8. background-size: cover;
    9. font-family: "Microsoft Yahei","Hiragino Sans GB","Helvetica Neue",Helvetica,tahoma,arial,"WenQuanYi Micro Hei",Verdana,sans-serif,"\5B8B\4F53";
    10. }

    整个header如下,包括导航栏和第0个透明介绍部分: 

     导航栏样式如下:

    1. /*logo单独设置靠左的li元素,可以单独添加样式*/
    2. .logo {
    3. float: left;
    4. margin-left: 40px;
    5. }
    6. /*class为logo的li元素下的a标签样式----即"博客"二字*/
    7. .logo a {
    8. font-size: 20px;
    9. color: white;
    10. font-weight: 700;
    11. /*文字中间的空隙*/
    12. letter-spacing: 2px;
    13. }

    第0部分样式如下:

    1. .banner {
    2. height: 600px;
    3. }
    4. /*设置第0部分的内容样式*/
    5. .banner .inner {
    6. /*全部使用白色,居中对齐,并设置一个最大的宽度*/
    7. color: white;
    8. text-align: center;
    9. margin: 0 auto;
    10. max-width: 400px;
    11. /*设置relative就会随着鼠标上下滚动,fixed就会固定在页面上,跟背景图一样*/
    12. position: relative;
    13. top:160px;
    14. }
    15. /*设置文本上下的线条的样式*/
    16. .line {
    17. /*这个宽度为父元素inner的宽度400px*/
    18. width: 100%;
    19. /*设置了一个高度为2px的白色背景作为线条*/
    20. height: 5px;
    21. background: white;
    22. margin: 10px 10px;
    23. }
    24. /*inner里面的p元素设置样式*/
    25. .banner .inner p {
    26. line-height: 30px;
    27. font-size: 18px;
    28. letter-spacing: 1px;
    29. }
    30. /*给按钮设置样式*/
    31. .banner .inner button {
    32. margin-top: 20px;
    33. /*使用margin会留白,padding会带着背景色一起撑开*/
    34. padding: 10px 20px;
    35. background: #e85e17;
    36. /*设置圆角*/
    37. border-radius: 5px;
    38. /*去除按钮的边框*/
    39. border: none;
    40. color: white;
    41. /*去掉按钮点击时的边框*/
    42. outline: none;
    43. }
    44. /*鼠标悬浮到按钮上时,按钮的动作*/
    45. .banner .inner button:hover {
    46. /*鼠标经过时,开始旋转720°动画,并放大2倍,持续时间2s*/
    47. transform: rotate(720deg) scale(2);
    48. transition: 2s;
    49. }
    50. .banner .inner .more {
    51. margin-top: 140px;
    52. }

    再给导航栏设置个active的样式,选中当前标签时,下方出现白色加粗的横线,right-menu除外。样式如下:

    选中main:

    选中blog: 

    网页一打开默认选中的是main。

    样式如下:

    1. .active {
    2. position: relative;
    3. }
    4. /*同样设置了4px高度的白色背景框作为短横线*/
    5. /*因为4个标签中main、web、blog都添加了span标签*/
    6. /*right-menu没有添加*/
    7. .active span {
    8. position: absolute;
    9. height: 4px;
    10. background: white;
    11. bottom: 5px;
    12. left: 0;
    13. width: 100%;
    14. }

    添加点击动作:

    1. // 1.鼠标移到标签上时,当前标签有一个白色的下划线,其他的兄弟标签样式取消
    2. $('.nav-ul li').click(function () {
    3. $(this).addClass('active')
    4. $(this).siblings().removeClass('active')
    5. })

     当然你也修改为其他动作,随你开心。 

     最后还有个side-bar的class放到后面解释。

     第二部分为内容content区,分了三块:

     先看part-one:

    几行文字和一条线,还有几个图片+旋转的边框,背景色记得设置透明度:

     

     CSS样式如下:

    1. /*中间的内容整个设置为透明度0.9,保证滚动条滑动时,主背景可以透出来,*/
    2. /*同时主背景用的是fixed,不随滚动条而移动*/
    3. .content{
    4. opacity: .9;
    5. }
    6. /*设置第一部分整体的样式*/
    7. .part-one {
    8. text-align: center;
    9. color: white;
    10. background: rgba(67,178,165,1);
    11. padding-top: 65px;
    12. opacity: 0.95;
    13. }
    14. .wraper {
    15. /*margin这样设置可以居中*/
    16. margin: 0 auto;
    17. max-width: 1080px;
    18. }
    19. .wraper h2 {
    20. padding: 15px 0;
    21. }
    22. .wraper .line {
    23. /*居中可以这样设置margin*/
    24. margin: 15px auto;
    25. width: 40%;
    26. height: 5px;
    27. background-color: #666666;
    28. }
    29. .wraper p {
    30. margin: 25px 0;
    31. font-size: 18px;
    32. }
    33. .icon {
    34. margin: 30px auto;
    35. margin-bottom: 0;
    36. padding-bottom: 30px;
    37. }
    38. /*给3个图标设置边框*/
    39. /*宽度2px实线、绿色,80*80px,旋转45°*/
    40. .icon .item{
    41. border: 2px solid green;
    42. /*因为span不可以调整宽高,所以先将display设置成如下*/
    43. display: inline-block;
    44. height: 80px;
    45. width: 80px;
    46. margin-right: 50px;
    47. transform: rotate(45deg);
    48. }
    49. /*设置宽和高为100%,适应父元素item的宽和高,就不会超出item的border,
    50. 同时img继承了item的旋转,需要纠正回来*/
    51. .icon .item img{
    52. width: 100%;
    53. height: 100%;
    54. transform: rotate(-45deg);
    55. }

    第二部分为分栏的显示,有重复的3个分栏,可以先做一个,然后复制3份:

     

    样式如下:

    1. /*给整个第二部分添加背景色*/
    2. .part-two {
    3. background-color: rgb(33,41,50);
    4. }
    5. .first .text-right {
    6. float: right;
    7. }
    8. .first-left {
    9. width: 41%;
    10. }
    11. .first-left img {
    12. width: 100%;
    13. }
    14. /*表示first标签的第一代子标签div*/
    15. .first>div {
    16. float: left;
    17. }
    18. /*设置浮动之后,父元素first就没有了高度,需要清除浮动,用伪元素做以下处理*/
    19. .clear-fix:after {
    20. content: '';
    21. display: block;
    22. clear: both;
    23. }
    24. .first-text {
    25. position: relative;
    26. top: 68px;
    27. left: 50px;
    28. width: 55%;
    29. color: white;
    30. }
    31. .first-text h2 {
    32. font-size: 24px;
    33. margin-bottom: 10px;
    34. }
    35. .first-text .first-title {
    36. margin-bottom: 20px;
    37. font-size: 18px;
    38. }
    39. .first-text p {
    40. font-size: 15px;
    41. width: 90%;
    42. }

     需要注意的就是浮动样式的清除。你会发现所有设置了float的class后面都有多加一个clear-fix样式,包括:导航栏、左右分栏部分、6个小card部分。一个元素是可以同时添加多个class样式的。

    1. .clear-fix:after {
    2. content: '';
    3. display: block;
    4. clear: both;
    5. }

    后面复制的部分就不详细介绍了,

    HTML部分就是将图片(白色)和文字(蓝色)的顺序调换一下:

     看源码,样式有个地方需要注意下:

    1. /*第二部分结构是一样的,故直接复制了3分,将中间一个的左右顺序交换(图片和文字的div交换即可),*/
    2. /*为了更好地区别是三块,采用如下方式将偶数even那一块透明度修改为0.3,同理可修改奇数部分*/
    3. .first:nth-child(even) {
    4. background-color: rgba(255,255,255,0.3);
    5. }

    第三部分有一个大的标题+横线+内容,接着是6个相同的小方块,可以写一个方块后复制。

    HTML结构:

    样式如下:

    1. /*设置第三部分整体的样式:背景、透明度、文字颜色*/
    2. .part-three {
    3. background: #3f3965;
    4. opacity: 0.9;
    5. color: white;
    6. }
    7. /*设置大包裹的框架大小及样式:居中,占宽度的60%*/
    8. .three-wrap {
    9. margin: 0 auto;
    10. width: 60%;
    11. }
    12. .three-wrap .three-title {
    13. /*使用margin会留白,padding是由内向外撑开*/
    14. padding-top: 60px;
    15. }
    16. /*标题行居中,距离下方20px*/
    17. .three-title h2 {
    18. margin-bottom: 20px;
    19. text-align: center;
    20. }
    21. /*设置横线的样式:背景、宽度、居中*/
    22. .three-title .line {
    23. /*即使不设置高度,也有一个默认的高度显示*/
    24. height: 5px;
    25. background: #1a0973;
    26. width: 50%;
    27. margin: 0 auto;
    28. }
    29. /*设置three-title下的div的样式*/
    30. .three-title div {
    31. font-size: 15px;
    32. margin: 20px auto;
    33. }
    34. /*这里先设置一个card的样式,然后复制*/
    35. /*每个card里面有标题h3和文本p*/
    36. .card {
    37. min-height: 300px;
    38. margin-top: 20px;
    39. width: 50%;
    40. max-width: 461px;
    41. padding: 50px;
    42. float: left;
    43. /*以下两句解决盒子被挤下去的问题,让每个box都是独立的盒子,不被其他影响,兼容各种浏览器*/
    44. -webkit-box-sizing: border-box;
    45. -moz-box-sizing: border-box;
    46. }
    47. .card h3 {
    48. text-align: center;
    49. }
    50. .card p{
    51. font-size: 13px;
    52. }
    53. /*因为每个盒子的透明度不同,整体呈现由浅到深的渐变效果*/
    54. .card:nth-child(1) {
    55. background: rgba(0,0,0,0.05);
    56. }
    57. .card:nth-child(2) {
    58. background: rgba(0,0,0,0.1);
    59. }
    60. .card:nth-child(3) {
    61. background: rgba(0,0,0,0.15);
    62. }
    63. .card:nth-child(4) {
    64. background: rgba(0,0,0,0.2);
    65. }
    66. .card:nth-child(5) {
    67. background: rgba(0,0,0,0.25);
    68. }
    69. .card:nth-child(6) {
    70. background: rgba(0,0,0,0.3);
    71. }

    footer就不多说了,跟导航栏类似:

    HTML布局:

     样式也没啥说的:

    1. /*页尾常规样式*/
    2. .footer {
    3. background-color: #333;
    4. min-height: 200px;
    5. text-align: center;
    6. color: white;
    7. opacity: 0.9;
    8. }
    9. .share-group {
    10. display: block;
    11. margin: 0 auto;
    12. width: 1080px;
    13. padding: 45px;
    14. }
    15. .share-group li {
    16. display: inline-block;
    17. padding: 10px;
    18. }
    19. .footer ul {
    20. font-size: 18px;
    21. }
    22. .footer>div {
    23. font-size: 15px;
    24. }

    接下来解释右侧菜单栏,点击right-menu会弹出一条菜单选项,鼠标悬浮会高亮显示,同样使用ul:

     

    同时菜单出来的时候将主页面颜色淡出(加个遮盖),使菜单栏更明显。

    对比下左右图,右侧为菜单弹出,加上遮盖的效果,还是明显的哈,棒棒哒💯。

     遮罩:

    1. /*遮罩样式*/
    2. .mask {
    3. display: none;
    4. position: fixed;
    5. top: 0;
    6. bottom: 0;
    7. left: 0;
    8. right: 0;
    9. background: rgba(0,0,0,0.3);
    10. }

    菜单栏:

    1. /*右侧菜单栏*/
    2. .slider {
    3. background: #333;
    4. position: fixed;
    5. top: 0;
    6. /*这里之所以将位置设置为-300,是一开始将菜单栏放到页面外面隐藏起来*/
    7. /*当点击标签时再将其挪出来*/
    8. right: -300px;
    9. bottom: 0;
    10. width: 300px;
    11. /*挪出来的时间设置为0.3s,加个动画*/
    12. transition: 0.3s;
    13. }
    14. .slider ul li {
    15. margin-top: 30px;
    16. padding: 15px;
    17. }
    18. .slider ul li a {
    19. padding: 20px;
    20. color: white;
    21. width: 100%;
    22. display: inline-block;
    23. }
    24. /*鼠标悬浮时添加背景*/
    25. .slider ul li :hover {
    26. background: grey;
    27. }

    逻辑是这样的:

    1.点击菜单栏,遮罩打开,菜单栏移出;

    2.点击遮罩:菜单栏挪出页面外,关闭遮罩。

    1. // 2.点击侧边栏按钮,显示菜单栏
    2. $('.side-bar').click(function () {
    3. show_slider()
    4. })
    5. // 由于给整个页面添加了遮盖,且在点击侧边栏时,触发遮盖,故可以点击遮盖隐藏侧边栏
    6. $('.mask').click(function () {
    7. hide_slider()
    8. })
    9. // 菜单出现函数
    10. function show_slider() {
    11. $('.mask').fadeIn()
    12. // 因为原菜单栏的right设置的为-300,既可以隐藏到页面外部
    13. // 将right项设置为0,即可将侧边栏显示出来
    14. $('.slider').css('right',0)
    15. }
    16. // 菜单隐藏函数
    17. function hide_slider() {
    18. $('.mask').fadeOut()
    19. $('.slider').css('right',-300)
    20. }

    终于到最后的一个小动作了。

    由一个图片和一个文本组成: 

     先将样式设置好:

    1. /*返回顶部快捷键头*/
    2. .top {
    3. /*一开始设置none的原因是,网页加载出来时,不需要显示它,*/
    4. /*当滚动到一定位置时再取消隐藏*/
    5. display: none;
    6. width: 50px;
    7. height: 30px;
    8. position: fixed;
    9. right: 30px;
    10. bottom: 120px;
    11. }
    12. .top p,img {
    13. width: 100%;
    14. text-align: center;
    15. }

    调试的时候可以先将none取消,等调试好样式,写动作时再加上。

    1. // 3.回到顶部的动作
    2. $('.top').click(function () {
    3. // 点击TOP,返回至网页顶部
    4. $('body,html').animate({
    5. scrollTop: 0
    6. },300)
    7. })
    8. // 监听窗口,当距离顶部超过100时,才显示TOP按钮,否则不显示
    9. $(window).scroll(function () {
    10. if ($(window).scrollTop()>100) {
    11. // top的CSS中display设置的为none,即为隐藏状态
    12. // 当距离>100时,将其显示出来即可
    13. $('.top').css('display','block')
    14. } else {
    15. // 当距离过近时,再次将其隐藏
    16. $('.top').css('display','none')
    17. }
    18. })

    终于弄完了,快烦死了,图片自己找类似的,我懒得上传,路径自己改。

    源码部分

    HTML文件:

    1. <!DOCTYPE html>
    2. <html lang="en">
    3. <head>
    4. <meta charset="UTF-8">
    5. <title>Blog</title>
    6. <link rel="stylesheet" href="blog.css">
    7. <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
    8. <script src="blog.js"></script>
    9. </head>
    10. <body>
    11. <!--整个页面分成了三部分:头部、内容区、尾部-->
    12. <!--整个的包裹id定义为wrap,内容区的class定义为content,尾部的class定义为footer-->
    13. <!--紧跟着的mask为整个页面设置遮罩:当右侧菜单栏弹出时,整个页面加上遮罩,-->
    14. <!--slider为侧边栏菜单-->
    15. <!--top为右下角"回到顶部"的按钮-->
    16. <div id="wrap">
    17. <!-- 定义头部栏,例子中包括导航栏和第0个透明介绍部分-->
    18. <header class="header">
    19. <!-- 导航栏-->
    20. <nav>
    21. <ul class="nav-ul clear-fix">
    22. <li class="logo"><a href="#">博客</a></li>
    23. <!-- tips:这里使用右浮动,则最右边的标签卡写在最前面,可以保证浮动后最靠右-->
    24. <li class="side-bar"><a href="#">right-menu</a></li>
    25. <li><a href="#">blog</a><span></span></li>
    26. <li><a href="#">web</a><span></span></li>
    27. <li class="active"><a href="#">main</a><span></span></li>
    28. </ul>
    29. </nav>
    30. <!-- 定义第0个介绍部分,需要双层div包裹,外部div定义大小,方便内部div调整样式-->
    31. <div class="banner">
    32. <div class="inner">
    33. <!-- 从上到下依次为:横线、标题文字、横线、3行文本、按钮、"more"文字-->
    34. <div class="line"></div>
    35. <h1>Lily's Autumn</h1>
    36. <div class="line"></div>
    37. <p>E-mail:188888888@qq.com</p>
    38. <p>Tel:188 8888 8888</p>
    39. <p>Addr:Longhua,Shenzhen,China</p>
    40. <button>click me</button>
    41. <div class="more">more</div>
    42. </div>
    43. </div>
    44. </header>
    45. <div class="content">
    46. <section class="part-one">
    47. <!-- 设置一个外部的包裹wraper-->
    48. <!-- 内容如下:-->
    49. <!-- 一行标题文字、一行文本、一条线、再一段文字和图标-->
    50. <div class="wraper">
    51. <h2>Spring Flowers and Autumn Moon</h2>
    52. <div class="first-title">Right I die. My life before my eyes.</div>
    53. <div class="line"></div>
    54. <p>
    55. As I was hang there, I see wonderland, I don't really see much of anything.
    56. But I see you. That's crazy.
    57. </p>
    58. <!-- 图标部分-->
    59. <div class="icon">
    60. <span class="item"><img src="./img/钻石.svg" alt=""></span>
    61. <span class="item"><img src="./img/程序.svg" alt=""></span>
    62. <span class="item"><img src="./img/爱心.svg" alt=""></span>
    63. </div>
    64. </div>
    65. </section>
    66. <section class="part-two">
    67. <!-- 复制了3份-->
    68. <!-- 每一份都有一侧图片加一侧文字-->
    69. <div class="first clear-fix">
    70. <div class="first-left">
    71. <img src="./img/sunset.jpeg" alt="">
    72. </div>
    73. <div class="first-text">
    74. <h2>Missing is A Kind Of Sick</h2>
    75. <div class="first-title">
    76. Love once begun,will never end.
    77. </div>
    78. <p>The moon is still so bright;
    79. Beyond the hills the lamp sheds the same light,
    80. The sky besprinkled with star upon star, But I do not know where you are.</p>
    81. </div>
    82. </div>
    83. <div class="first clear-fix">
    84. <div class="first-text">
    85. <h2>Missing is A Kind Of Sick</h2>
    86. <div class="first-title">
    87. Love once begun,will never end.
    88. </div>
    89. <p>The moon is still so bright;
    90. Beyond the hills the lamp sheds the same light,
    91. The sky besprinkled with star upon star, But I do not know where you are.</p>
    92. </div>
    93. <div class="first-left text-right">
    94. <img src="./img/mountain.jpeg" alt="">
    95. </div>
    96. </div>
    97. <div class="first clear-fix">
    98. <div class="first-left">
    99. <img src="./img/pic03.jpg" alt="">
    100. </div>
    101. <div class="first-text">
    102. <h2>Missing is A Kind Of Sick</h2>
    103. <div class="first-title">
    104. Love once begun,will never end.
    105. </div>
    106. <p>The moon is still so bright;
    107. Beyond the hills the lamp sheds the same light,
    108. The sky besprinkled with star upon star, But I do not know where you are.</p>
    109. </div>
    110. </div>
    111. </section>
    112. <!-- 第三部分有一个大的标题+横线+内容,接着是6个相同的小方块,可以写一个方块后复制-->
    113. <section class="part-three">
    114. <!-- 还是一样,外面添加一个包裹-->
    115. <div class="three-wrap">
    116. <!-- 大的标题+横线+内容-->
    117. <div class="three-title">
    118. <h2>Lang Tao Sha</h2>
    119. <div class="line"></div>
    120. <div>Easy to leave it but hard to see it again,With flowers fallen on the waves spring's gone away;So has the paradise of yesterday.
    121. Easy to leave it but hard to see it again,With flowers fallen on the waves spring's gone away;So has the paradise of yesterday.</div>
    122. </div>
    123. <!-- 6个相同的小方块-->
    124. <div class="card-group clear-fix">
    125. <div class="card">
    126. <h3>believe</h3>
    127. <p>The moon is still so bright; Beyond the hills the lamp sheds the same light,
    128. The sky besprinkled with star upon star, But I do not know where you are.</p>
    129. </div>
    130. <div class="card">
    131. <h3>believe</h3>
    132. <p>The moon is still so bright; Beyond the hills the lamp sheds the same light,
    133. The sky besprinkled with star upon star, But I do not know where you are.</p>
    134. </div>
    135. <div class="card">
    136. <h3>believe</h3>
    137. <p>The moon is still so bright; Beyond the hills the lamp sheds the same light, The sky besprinkled with star upon star, But I do not know where you are.</p>
    138. </div>
    139. <div class="card">
    140. <h3>believe</h3>
    141. <p>The moon is still so bright; Beyond the hills the lamp sheds the same light, The sky besprinkled with star upon star, But I do not know where you are.</p>
    142. </div>
    143. <div class="card">
    144. <h3>believe</h3>
    145. <p>The moon is still so bright; Beyond the hills the lamp sheds the same light, The sky besprinkled with star upon star, But I do not know where you are.</p>
    146. </div>
    147. <div class="card">
    148. <h3>believe</h3>
    149. <p>The moon is still so bright; Beyond the hills the lamp sheds the same light, The sky besprinkled with star upon star, But I do not know where you are.</p>
    150. </div>
    151. </div>
    152. </div>
    153. </section>
    154. </div>
    155. <div class="footer">
    156. <ul class="share-group">
    157. <li>mon</li>
    158. <li>tuey</li>
    159. <li>wed</li>
    160. <li>thur</li>
    161. <li>fri</li>
    162. </ul>
    163. <div>@lily's autumn-2022</div>
    164. </div>
    165. <div class="mask"></div>
    166. <div class="slider">
    167. <ul>
    168. <li><a href="#">111</a></li>
    169. <li><a href="#">222</a></li>
    170. <li><a href="#">333</a></li>
    171. <li><a href="#">444</a></li>
    172. <li><a href="#">555</a></li>
    173. </ul>
    174. </div>
    175. <div class="top">
    176. <a href="#">
    177. <img src="./img/向上箭头.svg" alt="">
    178. <p>TOP</p>
    179. </a>
    180. </div>
    181. </div>
    182. </body>
    183. </html>

    CSS文件:

    1. * {
    2. margin: 0;
    3. padding: 0;
    4. }
    5. em,i {
    6. font-style: normal;
    7. }
    8. /*去除列表前的小黑点*/
    9. li {
    10. list-style: none;
    11. }
    12. img {
    13. border: 0;
    14. vertical-align: middle;
    15. }
    16. button {
    17. cursor: pointer;
    18. }
    19. a {
    20. color: black;
    21. /*去除下划线*/
    22. text-decoration: none;
    23. }
    24. a:hover {
    25. color: #c81623;
    26. }
    27. /*以上为清除浏览器设置,并给定一下常见的样式*/
    28. .header {
    29. /*居中*/
    30. /*给整个头部设置背景和透明度*/
    31. line-height: 50px;
    32. background: rgba(0,0,0,0.4);
    33. }
    34. /*给header的导航栏设置背景色*/
    35. .header nav {
    36. background-color: gray;
    37. height: 50px;
    38. }
    39. /*导航栏向右浮动*/
    40. nav ul li {
    41. float: right;
    42. margin-right: 30px;
    43. }
    44. /*整个页面最外层的包裹*/
    45. #wrap {
    46. /*背景使用banner的图片,不重复的显示,居中,固定在页面上,就可以不随滚动条而变化*/
    47. /*同时设置整个页面的文字*/
    48. background: url("./img/banner.jpeg") no-repeat;
    49. background-position: center center;
    50. background-attachment: fixed;
    51. background-size: cover;
    52. font-family: "Microsoft Yahei","Hiragino Sans GB","Helvetica Neue",Helvetica,tahoma,arial,"WenQuanYi Micro Hei",Verdana,sans-serif,"\5B8B\4F53";
    53. }
    54. /*logo单独设置靠左的li元素,可以单独添加样式*/
    55. .logo {
    56. float: left;
    57. margin-left: 40px;
    58. }
    59. /*class为logo的li元素下的a标签样式----即"博客"二字*/
    60. .logo a {
    61. font-size: 20px;
    62. color: white;
    63. font-weight: 700;
    64. /*文字中间的空隙*/
    65. letter-spacing: 2px;
    66. }
    67. .banner {
    68. height: 600px;
    69. }
    70. /*设置第0部分的内容样式*/
    71. .banner .inner {
    72. /*全部使用白色,居中对齐,并设置一个最大的宽度*/
    73. color: white;
    74. text-align: center;
    75. margin: 0 auto;
    76. max-width: 400px;
    77. /*设置relative就会随着鼠标上下滚动,fixed就会固定在页面上,跟背景图一样*/
    78. position: relative;
    79. top:160px;
    80. }
    81. /*设置文本上下的线条的样式*/
    82. .line {
    83. /*这个宽度为父元素inner的宽度400px*/
    84. width: 100%;
    85. /*设置了一个高度为2px的白色背景作为线条*/
    86. height: 5px;
    87. background: white;
    88. margin: 10px 10px;
    89. }
    90. /*inner里面的p元素设置样式*/
    91. .banner .inner p {
    92. line-height: 30px;
    93. font-size: 18px;
    94. letter-spacing: 1px;
    95. }
    96. /*给按钮设置样式*/
    97. .banner .inner button {
    98. margin-top: 20px;
    99. /*使用margin会留白,padding会带着背景色一起撑开*/
    100. padding: 10px 20px;
    101. background: #e85e17;
    102. /*设置圆角*/
    103. border-radius: 5px;
    104. /*去除按钮的边框*/
    105. border: none;
    106. color: white;
    107. /*去掉按钮点击时的边框*/
    108. outline: none;
    109. }
    110. /*鼠标悬浮到按钮上时,按钮的动作*/
    111. .banner .inner button:hover {
    112. /*鼠标经过时,开始旋转720°动画,并放大2倍,持续时间2s*/
    113. transform: rotate(720deg) scale(2);
    114. transition: 2s;
    115. }
    116. .banner .inner .more {
    117. margin-top: 140px;
    118. }
    119. /*中间的内容整个设置为透明度0.9,保证滚动条滑动时,主背景可以透出来,*/
    120. /*同时主背景用的是fixed,不随滚动条而移动*/
    121. .content{
    122. opacity: .9;
    123. }
    124. /*设置第一部分整体的样式*/
    125. .part-one {
    126. text-align: center;
    127. color: white;
    128. background: rgba(67,178,165,1);
    129. padding-top: 65px;
    130. opacity: 0.95;
    131. }
    132. .wraper {
    133. /*margin这样设置可以居中*/
    134. margin: 0 auto;
    135. max-width: 1080px;
    136. }
    137. .wraper h2 {
    138. padding: 15px 0;
    139. }
    140. .wraper .line {
    141. /*居中可以这样设置margin*/
    142. margin: 15px auto;
    143. width: 40%;
    144. height: 5px;
    145. background-color: #666666;
    146. }
    147. .wraper p {
    148. margin: 25px 0;
    149. font-size: 18px;
    150. }
    151. .icon {
    152. margin: 30px auto;
    153. margin-bottom: 0;
    154. padding-bottom: 30px;
    155. }
    156. /*给3个图标设置边框*/
    157. /*宽度2px实线、绿色,80*80px,旋转45°*/
    158. .icon .item{
    159. border: 2px solid green;
    160. /*因为span不可以调整宽高,所以先将display设置成如下*/
    161. display: inline-block;
    162. height: 80px;
    163. width: 80px;
    164. margin-right: 50px;
    165. transform: rotate(45deg);
    166. }
    167. /*设置宽和高为100%,适应父元素item的宽和高,就不会超出item的border,
    168. 同时img继承了item的旋转,需要纠正回来*/
    169. .icon .item img{
    170. width: 100%;
    171. height: 100%;
    172. transform: rotate(-45deg);
    173. }
    174. /*给整个第二部分添加背景色*/
    175. .part-two {
    176. background-color: rgb(33,41,50);
    177. }
    178. .first .text-right {
    179. float: right;
    180. }
    181. .first-left {
    182. width: 41%;
    183. }
    184. .first-left img {
    185. width: 100%;
    186. }
    187. /*表示first标签的第一代子标签div*/
    188. .first>div {
    189. float: left;
    190. }
    191. /*设置浮动之后,父元素first就没有了高度,需要清除浮动,用伪元素做以下处理*/
    192. .clear-fix:after {
    193. content: '';
    194. display: block;
    195. clear: both;
    196. }
    197. .first-text {
    198. position: relative;
    199. top: 68px;
    200. left: 50px;
    201. width: 55%;
    202. color: white;
    203. }
    204. .first-text h2 {
    205. font-size: 24px;
    206. margin-bottom: 10px;
    207. }
    208. .first-text .first-title {
    209. margin-bottom: 20px;
    210. font-size: 18px;
    211. }
    212. .first-text p {
    213. font-size: 15px;
    214. width: 90%;
    215. }
    216. /*第二部分结构是一样的,故直接复制了3分,将中间一个的左右顺序交换(图片和文字的div交换即可),*/
    217. /*为了更好地区别是三块,采用如下方式将偶数even那一块透明度修改为0.3,同理可修改奇数部分*/
    218. .first:nth-child(even) {
    219. background-color: rgba(255,255,255,0.3);
    220. }
    221. /*设置第三部分整体的样式:背景、透明度、文字颜色*/
    222. .part-three {
    223. background: #3f3965;
    224. opacity: 0.9;
    225. color: white;
    226. }
    227. /*设置大包裹的框架大小及样式:居中,占宽度的60%*/
    228. .three-wrap {
    229. margin: 0 auto;
    230. width: 60%;
    231. }
    232. .three-wrap .three-title {
    233. /*使用margin会留白,padding是由内向外撑开*/
    234. padding-top: 60px;
    235. }
    236. /*标题行居中,距离下方20px*/
    237. .three-title h2 {
    238. margin-bottom: 20px;
    239. text-align: center;
    240. }
    241. /*设置横线的样式:背景、宽度、居中*/
    242. .three-title .line {
    243. /*即使不设置高度,也有一个默认的高度显示*/
    244. height: 5px;
    245. background: #1a0973;
    246. width: 50%;
    247. margin: 0 auto;
    248. }
    249. /*设置three-title下的div的样式*/
    250. .three-title div {
    251. font-size: 15px;
    252. margin: 20px auto;
    253. }
    254. /*这里先设置一个card的样式,然后复制*/
    255. /*每个card里面有标题h3和文本p*/
    256. .card {
    257. min-height: 300px;
    258. width: 50%;
    259. /*最大值可以打开浏览器调试,自己看一下那个值合适,就改一下*/
    260. max-width: 461px;
    261. padding: 50px;
    262. float: left;
    263. /*以下两句解决盒子被挤下去的问题,让每个box都是独立的盒子,不被其他影响,兼容各种浏览器*/
    264. -webkit-box-sizing: border-box;
    265. -moz-box-sizing: border-box;
    266. }
    267. /*单独设置标题居中,文本不需要*/
    268. .card h3 {
    269. text-align: center;
    270. }
    271. .card p{
    272. font-size: 13px;
    273. }
    274. /*因为每个盒子的透明度不同,整体呈现由浅到深的渐变效果*/
    275. .card:nth-child(1) {
    276. background: rgba(0,0,0,0.05);
    277. }
    278. .card:nth-child(2) {
    279. background: rgba(0,0,0,0.1);
    280. }
    281. .card:nth-child(3) {
    282. background: rgba(0,0,0,0.15);
    283. }
    284. .card:nth-child(4) {
    285. background: rgba(0,0,0,0.2);
    286. }
    287. .card:nth-child(5) {
    288. background: rgba(0,0,0,0.25);
    289. }
    290. .card:nth-child(6) {
    291. background: rgba(0,0,0,0.3);
    292. }
    293. /*页尾常规样式*/
    294. .footer {
    295. background-color: #333;
    296. min-height: 200px;
    297. text-align: center;
    298. color: white;
    299. opacity: 0.9;
    300. }
    301. .share-group {
    302. display: block;
    303. margin: 0 auto;
    304. width: 1080px;
    305. padding: 45px;
    306. }
    307. .share-group li {
    308. display: inline-block;
    309. padding: 10px;
    310. }
    311. .footer ul {
    312. font-size: 18px;
    313. }
    314. .footer>div {
    315. font-size: 15px;
    316. }
    317. .active {
    318. position: relative;
    319. }
    320. /*同样设置了4px高度的白色背景框作为短横线*/
    321. /*因为4个标签中main、web、blog都添加了span标签*/
    322. /*right-menu没有添加*/
    323. .active span {
    324. position: absolute;
    325. height: 4px;
    326. background: white;
    327. bottom: 5px;
    328. left: 0;
    329. width: 100%;
    330. }
    331. /*遮罩样式*/
    332. .mask {
    333. display: none;
    334. position: fixed;
    335. top: 0;
    336. bottom: 0;
    337. left: 0;
    338. right: 0;
    339. background: rgba(0,0,0,0.3);
    340. }
    341. /*右侧菜单栏*/
    342. .slider {
    343. background: #333;
    344. position: fixed;
    345. top: 0;
    346. /*这里之所以将位置设置为-300,是一开始将菜单栏放到页面外面隐藏起来*/
    347. /*当点击标签时再将其挪出来*/
    348. right: -300px;
    349. bottom: 0;
    350. width: 300px;
    351. /*挪出来的时间设置为0.3s,加个动画*/
    352. transition: 0.3s;
    353. }
    354. .slider ul li {
    355. margin-top: 30px;
    356. padding: 15px;
    357. }
    358. .slider ul li a {
    359. padding: 20px;
    360. color: white;
    361. width: 100%;
    362. display: inline-block;
    363. }
    364. /*鼠标悬浮时添加背景*/
    365. .slider ul li :hover {
    366. background: grey;
    367. }
    368. /*返回顶部快捷键头*/
    369. .top {
    370. /*一开始设置none的原因是,网页加载出来时,不需要显示它,*/
    371. /*当滚动到一定位置时再取消隐藏*/
    372. display: none;
    373. width: 50px;
    374. height: 30px;
    375. position: fixed;
    376. right: 30px;
    377. bottom: 120px;
    378. }
    379. .top p,img {
    380. width: 100%;
    381. text-align: center;
    382. }

    JS文件:

    1. $(function () {
    2. // 本例中只有3个动作,
    3. // 一是鼠标悬浮在标签栏时,显示白色加粗的下划线;
    4. // 二是点击右侧菜单栏有弹出菜单;
    5. // 三是点击回到顶部的按钮;
    6. // 1.鼠标移到标签上时,当前标签有一个白色的下划线,其他的兄弟标签样式取消
    7. $('.nav-ul li').click(function () {
    8. $(this).addClass('active')
    9. $(this).siblings().removeClass('active')
    10. })
    11. // 2.点击侧边栏按钮,显示菜单栏
    12. $('.side-bar').click(function () {
    13. show_slider()
    14. })
    15. // 由于给整个页面添加了遮盖,且在点击侧边栏时,触发遮盖,故可以点击遮盖隐藏侧边栏
    16. $('.mask').click(function () {
    17. hide_slider()
    18. })
    19. // 菜单出现函数
    20. function show_slider() {
    21. $('.mask').fadeIn()
    22. // 因为原菜单栏的right设置的为-300,既可以隐藏到页面外部
    23. // 将right项设置为0,即可将侧边栏显示出来
    24. $('.slider').css('right',0)
    25. }
    26. // 菜单隐藏函数
    27. function hide_slider() {
    28. $('.mask').fadeOut()
    29. $('.slider').css('right',-300)
    30. }
    31. // 3.回到顶部的动作
    32. $('.top').click(function () {
    33. // 点击TOP,返回至网页顶部
    34. $('body,html').animate({
    35. scrollTop: 0
    36. },300)
    37. })
    38. // 监听窗口,当距离顶部超过100时,才显示TOP按钮,否则不显示
    39. $(window).scroll(function () {
    40. if ($(window).scrollTop()>100) {
    41. // top的CSS中display设置的为none,即为隐藏状态
    42. // 当距离>100时,将其显示出来即可
    43. $('.top').css('display','block')
    44. } else {
    45. // 当距离过近时,再次将其隐藏
    46. $('.top').css('display','none')
    47. }
    48. })
    49. })

  • 相关阅读:
    OpenAI视频生成Sora技术简析
    java-php-net-python-房产交易资金管理系统计算机毕业设计程序
    SQL Injection
    Hadoop面试重点
    怎样用Python识别条形码?
    【KCC@南京】KCC南京"数字经济-开源行"
    Maven 使用教程(三)
    浅谈微服务架构中实现单点登录
    matlab⾼级绘图时间距离图像
    找准边界,吃定安全 | 串联边界设备协同,便捷运营思维让安全更有效
  • 原文地址:https://blog.csdn.net/qq_34285232/article/details/125413937