Scroll bar in a SELECT in html

Asked

Viewed 568 times

0

Talk to you guys, I have a SELECT in my HTML that when the results exceed the width limit, it breaks a line. I would like instead of breaking this line, to be added a scroll bar.

Explanatory image: inserir a descrição da imagem aqui

DEMO PAGE

What css properties should I use? grateful, a big hug!

  • 1

    Hello Caio, could post as is your code?

  • I added a demo page.

  • 1

    But put the code, it is easier to adjust... It will probably have to be with javascript... Edit and add the javascript tag as well...

  • 2

    Caio, your problem is with Select2, which you are using. You did not mention this at the beginning, and if you edit it now you will invalidate the answers. I advise you to choose one that you think will suit you better, and create another question specifying the use of the plugin.

3 answers

3

The input I don’t know, but you can use the textarea:

textarea
{
    height:30px;
    overflow-y:hidden;
    overflow-x: auto;
    white-space: nowrap;
    resize: none;
    border-radius:5px;
}
<textarea>fffffffffffffffffffffffffffffffffffffffffffffffffffffffhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh</textarea>

Edit

As mentioned by @Felipe Nascimento, it is not possible to place elements from the input nor in the textarea as #PCDATA (processed Character data). You will need to use a div even...

3


Can use overflow-x and white-space: nowrap;, note that the elements have to use display: inline-block;, I believe this doesn’t work with float, then remove it from its elements.

In case your code would look like this (it uses the Select2):

/* itens dentro do select2 */
.select2-selection--multiple .select2-search--inline {
    float: none;/*"remove" o float*/
    display: inline-block;
}

/* área para digitar dentro do select2 */
.select2-selection--multiple .select2-selection__choice {
    float: none;
    display: inline-block;
}

/* área aonde ficam os items e o campo para digitar */
.select2-selection--multiple .select2-selection__rendered {
    overflow-x: auto;
}

An example to see the effect (and that will be useful to future visitors of the question)

.area {
   border: 1px #ccc solid;
   padding: 5px;
   width: 400px;
   overflow-x: auto;
   white-space: nowrap;
}
.area > .item {
    border-radius: 2px;
    background-color: #455a64;
    display: inline-block;
    margin: 0 0 0 2px;
    padding: 5px;
    color: #fff;
}
.area > .item:last-child {
    margin: 0;
}
<div class="area">
    <div class="item">
        Memes
    </div>
    <div class="item">
        Programação
    </div>
    <div class="item">
        Entretenimento
    </div>
    <div class="item">
        Stack Overflow
    </div>
    <div class="item">
        Super User
    </div>
    <div class="item">
        Stack Exchange
    </div>
    <div class="item">
        C#
    </div>
    <div class="item">
        asp.net
    </div>
    <div class="item">
        asp.net-mvc
    </div>
</div>

  • 1

    you’re a monster, thanks friend!

  • is from the monsters S/O lol...

2

  • 1

    And in the case of a input type="text", knows how to proceed ?

  • 1

    There is no way to put other elements inside an input, it may be using some library that simulates tags, such as Bootstrap Tags Input for example.

  • I added a demo page. http://b2bi.com.br/B2BI2017/app/demo.html

Browser other questions tagged

You are not signed in. Login or sign up in order to post.