前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >CSS实现全屏切换效果

CSS实现全屏切换效果

作者头像
小胖
发布2018-06-27 17:52:28
2.7K0
发布2018-06-27 17:52:28
举报

如何通过CSS使div实现全屏效果

全屏要素

  • 全屏的元素及其父元素都要设置height:100%
  • 将html、body标签设置height:100%

(注:height:100%是跟随其父元素高度变化而变化的)

1.图片横排展示全屏切换效果

代码语言:javascript
复制
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Document</title>
  <style>
    *{
      padding: 0;
      margin: 0;
    }
    html,body{
      height: 100%;
    }
    #container,.sections,.section{
      height: 100%;
    }
    #section0,
    #section1,
    #section2,
    #section3{
      background-color: #000;
      background-size: cover;
      /*让背景图片在容器中居中*/
      background-position: 50% 50%;
      text-align: center;
      color: white;
    }
    #section0{
      background-image: url("http://ossweb-img.qq.com/images/lol/web201310/skin/big86000.jpg");
    }
    #section1{
      background-image: url("http://ossweb-img.qq.com/images/lol/web201310/skin/big11000.jpg");
    }
    #section2{
      background-image: url("http://ossweb-img.qq.com/images/lol/web201310/skin/big55000.jpg");
    }
    #section3{
      background-image: url("http://ossweb-img.qq.com/images/lol/web201310/skin/big45000.jpg");
    }
    .left{
      float: left;
      width: 25%;
    }
  </style>
</head>
<body>
  <div id="container" style="width:400%">
    <div class="sections">
      <div class="section left" id="section0">
        <h3>this is the page</h3>
      </div>
      <div class="section left" id="section1">
        <h3>this is the page</h3>
      </div>
      <div class="section left" id="section2">
        <h3>this is the page</h3>
      </div>
      <div class="section left" id="section3">
        <h3>this is the page</h3>
      </div>
    </div>
  </div>
</body>
</html>

展示效果

2.图片竖排展示全屏切换效果

代码语言:javascript
复制
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Document</title>
  <style>
    *{
      padding: 0;
      margin: 0;
    }
    html,body{
      height: 100%;
    }
    #container,.sections,.section{
      height: 100%;
    }
    #section0,
    #section1,
    #section2,
    #section3{
      background-color: #000;
      background-size: cover;
      /*让背景图片在容器中居中*/
      background-position: 50% 50%;
      text-align: center;
      color: white;
    }
    #section0{
      background-image: url("http://ossweb-img.qq.com/images/lol/web201310/skin/big86000.jpg");
    }
    #section1{
      background-image: url("http://ossweb-img.qq.com/images/lol/web201310/skin/big11000.jpg");
    }
    #section2{
      background-image: url("http://ossweb-img.qq.com/images/lol/web201310/skin/big55000.jpg");
    }
    #section3{
      background-image: url("http://ossweb-img.qq.com/images/lol/web201310/skin/big45000.jpg");
    }
  </style>
</head>
<body>
  <div id="container">
    <div class="sections">
      <div class="section" id="section0">
        <h3>this is the page</h3>
      </div>
      <div class="section" id="section1">
        <h3>this is the page</h3>
      </div>
      <div class="section" id="section2">
        <h3>this is the page</h3>
      </div>
      <div class="section" id="section3">
        <h3>this is the page</h3>
      </div>
    </div>
  </div>
</body>
</html>

展示效果

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017.11.05 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 如何通过CSS使div实现全屏效果
  • 1.图片横排展示全屏切换效果
  • 2.图片竖排展示全屏切换效果
相关产品与服务
容器服务
腾讯云容器服务(Tencent Kubernetes Engine, TKE)基于原生 kubernetes 提供以容器为核心的、高度可扩展的高性能容器管理服务,覆盖 Serverless、边缘计算、分布式云等多种业务部署场景,业内首创单个集群兼容多种计算节点的容器资源管理模式。同时产品作为云原生 Finops 领先布道者,主导开源项目Crane,全面助力客户实现资源优化、成本控制。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档