BootStrap4工具类之显示样式类系列

官方地址

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

其他文档地址

如何运作

使用 display 的工具类来改变 display 属性,官方故意只支持display 所有可能的一个子集,
可以依据需求将这些 Class 调整出各种效果。

命名

.d-{value} for xs

.d-{breakpoint}-{value} for sm, md, lg, and xl.

值可以替换成以下:

  • none
  • inline
  • block
  • inline-block
  • flex
  • inline-flex
  • table
  • table-cell
  • table-row

例子

<div class="container">
    <h1>实例</h1>
    <div class="d-inline p-2 bg-primary text-white">d-inline</div>
    <div class="d-inline p-2 bg-dark text-white">d-inline</div>
</div>

隐藏元素

Screen SizeClass
Hidden on all.d-none
Hidden only on xs.d-none .d-sm-block
Hidden only on sm.d-sm-none .d-md-block
Hidden only on md.d-md-none .d-lg-block
Hidden only on lg.d-lg-none .d-xl-block
Hidden only on xl.d-xl-none
Visible on all.d-block
Visible only on xs.d-block .d-sm-none
Visible only on sm.d-none .d-sm-block .d-md-none
Visible only on md.d-none .d-md-block .d-lg-none
Visible only on lg.d-none .d-lg-block .d-xl-none
Visible only on xl.d-none .d-xl-block

显示在打印中

命名

.d-print-{value}

  • .d-print-none
  • .d-print-inline
  • .d-print-block
  • .d-print-inline-block
  • .d-print-flex
  • .d-print-inline-flex
  • .d-print-table
  • .d-print-table-cell
  • .d-print-table-row

例子

<h3>实例</h3>
<div class="d-print-none">Screen Only (Hide on print only)</div>
<div class="d-none d-print-block">Print Only (Hide on screen only)</div>
<div class="d-none d-lg-block d-print-block">Hide up to large on screen, but always show on print</div>

整体代码

<!DOCTYPE html>
<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>12显示</title>
    <!--<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">-->

    <!-- 新 Bootstrap4 核心 CSS 文件 -->
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
</head>
<body>
<pre class="pre-scrollable">

</pre>

<div class="container">
    <h1>如何运作</h1>
    <p>
        使用 display 的工具类来改变 display 属性,
        我们故意只支持 display 所有可能的一个子集,
        可以依据需求将这些 Class 调整出各种效果。
    </p>

    <div class="container">
        <h1>命名</h1>
        <p>
            <code>.d-{value}</code> for xs
        </p>
        <p>
            <code>.d-{breakpoint}-{value}</code> for sm, md, lg, and xl.
        </p>
        <h2>值可以替换成以下:</h2>
        <ul>
            <li>
                <code>none</code>
            </li>

            <li>
                <code>inline</code>
            </li>

            <li>
                <code>block</code>
            </li>

            <li>
                <code>inline-block</code>
            </li>

            <li>
                <code>flex</code>
            </li>

            <li>
                <code>inline-flex</code>
            </li>

            <li>
                <code>table</code>
            </li>

            <li>
                <code>table-cell</code>
            </li>

            <li>
                <code>table-row</code>
            </li>
        </ul>
    </div>
</div>


<div class="container">
    <h1>实例</h1>
    <div class="d-inline p-2 bg-primary text-white">d-inline</div>
    <div class="d-inline p-2 bg-dark text-white">d-inline</div>
</div>

<div class="container">
    <h1>隐藏元素</h1>
    <table class="table table-bordered table-striped table-hover">
        <thead>
        <tr>
            <th>Screen Size</th>
            <th>Class</th>
        </tr>
        </thead>
        <tbody>
        <tr>
            <td>Hidden on all</td>
            <td><code class="highlighter-rouge">.d-none</code></td>
        </tr>
        <tr>
            <td>Hidden only on xs</td>
            <td><code class="highlighter-rouge">.d-none .d-sm-block</code></td>
        </tr>
        <tr>
            <td>Hidden only on sm</td>
            <td><code class="highlighter-rouge">.d-sm-none .d-md-block</code></td>
        </tr>
        <tr>
            <td>Hidden only on md</td>
            <td><code class="highlighter-rouge">.d-md-none .d-lg-block</code></td>
        </tr>
        <tr>
            <td>Hidden only on lg</td>
            <td><code class="highlighter-rouge">.d-lg-none .d-xl-block</code></td>
        </tr>
        <tr>
            <td>Hidden only on xl</td>
            <td><code class="highlighter-rouge">.d-xl-none</code></td>
        </tr>
        <tr>
            <td>Visible on all</td>
            <td><code class="highlighter-rouge">.d-block</code></td>
        </tr>
        <tr>
            <td>Visible only on xs</td>
            <td><code class="highlighter-rouge">.d-block .d-sm-none</code></td>
        </tr>
        <tr>
            <td>Visible only on sm</td>
            <td><code class="highlighter-rouge">.d-none .d-sm-block .d-md-none</code></td>
        </tr>
        <tr>
            <td>Visible only on md</td>
            <td><code class="highlighter-rouge">.d-none .d-md-block .d-lg-none</code></td>
        </tr>
        <tr>
            <td>Visible only on lg</td>
            <td><code class="highlighter-rouge">.d-none .d-lg-block .d-xl-none</code></td>
        </tr>
        <tr>
            <td>Visible only on xl</td>
            <td><code class="highlighter-rouge">.d-none .d-xl-block</code></td>
        </tr>
        </tbody>
    </table>
</div>

<div class="container">
    <h1>显示在打印中</h1>
    <h2>命名</h2>
    <p>
        <code>.d-print-{value}</code>
    </p>
    <ul>
        <li>
            <code>.d-print-none</code>
        </li>

        <li>
            <code>.d-print-inline</code>
        </li>

        <li>
            <code>.d-print-block</code>
        </li>

        <li>
            <code>.d-print-inline-block</code>
        </li>

        <li>
            <code>.d-print-flex</code>
        </li>

        <li>
            <code>.d-print-inline-flex</code>
        </li>

        <li>
            <code>.d-print-table</code>
        </li>

        <li>
            <code>.d-print-table-cell</code>
        </li>

        <li>
            <code>.d-print-table-row</code>
        </li>
    </ul>
    <h3>实例</h3>
    <div class="d-print-none">Screen Only (Hide on print only)</div>
    <div class="d-none d-print-block">Print Only (Hide on screen only)</div>
    <div class="d-none d-lg-block d-print-block">Hide up to large on screen, but always show on print</div>
</div>
<!--<div style="width: 10px; height: 9000px;"></div>-->
<!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
<script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>

<!-- bootstrap.bundle.min.js 用于弹窗、提示、下拉菜单,包含了 popper.min.js -->
<script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script>

<!-- 最新的 Bootstrap4 核心 JavaScript 文件 -->
<script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值