BootStrap4工具类之定位

目录

  • 官方地址
  • 其他文档地址
  • 通用属性
  • 固定在顶部
  • 固定在底部
  • sticky置顶
  • 整体代码

官方地址

https://getbootstrap.com/docs/4.4/utilities/position/

其他文档地址

  • https://getbootstrap.net
    • https://getbootstrap.net/docs/utilities/position/
  • http://bs4.vx.link
    • http://bs4.vx.link/index.html?tmpui_page=/pages/utilities

通用属性

  • .postition-static
  • .position-relative
  • .position-absolute
  • .position-fixed
  • .position-sticky
<div class="container position-relative" style="height: 1000px;">
    <h1>通用属性h1>
    <div class="position-static bg-primary" style="width: 100px; height: 100px;">position-staticdiv>
    <div class="position-relative bg-secondary" style="width: 100px; height: 100px;">position-relativediv>
    <div class="position-absolute bg-success" style="width: 100px; height: 100px;">position-absolutediv>
    <div class="position-fixed bg-warning" style="left: 10px; width: 100px; height: 100px;">position-fixeddiv>
    <div class="position-sticky bg-danger" style="top: 10px; width: 100px; height: 100px;">position-stickydiv>
    <div class="position-sticky bg-dark" style="top: 10px; width: 100px; height: 100px;">position-stickydiv>
    <div class="position-sticky bg-light" style="top: 10px; width: 100px; height: 100px;">position-stickydiv>
div>

固定在顶部

.fixed-top

<div class="container">
    <h1>固定在顶部h1>
    <p class="lead">将一个元素置于可视区的顶部,从边到边。必要时你需要增加额外的 CSS。p>
    <div class="fixed-top bg-primary" style="width: 100px; height: 100px;">固定在顶部div>
div>

固定在底部

.fixed-bottom

<div class="container">
    <h1>固定在底部h1>
    <p class="lead">一个元素置于可视区的底部,从边到边。必要时你需要增加额外的 CSS。p>
    <div class="fixed-bottom bg-primary" style="width: 100px; height: 100px;">固定在顶部div>
div>

sticky置顶

.sticky-top

<div class="container border border-primary bg-light" style="height: 1000px;">
    <h1>粘性置顶h1>
    <div class="sticky-top bg-primary" style="width: 100px; height: 100px;">sticky-top bg-primarydiv>
    <div class="sticky-top bg-success" style="width: 100px; height: 100px;">sticky-top bg-successdiv>
    <div class="sticky-top bg-danger" style="width: 100px; height: 100px;">sticky-top bg-dangerdiv>
div>

整体代码


<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no"/>
    <title>11定位title>
    

    
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
head>
<body>
<pre class="pre-scrollable">
    若不明白sticky,阅读https://www.cnblogs.com/coco1s/p/6402723.html
    or 翻阅自已的笔记
pre>

<div class="container position-relative" style="height: 1000px;">
    <h1>通用属性h1>
    <div class="position-static bg-primary" style="width: 100px; height: 100px;">position-staticdiv>
    <div class="position-relative bg-secondary" style="width: 100px; height: 100px;">position-relativediv>
    <div class="position-absolute bg-success" style="width: 100px; height: 100px;">position-absolutediv>
    <div class="position-fixed bg-warning" style="left: 10px; width: 100px; height: 100px;">position-fixeddiv>
    <div class="position-sticky bg-danger" style="top: 10px; width: 100px; height: 100px;">position-stickydiv>
    <div class="position-sticky bg-dark" style="top: 10px; width: 100px; height: 100px;">position-stickydiv>
    <div class="position-sticky bg-light" style="top: 10px; width: 100px; height: 100px;">position-stickydiv>
div>

<div class="container">
    <h1>固定在顶部h1>
    <p class="lead">将一个元素置于可视区的顶部,从边到边。必要时你需要增加额外的 CSS。p>
    <div class="fixed-top bg-primary" style="width: 100px; height: 100px;">固定在顶部div>
div>

<div class="container">
    <h1>固定在底部h1>
    <p class="lead">一个元素置于可视区的底部,从边到边。必要时你需要增加额外的 CSS。p>
    <div class="fixed-bottom bg-primary" style="width: 100px; height: 100px;">固定在顶部div>
div>

<div class="container border border-primary bg-light" style="height: 1000px;">
    <h1>粘性置顶h1>
    <div class="sticky-top bg-primary" style="width: 100px; height: 100px;">sticky-top bg-primarydiv>
    <div class="sticky-top bg-success" style="width: 100px; height: 100px;">sticky-top bg-successdiv>
    <div class="sticky-top bg-danger" style="width: 100px; height: 100px;">sticky-top bg-dangerdiv>
div>


<script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js">script>


<script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js">script>


<script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js">script>
body>
html>

你可能感兴趣的:(BootStrap4)