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

编程入门 行业动态 更新时间:2024-10-08 06:18:13

面试总结:H5 移动 web 开发(H5 <a href=https://www.elefans.com/category/jswz/34/1767830.html style=新特性、CSS3 新特性、如何实现双飞翼(圣杯)布局)"/>

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

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>

更多推荐

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

本文发布于:2024-03-12 10:07:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1731276.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:新特性   如何实现   布局   圣杯   双飞翼

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!