实现背景图片自适应。
来源:互联网 发布:数据分析研究生专业 编辑:程序博客网 时间:2024/05/19 00:48
所需css js
<link rel="stylesheet" href="https://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="https://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>
css部分
<style type="text/css"> .header{background: url("images/back2.jpg") no-repeat center top;background-position: center center;width:100%;min-height:529px;background-size:100% 100%;padding-top: 30px;position:absolute;} .first-row div a{float: left;color: #fff;font-size: 22px;font-weight: bold;text-decoration: none;} .first-row div a img{width: 28px;height: 28px;} .first-row div ul{float: right;color: #fff;padding-top:5px;} .first-row div ul li{list-style: none;display: inline;} .first-row div ul li a{font-size: 17px;padding:0 10px;} @media(max-width: 867px){ .first-row div ul{font-size: 10px;float:none;} } @media(max-width: 260px){ .first-row div ul{display: none;} } .second-row{width: 100%;display: block;margin-left: auto;margin-right: auto;margin-top: 50px;color: #fff;margin-bottom: 0px;} .second-row div img{width: 96px;height: 96px;} .second-row div h1{letter-spacing:5px;margin-top: 35px;} .second-row div div{width: 200px;height: 37px;background:#1EC38B;text-align: center;line-height: 37px;margin-top: 35px;} .second-row div div a{text-decoration: none;color: #fff;} .third-row{width: 80%;position: relative;top:0px;margin-top: 30px;} .third-row div img{max-width:100%;margin-bottom: 0px;} @media(max-width: 590px){ .header{background: url("images/back2.jpg") no-repeat center top;background-position: center center;width:100%;height: 549px;background-size:100%;-webkit-background-size:cover;padding-top: 30px;} } </style>
</head>
正文部分
<body> <!-- header --> <div class="header"> <div class="container"> <div class="row first-row"> <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12"> <a> <img src="images/logo.png"> Bootstone </a> <ul> <li><a>Change log</a></li> <li><a>Team/Comming soon</a></li> <li><a>Shop</a></li> <li><a>Respository</a></li> </ul> </div> </div><!-- first-row --> <div class="row second-row"> <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12"> <img src="images/logo.png"> <h1>Write like a NINJA</h1> <h4>Boostnote is an open source note-taking app made for programmers just like you.</h4> <div class="center-block"><a href="###">Free Download</a></div> </div> </div><!-- second-row --> <div class="row third-row center-block"> <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12"> <img src="images/top.png"> </div> </div><!-- third-row --> </div><!--container--> </div><!-- header --> <div class="test" style="width:100%;height:400px;background:red;position:relative;"></div> </body></html>
jQuery部分:
<script type="text/javascript"> var hheight=$(".header").height(); var Cheight=$(".test").css("top",hheight); $(window).resize(function(){ var hheight=$(".header").height(); var Cheight=$(".test").css("top",hheight); }); </script>
如果现在红色div后面再次添加div
在引用我的jQuery类比修改class就可以,eg:
Cheight 改为 bheight即可
<script type="text/javascript"> var hheight=$(".header").height(); var bheight=$(".bottom").css("top",hheight); $(window).resize(function(){ var hheight=$(".header").height(); var bheight=$(".bottom").css("top",hheight); }); </script>
1366分辨率全屏下效果:
500分辨率下效果
在线访问地址:
http://htmlpreview.github.io/?https://github.com/wy7365596/BootstoneTwo/blob/master/index.html
0 0
- 实现背景图片自适应。
- css实现背景图片自适应大小
- css样式实现背景图片自适应
- 如何实现背景图片自适应td大小
- CSS 实现背景图片自适应td大小
- 背景图片自适应
- 背景图片自适应
- 自适应背景图片
- 背景图片自适应
- html/js 实现背景图片自适应窗口分辨率大小
- 小标题两侧加横线或背景图片自适应布局实现技巧
- html 背景图片实现 宽度自适应,高度为背景图片高度 解决发案
- 背景图片自适应分辨率大小
- 如何设置背景图片自适应
- 背景图片自适应浏览器大小
- 控件背景图片自适应
- html背景图片自适应
- 背景图片自适应大小(css3)
- 关于#ifdef的一个注意事项
- scanf sprintf用法
- iOS平台上aa(见缝插针)游戏的简易实现
- STL完整版整理
- LinkedList源码解析
- 实现背景图片自适应。
- 输出一行数字,中间用空格隔开,最后一个数字没有空格
- Activity的四种启动模式
- 贪心算法--喷水装置(二)
- 闲话mysql-5.7.18-winx64的secure_file_priv配置项
- chrome on mac
- 水乳交融:论VMware与OpenStack的整合—1
- yii定义常量
- 学习记录