position: sticky 吸顶css

DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Documenttitle>
    <style>
        .main-container {
            max-width: 500px;
            height: 500px;
            margin: 0 auto;
            margin-top: 40px;
            overflow: auto;
            margin-top: 20px;
        }
        .min{
          width: 100%;
          border: 1px solid;
          height: 400px;
        }
        .main-header {
            height: 50px;
            border: 5px solid red;
        }
        
        .main-content {
            min-height: 800px;
            border: 5px solid green;
            margin-top: 20px;
        }
        
        .main-footer {
            border: 5px solid blue;
            margin-top: 20px;
            height: 700px;
        }
        
        .main-header {
            position: sticky;
            top: 0;
          
        }
    style>
head>

<body>
    <main class="main-container">
        <div class="min">div>
        <div class="main-content">
          <header class="main-header">头部header>
        div>
        <footer class="main-footer">尾部footer>
    main>
    <div class="devide">div>
body>

html>

效果图
position: sticky 吸顶css_第1张图片

你可能感兴趣的:(css,html,css3)