温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

HTML5和CSS3的面试题有哪些

发布时间:2022-02-21 10:18:50 来源:亿速云 阅读:145 作者:iii 栏目:开发技术

本篇内容介绍了“HTML5和CSS3的面试题有哪些”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

1. 列举3个HTML5新标签,3个CSS3新特性。

  • HTML5 新标签 header,nav,article,footer,section,aside,audio,video,embed

  • CSS3 新特性 border-radius ,box-shadow,border-image,background-image,transition.

2. HTML5实现本地临时存储和永久存贮、读取、删除一条 key 为c,value 为 tom 的数据。

// 临时存储 
sessionStorage.setItem('c','tom')
// 永久存贮 
localStorage.setItem('c','tom')
// 读取 
localStorage.getItem('c')
// 删除 
localStorage.removeItem("c");//逐条删
localStorage.clear();//删除全部

3.用 js+css3 实现某 DIV 以50px每秒的速度左移 100px

<style>
    .box{
      width: 100px;
      height: 100px;
      background-color:pink;
      position: relative;
      left: 0;
      top: 0;
    }
  </style>
  <body>
  <div class="box"></div>
  <script>
    // 100*20=2000
    // 获取box
    let box= document.querySelector('.box')
    let left = box.style.left
    var leftnum = Number(left.split('px')[0]) //不要单位
    var num = 1
    var animate = setInterval(() => {
      if(num>=100){
        clearInterval(animate)
      }
      leftnum+=1
      box.style.left = leftnum+'px'
      num++
    }, 20);
  </script>
</body>

4.CSS 实现三栏布局(左右固定200px,中间自适应)

双飞翼布局:都左浮动,中间包一个盒子,padding 隔开两侧宽度。左右两侧都有 margin-left.

<style>
    body {
        min-width: 550px;
      }
      .col {
        float: left; 
      }
      #main {
        width: 100%;
        height: 400px;
        background-color: #ccc;
      }
      #main-wrap {
        margin: 0 200px 0 200px;
      }
      #left {
        width: 200px;
        height: 400px;
        margin-left: -100%;
        background-color: red;
      }
      #right {
        width: 200px;
        height: 400px;
        margin-left: -200px;
        background-color: #ff0000;
      }
  </style>
  <body>
  <div id="container">
    <div id="main" class="col">
      <div id="main-wrap"></div>
    </div>
    <div id="left" class="col"></div>
    <div id="right"class="col"></div>
  </div>
</body>

圣杯布局:中间不包盒子但还是有 padding。

<style>
    #container{
      padding: 0 190px 0 190px;
    }
    .col{
      position: relative;
      float: left;
    }
    #main{
      width: 100%;
      height: 400px;
      background-color: #ddd;
    }
    #left{
      width: 190px;
      height: 400px;
      background-color:red;
      /* 离左边距本身的距离 */
      margin-left: -100%;
      /* 然后又自己向左移了本身的宽度*/
      left: -190px;
    }
    #right{
      width: 190px;
      height: 400px;
      background-color: yellow;
      margin-left: -190px;
      right: -190px;
    }
  </style>
  <body>
  <div id="container">
    <div id="main" class="col"></div>
    <div id="left" class="col"></div>
    <div id="right"class="col"></div>
  </div>
  </body>

 拓展 左右布局

<style>
    html,body{
      height: 100%;
    }
    .left{
      width: 256px;
      height: 100%;
      background-color: #ddd;
      float: left;
    }
    .right{
      width: 100%;
      height: 100%;
      margin-left: 256px;
      background-color: rgb(230, 48, 48);
    }
  </style>
  <body>
  <div class="left"></div>
  <div class="right"></div>
  </body>

5.使用 html5 canvas 绘制实心原形。

<style>
    #canvas{
      width: 500px;
      height: 500px;
    }
</style>
<body>
  <canvas id="canvas"></canvas>
</body>
<script>
    var canvas=document.getElementById("canvas");
	var ctx=canvas.getContext("2d");
	//画一个空心圆
	ctx.beginPath();
	// arc()方法是创建弧/曲线(用于创建圆或部分圆)
	// context.arc(x,y,r,sAngle,eAngle,counterclockwise);
	// 起始角为 0
	// 结束角为 2*Math.PI
	ctx.arc(100,75,50,0,2*Math.PI);
	ctx.lineWidth=5;
	ctx.strokeStyle="green";
	// 使用 stroke()或fill()方法在画布上绘制实际的弧
	ctx.stroke();//画空心圆
	ctx.closePath();
	//画一个实心圆
	// ctx.beginPath();
	// ctx.arc(200,100,50,0,360,false);
	// ctx.fillStyle="red";//填充颜色,默认是黑色
	// ctx.fill();//画实心圆
	// ctx.closePath();
	//空心和实心的组合
	// ctx.beginPath();
	// ctx.arc(100,100,50,0,360,false);
	// ctx.fillStyle="red";
	// ctx.fill();
	// ctx.strokeStyle="green";
	// ctx.stroke();
	// ctx.closePath();
</script>

6.如何使用 css3 动画实现盒子 hover 时高度从10到100的动画?

<style>
    #box{
      width: 100px;
      height: 10px;
      background-color: pink;
      transition: all 1s ease;
    }
    #box:hover{
      height: 100px;
    }
</style>
<body>
  <div id="box"></div>
</body>

“HTML5和CSS3的面试题有哪些”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI