Html/CSS开发基础(CSS布局练习)

谁借莪1个温暖的怀抱¢ 2023-07-25 14:02 72阅读 0赞

Html/CSS.基础入门.Html/CSS开发基础.CSS布局练习

  • 0 目录
  • 1 Html/CSS
    • 1.1 CSS布局练习
      • 1.1.1 题目
      • 1.1.2 源码
      • 1.1.3目录结构
      • 1.1.4 效果展示
  • 2 下一章

0 目录

1 Html/CSS

1.1 CSS布局练习

1.1.1 题目

用DIV+CSS实现如下的布局与网页设计。
在这里插入图片描述
具体要求如下:
1、页面的宽度占屏幕显示区域的60%,页面的高度为600px。标题区的边框为黑色,标题区的文字内容为“欢迎光临我的网站”,标题为2级标题。导航区的边框颜色为红色,其余所有的区域的边框颜色为灰色。尾注部分的高度为标题区高度的一半。
2、导航区中添加5个链接:个人信息、学习经历、兴趣爱好、奖惩情况和我的相册。分别建立5个网页与其对应。点击链接后可以进入浏览该网页,每个网页中都需要实现返回到主页的功能(通过返回链接或按钮实现)。
3、登录区中包含用户名、密码以及两个用于输入的文本框,一个登录按钮和取消按钮。无须为按钮编写事件代码。内容区2的内容设计为一个投票区,标题为“你对我的网站感觉如何?”,用一组单选按钮表示非常喜欢、喜欢、一般和不喜欢四个选项。
4、内容区1的内容中为文本,内容区3的内容为一个图片(内容自己设定)。内容区4为文本内容。
5、标题区与导航区的间距为5px,导航区与登录区、内容区1的间距为5px。登录区与内容区1间距为8px。登录区与内容区2的间距为5px。内容区2与内容区3之间间距也为8px。内容区3和内容区4间距为8px。尾注区与上面的部分的间距为5px。
【操作提示】:可以先在Dreamweaver环境中建立CSS样式文件和主要的页面设计,如果本机上已经安装了IIS组件,则可以在本机上查看自己的网站效果。如果没有安装IIS,则可以在Visual
Studio环境中查看网页设计效果。通过新建空网站,然后添加现有项的方式把在Dreamweaver中建好的页面添加到自己建的网站中。

1.1.2 源码

