📜  CSS | text-overflow 属性

📅  最后修改于: 2021-08-30 10:23:50             🧑  作者: Mango

CSS text-overflow 属性用于指定某些文本已溢出并从视图中隐藏。必须将 white-space 属性设置为 nowrap 并且必须隐藏溢出属性。

句法:

text-overflow: clip|string|ellipsis|initial|inherit;

属性值:

  • 剪辑:文本被剪辑,无法看到。这是默认值。

    句法:

    text-overflow: clip;
    

    例子:

    
    
        
            CSS | text-overflow Property
        </ttile>
        <style type="text/css">
            div{
                width: 500px;
                font-size: 50px;
                white-space: nowrap; 
                overflow: hidden;
                text-overflow: clip;
      
            }
        </style>
    </head>
    <body>
        <div>
            Geeks For Geeks:
            A computer science portal for geeks.
        </div>
    </body>
    </html>
    </code></pre>
    </div>
    <p><strong>输出:</strong> </p>
    <div class="wp-caption aligncenter" id="attachment_838089" style="width:573px"><img alt="CSS text-overflow_clip gfg" class="img-fluid" height="218" loading="lazy" src="https://mangodoc.oss-cn-beijing.aliyuncs.com/geek8geeks/CSS_%7C_text-overflow_Property_0.jpg" width="563"/>
    <p class="wp-caption-text"> CSS text-overflow_clip</p>
    </div>
    </li>
    <li><strong>省略号:</strong>文本被剪切,被剪切的文本表示为<strong>‘…’</strong> 。<br/><strong>句法:</strong>
    <div class="hcb_wrap">
    <pre class="prism line-numbers lang-css" data-lang="CSS"><code class="replace">text-overflow: ellipsis;
    </code></pre>
    </div>
    <p><strong>例子:</strong> </p>
    <div class="hcb_wrap">
    <pre class="prism line-numbers lang-css" data-lang="CSS"><code class="replace"><html>
      
    <head>
        <title>
            CSS | text-overflow Property
        </ttile>
        <style type="text/css">
            div {
                width: 500px;
                font-size: 50px;
                white-space: nowrap;
                overflow: hidden;
                text-overflow: clip;
            }
        </style>
    </head>
      
    <body>
        <div>
            Geeks For Geeks:
            A computer science portal for geeks.
        </div>
    </body>
      
    </html>
    </code></pre>
    </div>
    <p><strong>输出:</strong> <br/><img alt="" class="img-fluid" src="https://mangodoc.oss-cn-beijing.aliyuncs.com/geek8geeks/CSS_%7C_text-overflow_Property_1.jpg"/></p>
    </li>
    <li> <strong>字符串:</strong>使用编码器选择的字符串向用户表示剪切的文本。此选项仅在 Firefox 浏览器中可见。
    <p><b>句法:</b> </p>
    <div class="hcb_wrap">
    <pre class="prism line-numbers lang-css" data-lang="CSS"><code class="replace">text-overflow: string;
    
    where a string is defined by the coder.
    </code></pre>
    </div>
    <p><strong>例子:</strong> </p>
    <div class="hcb_wrap">
    <pre class="prism line-numbers lang-css" data-lang="CSS"><code class="replace"><html>
      
    <head>
        <title>
            CSS | text-overflow Property
        </ttile>
        <style type="text/css">
            div {
                width: 500px;
                font-size: 50px;
                white-space: nowrap;
                overflow: hidden;
                text-overflow: "Value Clipped";
            }
        </style>
    </head>
      
    <body>
        <div>
            Geeks For Geeks:
            A computer science portal for geeks.
        </div>
    </body>
      
    </html>
    </code></pre>
    </div>
    <p><strong>输出:</strong> <br/><img class="img-fluid" src="https://mangodoc.oss-cn-beijing.aliyuncs.com/geek8geeks/CSS_%7C_text-overflow_Property_2.jpg"/></p>
    </li>
    <li><strong>初始</strong>值<strong>:</strong>此值将文本溢出属性设置为默认值。
    <p><strong>句法:</strong> </p>
    <div class="hcb_wrap">
    <pre class="prism line-numbers lang-css" data-lang="CSS"><code class="replace">text-overflow: initial;
    </code></pre>
    </div>
    <p><strong>例子:</strong> </p>
    <div class="hcb_wrap">
    <pre class="prism line-numbers lang-css" data-lang="CSS"><code class="replace"><html>
      
    <head>
        <title>
            CSS | text-overflow Property
        </ttile>
        <style type="text/css">
            div {
                width: 500px;
                font-size: 50px;
                white-space: nowrap;
                overflow: hidden;
                text-overflow: initial;
            }
        </style>
    </head>
      
    <body>
        <div>
            Geeks For Geeks:
            A computer science portal for geeks.
        </div>
    </body>
      
    </html>
    </code></pre>
    </div>
    <p><strong>输出:</strong> <br/><img class="img-fluid" src="https://mangodoc.oss-cn-beijing.aliyuncs.com/geek8geeks/CSS_%7C_text-overflow_Property_3.jpg"/></p>
    </li>
    <li><strong>继承:</strong>此值将 text-overflow 属性设置为父元素的值。
    <p><strong>句法:</strong> </p>
    <div class="hcb_wrap">
    <pre class="prism line-numbers lang-css" data-lang="CSS"><code class="replace">text-overflow: inherit;
    </code></pre>
    </div>
    <p><strong>例子:</strong> </p>
    <div class="hcb_wrap">
    <pre class="prism line-numbers lang-css" data-lang="CSS"><code class="replace"><html>
      
    <head>
        <title>
            CSS | text-overflow Property
        </ttile>
        <style type="text/css">
            div {
                width: 500px;
                font-size: 50px;
                white-space: nowrap;
                overflow: hidden;
                text-overflow: ellipsis;
            }
              
            h1 {
                width: 500px;
                white-space: nowrap;
                overflow: hidden;
                text-overflow: inherit;
            }
        </style>
    </head>
      
    <body>
        <div>
            Geeks For Geeks:
            A computer science portal for geeks.
            <h1>
             I have inherited my overflow property from div.
            </h1>
        </div>
    </body>
      
    </html>
    </code></pre>
    </div>
    <p><strong>输出:</strong> <br/><img alt="" class="img-fluid" src="https://mangodoc.oss-cn-beijing.aliyuncs.com/geek8geeks/CSS_%7C_text-overflow_Property_4.jpg"/></p>
    </li>
    </ul>
    <p><strong>支持的浏览器:</strong> <em>text-overflow 属性</em><strong>支持的浏览</strong>器如下:</p>
    <ul>
    <li>铬:4.0</li>
    <li>火狐:7.0</li>
    <li> Safari:3.1</li>
    <li>边缘:16</li>
    <li>歌剧:11.0 </li>
    </ul>
    <div class="_ap_apex_ad" id="82d2079a-8120-480f-9fc7-5cda825d56e7"></div>
    <p></p></div>
    
                    </div>
    
                </div>
            </div>
        </div>
    </div>
    
    
      
    <footer>
        <div class="bg-white text-center pb-1">
            <p class="text-body-tertiary pt-3 lh-lg text-opacity-50" id="footer-text">Copyright © 2020 - 2024 版权所有
                <br>
    
                <a href="https://beian.miit.gov.cn/" target="_blank"
                    class="text-opacity-50 text-body-tertiary mt-1 mb-1">蜀ICP备20006366号-1</a>
    
                <br>
                Made with ❤️ in Chengdu
            </p>
        </div>
    </footer>
    
    
      <!-- 引入Bootstrap JavaScript库 -->
      <script src="https://unpkg.com/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"
        crossorigin="anonymous"></script>
    
      <!-- 引入Meilisearch搜索相关的JavaScript库 -->
      <script
        src="https://cdn.jsdelivr.net/npm/@meilisearch/instant-meilisearch/dist/instant-meilisearch.umd.min.js"></script>
      <script src="https://cdn.jsdelivr.net/npm/instantsearch.js@4"></script>
      <script src="https://imangodoc.com/static/javascript/meili_custom.js"></script>
    
      <!-- 引入prismjs代码高亮相关的JavaScript库 -->
      <script src="https://cdn.jsdelivr.net/npm/prismjs@1.29.0/components/prism-core.min.js"></script>
      <script src="https://cdn.jsdelivr.net/npm/prismjs@1.29.0/plugins/toolbar/prism-toolbar.min.js"></script>
      <script src="https://cdn.jsdelivr.net/npm/prismjs@1.29.0/plugins/autoloader/prism-autoloader.min.js"></script>
      <script
        src="https://cdn.jsdelivr.net/npm/prismjs@1.29.0/plugins/copy-to-clipboard/prism-copy-to-clipboard.min.js"></script>
    
    </body>
    
    
    </html>