• <bdo id='7JZzM'></bdo><ul id='7JZzM'></ul>

  1. <small id='7JZzM'></small><noframes id='7JZzM'>

    <legend id='7JZzM'><style id='7JZzM'><dir id='7JZzM'><q id='7JZzM'></q></dir></style></legend>
    <i id='7JZzM'><tr id='7JZzM'><dt id='7JZzM'><q id='7JZzM'><span id='7JZzM'><b id='7JZzM'><form id='7JZzM'><ins id='7JZzM'></ins><ul id='7JZzM'></ul><sub id='7JZzM'></sub></form><legend id='7JZzM'></legend><bdo id='7JZzM'><pre id='7JZzM'><center id='7JZzM'></center></pre></bdo></b><th id='7JZzM'></th></span></q></dt></tr></i><div id='7JZzM'><tfoot id='7JZzM'></tfoot><dl id='7JZzM'><fieldset id='7JZzM'></fieldset></dl></div>

    1. <tfoot id='7JZzM'></tfoot>

      是否可以仅使用 css 为 select 制作 text-overflow:ellipsis ?

      时间:2023-09-07
      <legend id='qAuFR'><style id='qAuFR'><dir id='qAuFR'><q id='qAuFR'></q></dir></style></legend>
    2. <i id='qAuFR'><tr id='qAuFR'><dt id='qAuFR'><q id='qAuFR'><span id='qAuFR'><b id='qAuFR'><form id='qAuFR'><ins id='qAuFR'></ins><ul id='qAuFR'></ul><sub id='qAuFR'></sub></form><legend id='qAuFR'></legend><bdo id='qAuFR'><pre id='qAuFR'><center id='qAuFR'></center></pre></bdo></b><th id='qAuFR'></th></span></q></dt></tr></i><div id='qAuFR'><tfoot id='qAuFR'></tfoot><dl id='qAuFR'><fieldset id='qAuFR'></fieldset></dl></div>
          <tfoot id='qAuFR'></tfoot>

          <small id='qAuFR'></small><noframes id='qAuFR'>

            <tbody id='qAuFR'></tbody>

                <bdo id='qAuFR'></bdo><ul id='qAuFR'></ul>
              • 本文介绍了是否可以仅使用 css 为 select 制作 text-overflow:ellipsis ?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                是否可以为 select 制作 text-overflow: ellipsis;?在 div 中很简单.当字符串太长有点时,我需要在 select 中相同.我知道,使用 js 是可能的,但我想获得轻量级"css 决定:

                Is it possible to make text-overflow: ellipsis; for select? In the divit is simple. When the string is too long there are dots, I need the same in select. I know, that it is possible with js, but I would like to get "light" css decision:

                .select {
                  box-sizing: border-box;
                  display: block;
                  width: 200px;
                  height: 34.5px;
                  padding: 5px 22px 3px 11px;
                  font: 400 16px/24px sans-serif;
                  color: #464a4c;
                  vertical-align: middle;
                  background: #fff url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiID8+CjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgd2lkdGg9IjEyIiBoZWlnaHQ9IjciPgoJPGRlZnM+CgkJPGNsaXBQYXRoIGlkPSJjbGlwXzAiPgoJCQk8cmVjdCB4PSItNDE1IiB5PSItNjYyIiB3aWR0aD0iMTQzNyIgaGVpZ2h0PSIyMjE2IiBjbGlwLXJ1bGU9ImV2ZW5vZGQiLz4KCQk8L2NsaXBQYXRoPgoJPC9kZWZzPgoJPGcgY2xpcC1wYXRoPSJ1cmwoI2NsaXBfMCkiPgoJCTxwYXRoIGZpbGw9InJnYig2NSw2NSw2NSkiIHN0cm9rZT0ibm9uZSIgZD0iTTAuNjUzNDQzIDQuNzY4MzdlLTA3TDExLjM0NjEgLTQuNzY4MzdlLTA3QzExLjk0MDIgLTQuNzY4MzdlLTA3IDEyLjE2ODIgMC41ODQ0ODggMTEuODY4MiAwLjkwNzY0OUw2LjU1MDMzIDYuNzE0MDRDNi4yNDczMSA3LjAzNjAzIDUuNzUzNzcgNy4xMTc3IDUuNDUwNzYgNi43OTQ1NEwwLjEzMjkxIDAuODY2ODE3Qy0wLjE3MDEwOSAwLjU0NDgyMyAwLjA2MjQwNTYgNC43NjgzN2UtMDcgMC42NTM0NDMgNC43NjgzN2UtMDciLz4KCTwvZz4KPC9zdmc+Cg==) no-repeat right 6px top 13px;
                  border: 1px solid #D6D6D6;
                  border-radius: 0;
                  -moz-appearance: none;
                  -webkit-appearance: none;
                  overflow: hidden;
                  white-space: nowrap;
                  text-overflow: ellipsis
                }

                <select class="select">
                  <option selected>select Mississippi Mississippi Mississippi Mississippi Mississippi</option>
                  <option value="1">1 Mississippi Mississippi Mississippi Mississippi Mississippi</option>
                  <option value="2">2 Mississippi Mississippi Mississippi Mississippi Mississippi</option>
                  <option value="3">3 Mississippi Mississippi Mississippi Mississippi Mississippi</option>
                </select>
                
                <br>
                
                <div class="select">div Mississippi Mississippi Mississippi Mississippi Mississippi</div>

                推荐答案

                不是最干净的解决方案,但您总是可以欺骗"它,将 select 包装在 div 中,并使用 :after 伪元素在 select 上放置一个假的 ... 来隐藏下面的内容:

                Not the cleanest solution but you could always "trick" it, wrapping the select inside a div, and use :after pseudoelement to position a fake ... over the select hidding the content below:

                .select {
                  box-sizing: border-box;
                  display: block;
                  width: 200px;
                  height: 34.5px;
                  padding: 5px 22px 3px 11px;
                  font: 400 16px/24px sans-serif;
                  color: #464a4c;
                  vertical-align: middle;
                  background: #fff url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiID8+CjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgd2lkdGg9IjEyIiBoZWlnaHQ9IjciPgoJPGRlZnM+CgkJPGNsaXBQYXRoIGlkPSJjbGlwXzAiPgoJCQk8cmVjdCB4PSItNDE1IiB5PSItNjYyIiB3aWR0aD0iMTQzNyIgaGVpZ2h0PSIyMjE2IiBjbGlwLXJ1bGU9ImV2ZW5vZGQiLz4KCQk8L2NsaXBQYXRoPgoJPC9kZWZzPgoJPGcgY2xpcC1wYXRoPSJ1cmwoI2NsaXBfMCkiPgoJCTxwYXRoIGZpbGw9InJnYig2NSw2NSw2NSkiIHN0cm9rZT0ibm9uZSIgZD0iTTAuNjUzNDQzIDQuNzY4MzdlLTA3TDExLjM0NjEgLTQuNzY4MzdlLTA3QzExLjk0MDIgLTQuNzY4MzdlLTA3IDEyLjE2ODIgMC41ODQ0ODggMTEuODY4MiAwLjkwNzY0OUw2LjU1MDMzIDYuNzE0MDRDNi4yNDczMSA3LjAzNjAzIDUuNzUzNzcgNy4xMTc3IDUuNDUwNzYgNi43OTQ1NEwwLjEzMjkxIDAuODY2ODE3Qy0wLjE3MDEwOSAwLjU0NDgyMyAwLjA2MjQwNTYgNC43NjgzN2UtMDcgMC42NTM0NDMgNC43NjgzN2UtMDciLz4KCTwvZz4KPC9zdmc+Cg==) no-repeat right 6px top 13px;
                  border: 1px solid #D6D6D6;
                  border-radius: 0;
                  -moz-appearance: none;
                  -webkit-appearance: none;
                  position:relative;
                
                }
                div {
                  position:relative;
                  display:inline-block;
                }
                div:after {
                      content: '...';
                    display: block;
                    background-color: #fff;
                    height: 15px;
                    width: 25px;
                    color: #464a4c;
                    position: absolute;
                    right: 23px;
                    bottom: 11px;
                    text-align: center;
                    pointer-events: none;
                }

                <div>
                <select class="select">
                  <option selected>select Mississippi Mississippi Mississippi Mississippi Mississippi</option>
                  <option value="1">1 Mississippi Mississippi Mississippi Mississippi Mississippi</option>
                  <option value="2">2 Mississippi Mississippi Mississippi Mississippi Mississippi</option>
                  <option value="3">3 Mississippi Mississippi Mississippi Mississippi Mississippi</option>
                </select>
                </div>

                我还添加了 pointer-events: none; 到元素,所以即使你点击它,它仍然会打开下面的选择.

                I have also added pointer-events: none; to the element so even if you click on it it will still open the select below.

                这篇关于是否可以仅使用 css 为 select 制作 text-overflow:ellipsis ?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:HTML5 数据属性排序 下一篇:在不刷新页面的情况下更改 HTML 代码

                相关文章

                    <tfoot id='ZHRYO'></tfoot>
                      <bdo id='ZHRYO'></bdo><ul id='ZHRYO'></ul>
                  1. <small id='ZHRYO'></small><noframes id='ZHRYO'>

                    <i id='ZHRYO'><tr id='ZHRYO'><dt id='ZHRYO'><q id='ZHRYO'><span id='ZHRYO'><b id='ZHRYO'><form id='ZHRYO'><ins id='ZHRYO'></ins><ul id='ZHRYO'></ul><sub id='ZHRYO'></sub></form><legend id='ZHRYO'></legend><bdo id='ZHRYO'><pre id='ZHRYO'><center id='ZHRYO'></center></pre></bdo></b><th id='ZHRYO'></th></span></q></dt></tr></i><div id='ZHRYO'><tfoot id='ZHRYO'></tfoot><dl id='ZHRYO'><fieldset id='ZHRYO'></fieldset></dl></div>
                    <legend id='ZHRYO'><style id='ZHRYO'><dir id='ZHRYO'><q id='ZHRYO'></q></dir></style></legend>