1CSS样式

  1. * {
  2. padding: 0;
  3. margin: 0;
  4. }
  5. .container {
  6. width: 60%;
  7. height: 600px;
  8. text-align: center;
  9. position: relative;
  10. left: 20%;
  11. }
  12. .container .header {
  13. width: calc(100% - 2px);
  14. height: 100px;
  15. line-height: 80px;
  16. border: 1px solid black;
  17. overflow: hidden;
  18. }
  19. .container .nav {
  20. margin-top: 5px;
  21. width: calc(100% - 2px);
  22. height: 50px;
  23. line-height: 50px;
  24. border: 1px solid red;
  25. overflow: hidden;
  26. }
  27. .container .nav a {
  28. text-decoration: none;
  29. display: block;
  30. width: 20%;
  31. float: left;
  32. color: #1e1bd1;
  33. }
  34. .container .nav a:hover {
  35. color: #3781d6;
  36. }
  37. .container ul {
  38. width: 100%;
  39. list-style-type: none;
  40. }
  41. .container ul li {
  42. float: left;
  43. margin-top: 5px;
  44. height: 150px;
  45. border: 1px solid gray;
  46. overflow: hidden;
  47. }
  48. .container ul li textarea {
  49. width: calc(100% - 2px);
  50. height: calc(100% - 2px);
  51. border: 0;
  52. margin-top: 1px;
  53. }
  54. .container ul li:nth-child(1) {
  55. width: calc(35% - 2px);
  56. position: relative;
  57. }
  58. .container ul li:nth-child(1)
  59. .login_container {
  60. position: absolute;
  61. height: 100px;
  62. top: 100px;
  63. margin-top: -75px;
  64. }
  65. .container ul li:nth-child(1)
  66. .login_container .login {
  67. width: 100%;
  68. height: 30px;
  69. margin-top: 5px;
  70. }
  71. .container ul li:nth-child(1)
  72. .login_container .login span {
  73. display: block;
  74. width: 36px;
  75. font-size: 12px;
  76. height: 30px;
  77. float: left;
  78. line-height: 30px;
  79. }
  80. .container ul li:nth-child(1)
  81. .login_container .login input {
  82. width: calc(100% - 44px);
  83. height: 25px;
  84. float: left;
  85. }
  86. .container ul li:nth-child(1)
  87. .login_container .login_btn {
  88. width: 100%;
  89. height: 30px;
  90. margin-top: 5px;
  91. }
  92. .container ul li:nth-child(1)
  93. .login_container .login_btn button {
  94. height: 22px;
  95. margin-left: 5px;
  96. }
  97. .container ul li:nth-child(2) {
  98. width: calc(65% - 10px);
  99. margin-left: 8px;
  100. }
  101. .container ul li:nth-child(3) {
  102. width: calc(35% - 2px);
  103. }
  104. .container ul li:nth-child(3)
  105. div:nth-child(2) {
  106. margin-top: 10px;
  107. }
  108. .container ul li:nth-child(3) div
  109. {
  110. width: 100%;
  111. height: 25px;
  112. }
  113. .container ul li:nth-child(3) div
  114. input {
  115. float: left;
  116. margin-left: 10%;
  117. margin-top: 4px;
  118. }
  119. .container ul li:nth-child(3) div
  120. span {
  121. float: left;
  122. margin-left: 5px;
  123. }
  124. .container ul li:nth-child(4) {
  125. margin-left: 8px;
  126. width: calc(35% - 10px);
  127. }
  128. .container ul li:nth-child(5) {
  129. margin-left: 8px;
  130. width: calc(30% - 10px);
  131. }
  132. .container .footer {
  133. position: relative;
  134. top: 5px;
  135. clear: both;
  136. line-height: 50px;
  137. width: 100%;
  138. height: 50px;
  139. border: 1px solid gray;
  140. }

2HTML元素及其标记代码

  1. <div class="container">
  2. <div class="header">
  3. <h2>欢迎光临我的网站</h2>
  4. </div>
  5. <div class="nav">
  6. <a href="myInfo.html">个人信息</a>
  7. <a href="study.html">学习经历</a>
  8. <a href="hobby.html">兴趣爱好</a>
  9. <a href="rewards.html">奖惩情况</a>
  10. <a href="myPhotos.html">我的相册</a>
  11. </div>
  12. <div class="content">
  13. <ul>
  14. <li>
  15. <div class="login_container">
  16. <div class="login">
  17. <span>用户名</span>
  18. <input type="text">
  19. </div>
  20. <div class="login">
  21. <span>密码</span>
  22. <input type="password">
  23. </div>
  24. <div class="login_btn">
  25. <button>登录</button>
  26. <button>取消</button>
  27. </div>
  28. </div>
  29. </li>
  30. <li>
  31. <textarea name="" id="" cols="30" rows="10"></textarea>
  32. </li>
  33. <li>
  34. <span>你对我的网站感觉如何?</span>
  35. <div>
  36. <input type="radio">
  37. <span>非常喜欢</span>
  38. </div>
  39. <div>
  40. <input type="radio">
  41. <span>喜欢</span>
  42. </div>
  43. <div>
  44. <input type="radio">
  45. <span>一般</span>
  46. </div>
  47. <div>
  48. <input type="radio">
  49. <span>不喜欢</span>
  50. </div>
  51. </li>
  52. <li>
  53. <img src="./test.jpg" alt="图片">
  54. </li>
  55. <li>
  56. <textarea name="" id="" cols="30" rows="10"></textarea>
  57. </li>
  58. </ul>
  59. </div>
  60. <div class="footer">
  61. 尾注区
  62. </div>
  63. </div>

1.1.3目录结构

在这里插入图片描述

1.1.4 效果展示

在这里插入图片描述

2 下一章

博客地址:

发表评论

表情:
评论列表 (有 0 条评论,72人围观)

还没有评论,来说两句吧...

相关阅读

    相关 7 css基础布局

      上一章我们学习了CSS的引用,让我们可以将CSS运用在我们的HTML文档上,那么我们这一次就来实际的运用它。 这一次将介绍CSS的几个布局方式: 1. 左右布