背景图片宽度100%高度同比例放大不变形
2017-01-12 12:11
225 查看
解决方案:
1、js 通过计算屏幕宽度 根据图片的宽高度比例来计算高度 来调整div等标签的尺寸
2、使用rem作为单位,提前根据款高比在css写死宽高度
3、使用css样式,代码如下:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.Header
{
position:relative;
width: 100%;
height:0;
padding-bottom:98.125%;
background: url('http://img.kuaiwanwo.com/Recom/Header.png') no-repeat;
background-size: 100% 100%;
}
.Header-container
{
position:absolute;
width:100%;
height:100%;
top:0;
left:0;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div class="Header">
<div class="Header-container">
这里是内容
</div>
</div>
</form>
</body>
</html>
1、js 通过计算屏幕宽度 根据图片的宽高度比例来计算高度 来调整div等标签的尺寸
2、使用rem作为单位,提前根据款高比在css写死宽高度
3、使用css样式,代码如下:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.Header
{
position:relative;
width: 100%;
height:0;
padding-bottom:98.125%;
background: url('http://img.kuaiwanwo.com/Recom/Header.png') no-repeat;
background-size: 100% 100%;
}
.Header-container
{
position:absolute;
width:100%;
height:100%;
top:0;
left:0;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div class="Header">
<div class="Header-container">
这里是内容
</div>
</div>
</form>
</body>
</html>
相关文章推荐
- 最棒的Android控件效果
- php 学习笔记--数组篇(7)
- 唐巧总结的40个国人iOS技术博客
- Java String.split()特殊字符的使用
- 虚拟机与本地主机无法ping通及虚拟机设置两个网卡
- Sublime Text 3 全程详细图文原创教程(持续更新中。。。)
- opencv图像旋转
- 【SSH】:基于Struts2+HIbernate3+Spring3实现员工管理系统之案例实现篇(上)
- cordova 环境搭建
- 陶陶摘苹果
- mysql查询表中某个字段包含有中文的行
- Redis简介
- ionic2常见问题——修改应用图标及添加启动画面(官方命令行工具自动生成)
- 跨平台的HTML转图片方法
- 假期小目标,以及大学半年来的经历
- ural 1563
- Swift3-Type 'String' does not conform to protocol 'Sequence'
- 秒,毫秒,微秒,纳秒,皮秒,飞秒
- studio构建错误Element uses-permission#android.permission.ACCESS_NETWORK_STATE at AndroidManifest.xml:38:5-79 dupli
- windows下面配置apache+https