响应式网页设计实战

4 篇文章 1 订阅

1.设计思路

在本响应式网页设计中,通过媒体查询 @media 规则,使网页自适应不同浏览设备的屏幕宽度。网页中 <header> 位于网页顶端, <footer> 位于网页底端, 二者不论在哪一种情况下,其宽度总是为浏览窗口宽度的100%,而 <nav><article><aside> 根据不同浏览窗口的大小自适应其宽度,并以不同方式布局:

  1. 当浏览窗口宽度大于768px时,<nav> 位于网页左侧 、<article> 位于网页中间,<aside> 位于网页右侧,适应桌面端浏览窗口;
  2. 当浏览窗口宽度大于480px小于768px时,<nav><article> 位于网页上方并由左至右排列 、<aside> 位于网页下方,适应ipad端浏览窗口;
  3. 当浏览窗口宽度小于480px时,<nav><article><aside> 由上至下依次排列,适应手机端浏览窗口。

2.网页截图

桌面端:

在这里插入图片描述

ipad端:

在这里插入图片描述

手机端:

在这里插入图片描述
在这里插入图片描述

3.代码实现

test.html
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>test</title>
    <link rel="stylesheet" type="text/css" href="test.css">

    <!-- 通过JS,动态地为footer添加类fixed-bottom -->
    <script src="http://libs.baidu.com/jquery/1.7.2/jquery.min.js"></script>
    <script type="text/javascript">
      $(function(){
          function footerPosition(){
              $("footer").removeClass("fixed-bottom");
              var contentHeight = document.body.scrollHeight,//网页正文全文高度
                  winHeight = window.innerHeight;//可视窗口高度,不包括浏览器顶部工具栏
              if(!(contentHeight > winHeight)){
                  //当网页正文高度小于可视窗口高度时,为footer添加类fixed-bottom
                  $("footer").addClass("fixed-bottom");
              } else {
                  $("footer").removeClass("fixed-bottom");
              }
          }
          footerPosition();
          $(window).resize(footerPosition);
      });
    </script>

</head>
<body>
    <header>
        <h1>我的网页</h1>
        <p>——这是一个同时适应桌面端/ipad/手机的响应式网页</p>
    </header>

    <div class="row">
        <nav class="col-25 col-s-25 menu">
            <ul>
                <li>个人简介</li>
                <li>我的收藏</li>
                <li>联系方式</li>
                <li>历史记录</li>
                <li>关于我们</li>
                <li>更多功能</li>
            </ul>
        </nav>
        <article class="col-50 col-s-75 article">
            <h1>为什么我们需要开源的系统芯片</h1>
            <p>
                不再使用的芯片区域是一件大事,因为构建芯片可不像搭乐高积木那般简单,它更像是雕刻家刻在大理石快上的雕塑,因此添加电路的难度远远高于关闭电路。增加一条电路仅制作新的掩膜就大约需要花费100万美元,同时还会导致项目延迟70天(大约10万人时的额外工作)。而在正确计划的情况下,关闭一条电路非常简单,只需要修改代码,或者针对某个掩模层进行轻微改动,只需要花费大约1万美元以及几天的延迟(假设晶圆尚处于中期阶段,很容易进行这样的改动)。
            </p>
            <img src="https://img-blog.csdnimg.cn/2020111709205454.png">
        </article>
        <div class="col-25 col-s-100">
            <aside>
                <h2>数据结构与算法</h2>
                <h2>计算机网络</h2>
                <h2>操作系统</h2>
                <h2>计算机组成原理</h2>
                <h2>计算机系统结构</h2>
                <h2>数据库原理</h2>
            </aside>
        </div>
    </div>
    
    <footer>
        <p>footer@2020</p>
    </footer>
</body>
</html>
test.css
* {
    /* 初始化 取消页面的内外边距 */
	padding: 0;
	margin: 0;
	/* 盒子模型 */
	box-sizing: border-box;
}

