面试总结:H5 移动 web 开发(H5 新特性、CSS3 新特性、如何实现双飞翼(圣杯)布局)

这篇博客主要涵盖了H5和CSS3的新特性,并详细探讨了如何实现盒子的水平垂直居中以及双飞翼布局(圣杯布局)的方法,是前端开发者面试准备的重要参考资料。
摘要由CSDN通过智能技术生成

H5 新特性

1、 拖拽释放(Drap and drop) API ondrop
拖放是一种常见的特性,即抓取对象以后拖到另一个位置
在 HTML5 中,拖放是标准的一部分,任何元素都能够拖放
2、自定义属性 data-id
3、语义化更好的内容标签(header,nav,footer ,aside, article, section)
4、音频 ,视频(audio, video) 如果浏览器不支持自动播放怎么办? 在属性中添加
autoplay(谷歌浏览器不支持音频自动播放,但是视频支持静音自动播放)
5、画布 Canvas
5.1)getContext() 方法返回一个用于在画布上绘图的环境
Canvas.getContext(contextID) 参数 contextID 指定了您想要在画布上绘制的类型。当
前唯一的合法值是 “2d”,它指定了二维绘图,并且导致这个方法返回一个环境对象,该
对象导出一个二维绘图 API
5.2)cxt.stroke() 绘制线条
5.3)canvas 和 image 在处理图片的时候有什么区别?
image 是通过对象的形式描述图片的,canvas 通过专门的 API 将图片绘制在画布
上.
6、 地理(Geolocation) API 其实 Geolocation 就是用来获取到当前设备的经纬度(位
置)
7、 本地离线存储 localStorage 用于长久保存整个网站的数据,保存的数据没有过
期时间,直到手动去删除
8、 sessionStorage 该数据对象临时保存同一窗口(或标签页)的数据,在关闭窗口或
标签页之后将会删除这些数据。
9、 表单控件 calendar , date , time , email , url , search , tel , file ,
number
10、新的技术 webworker, websocket , Geolocation

CSS3 新特性

1、颜色: 新增 RGBA , HSLA 模式
2、文字阴影(text-shadow)
3、边框: 圆角(border-radius) 边框阴影 : box-shadow
4、盒子模型: box-sizing
5、背景:background-size background-origin background-clip
6、渐变: linear-gradient , radial-gradient
7、过渡 : transition 可实现属性的渐变
8、自定义动画 animate @keyfrom
9、媒体查询 多栏布局 @media screen and (width:800px) {…}
10、border-image 图片边框
11、2D 转换/3D 转换;transform: translate(x,y) rotate(x,y) skew(x,y) scale(x,y)
12、字体图标 iconfont/icomoon
13、弹性布局 flex

如何使一个盒子水平垂直居中?

方法一:利用定位(常用方法,推荐)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.parent {
width: 500px;
height: 500px;
border: 1px solid #000;
position: relative;
}
.child {
width: 100px;
height: 100px;
border: 1px solid #999;
position: absolute;
top: 50%;
left: 50%;
margin-top: -50px;
margin-left: -50px;
}
</style>
</head>
<body>
<div class="parent">
<div class="child">我是子元素</div>
</div>
</body>
</html>
方法二:利用 margin:auto;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.parent {
width: 500px;
height: 500px;
border: 1px solid #000;
position: relative;
}
.child {
width: 100px;
height: 100px;
border: 1px solid #999;
position: absolute;
margin: auto;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
</style>
</head>
<body>
<div class="parent">
<div class="child">我是子元素</div>
</div>
</body>
</html>
方法三:利用 display:table-cell
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.parent {
width: 500px;
height: 500px;
border: 1px solid #000;
display: table-cell;
vertical-align: middle;
text-align: center;
}
.child {
width: 100px;
height: 100px;
border: 1px solid #999;
display: inline-block;
}
</style>
</head>
<body>
<div class="parent">
<div class="child">我是子元素</div>
</div>
</body>
</html>
方法四:利用 display:flex;设置垂直水平都居中
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.parent {
width: 500px;
height: 500px;
border: 1px solid #000;
display: flex;
justify-content: center;
align-items: center;
}
.child {
width: 100px;
height: 100px;
border: 1px solid #999;
}
</style>
</head>
<body>
<div class="parent">
<div class="child">我是子元素</div>
</div>
</body>
</html>
方法五:计算父盒子与子盒子的空间距离(这跟方法一是一个道理)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.parent {
width: 500px;
height: 500px;
border: 1px solid #000;
}
.child {
width: 100px;
height: 100px;
border: 1px solid #999;
margin-top: 200px;
margin-left: 200px;
}
</style>
</head>
<body>
<div class="parent">
<div class="child">我是子元素</div>
</div>
</body>
</html>
方法六:利用 transform
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.parent {
width: 500px;
height: 500px;
border: 1px solid #000;
position: relative;
}
.child {
width: 100px;
height: 100px;
border: 1px solid #999;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
</style>
</head>
<body>
<div class="parent">
<div class="child">我是子元素</div>
</div>
</body>
</html>

如何实现双飞翼(圣杯)布局?

1、利用定位实现两侧固定中间自适应
1.1)父盒子设置左右 padding 值
1.2)给左右盒子的 width 设置父盒子的 padding 值,然后分别定位到 padding 处.
1.3)中间盒子自适应
具体 CSS 代码:
<style>
 .father {
 height: 400px;
 background-color: pink;
 position: relative;
 padding: 0 200px;
 }
 .left,.right {
 width: 200px;
 height: 300px;
 background-color: yellow;
position: absolute;
 top: 0;
 }
 .left {
 left: 0;
 }
 .right {
 right: 0;
 }
 .center {
 background-color: blue;
 height: 350px;
 }
</style>
// html 结构
<div class="father">
 <div class="left"></div>
 <div class="center"></div>
 <div class="right"></div>
</div>
2、利用 flex 布局实现两侧固定中间自适应
1)父盒子设置 display:flex;
2)左右盒子设置固定宽高
3)中间盒子设置 flex:1 ;
<style>
 .father {
 height: 400px;
 background-color: pink;
 display: flex;
 }
 .left {
 width: 200px;
 height: 300px;
 background-color: yellow;
 }
 .right {
 width: 200px;
 height: 300px;
 background-color: yellow;
 }
 .center {
 flex: 1;
 background-color: blue;
 }
</style>
// html 结构
<div class="father">
 <div class="left"></div>
 <div class="center"></div>
 <div class="right"></div>
</div>
3、利用 bfc 块级格式化上下文, 实现两侧固定中间自适应
3.1)左右固定宽高,进行浮动
3.2)中间 overflow: hidden;
<style>
.father {
height: 500px;
background-color: pink;
}
.left {
float: left;
width: 200px;
height: 400px;
background-color: blue; 
}
.right {
float: right;
width: 200px;
height: 400px;
background-color: blue;
}
.center {
 
height: 450px;
background-color: green;
overflow: hidden;
}
 
</style>
// html 结构  
<!-- 注意:left 和 right 必须放在 center 前面 -->
<div class="father">
<div class="left"></div>
<div class="right"></div>
<div class="center"></div>
</div>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值