/*在整个row下面增加空行内容*/
.row::after {
    content: "";
    clear: left;
    display: table;
}

[class*="col-"] {
    float: left;
    padding: 15px;
    width: 100%;
}

/*默认是手机端 0-480px*/

/*ipad端 481px-768px*/
@media only screen and (min-width: 481px) {
    .col-s-25 {width: 25%;}
    .col-s-75 {width: 75%;}
    .col-s-100 {width: 100%;}
}

/*桌面端 769px+*/
@media only screen and (min-width: 769px) {
    .col-25 {width: 25%;}
    .col-50 {width: 50%;}
}

html {
    font-family: Arial, Helvetica, sans-serif;
}

header {
    background-color: darkblue;
    color: white;
    padding: 15px;
    text-align: center;
}

header p {
    margin-top: 15px;
}

.menu ul {
    margin: 0;
    padding: 0;
    list-style-type: none;
}

.menu li {
    background-color: deepskyblue;
    color: white;
    padding: 10px;
    margin-bottom: 15px;
    box-shadow: gray 1px 2px 2px;
    transition-property: all;
	transition-duration: .5s;
}

.menu li:hover {
    background-color: darkblue;
}

.article {
    background-color: wheat;
    padding: 15px;
    margin: 15px 0;
}

.article p {
    padding: 15px;
}

aside {
    background-color: deepskyblue;
    color: white;
    padding: 15px;
    text-align: center;
    font-size: 15px;
    box-shadow: gray 3px 3px 3px;
}

aside h2 {
    padding: 10px;
}

footer {
    background-color: lightgray;
    color: darkblue;
    text-align: center;
    font-size: 18px;
    padding: 15px;
    width: 100%;
}

img {
    padding: 15px;
    width: 100%;
    height: auto;
}

/*动态地为footer添加类fixed-bottom*/
.fixed-bottom {
    position: fixed;
    bottom: 0;
    width: 100%;
}
  • 15
    点赞
  • 62
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
当然,我可以帮你写一份响应网页设计项目实训说明书。下面是一个基本的模板,你可以根据需要进行修改和调整。 # 响应网页设计项目实训说明书 ## 项目概述 本项目旨在让学生通过实际操作,掌握响应网页设计的基本概念、技术和工具,了解并应用HTML、CSS、JavaScript等相关技术,设计出具有响应布局的网页。 ## 项目目标 - 掌握响应网页设计的基本概念和原理 - 熟悉并掌握HTML、CSS、JavaScript等相关技术 - 实现具有响应布局的网页设计 - 了解常用的响应设计框架和工具 ## 项目要求 ### 1. 网页设计需求 设计一个具有响应布局的网页,要求包括以下内容: - 顶部导航栏 - 主体内容区域 - 底部版权信息 ### 2. 技术要求 - 使用HTML5、CSS3、JavaScript等技术实现页面布局和交互效果 - 使用响应设计框架Bootstrap或者Foundation等进行布局设计 - 使用jQuery等JavaScript库实现交互效果 - 适配不同屏幕尺寸和设备,实现响应布局 ### 3. 项目步骤 - 设计网页结构和布局 - 利用HTML和CSS实现网页和排版 - 使用响应设计框架实现网页布局 - 使用JavaScript实现交互效果 - 调试和测试网页,确保在不同设备上都能正常显示和使用 ## 项目评分标准 - 网页设计的美观程度(20分) - 网页设计的布局和排版(20分) - 网页交互效果的实现(20分) - 网页响应布局(20分) - 代码的质量和规范性(20分) ## 参考资料 - 《HTML5与CSS3基础教程》(第8版),作者:Terry Felke-Morris - 《Bootstrap实战》(第2版),作者:Jake Spurlock、Mason Andrews、Syed Fazle Rahman - 《JavaScript高级程序设计》(第3版),作者:Nicholas C. Zakas 希望这份说明书能够对你有所帮助,如果还有其他问题,可以随时问我。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值