Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

178
Vistas
Select options - long text to be shown multiline

I'm dealing with an issue that I can't find a solution for this simple problem that bugs me. I have a select form on my single product page ( using woocommerce ) for selecting the variation of the product. I found out that this select is created in variable.php file with wc_dropdown_variation_attribute_options. Is there any way, for longer text in options, that text to be shown in multiline? For example, if select field have width 200px, I need all of the options to have the same width, and the ones who have long text, to be shown in multiline. I have searched and tried everything but without success. Is this possible? For now, the only solution I've found is to split the strings that have length bigger than the one specified, but on that way the text is getting trimmed and I want to show the whole text but in multiple lines. Thanks!

Here is the code for the select field:

    <table class="variations table" cellspacing="0">
    <tbody>
    <tr>
    <td class="label"><label for="online">Product Variations</label></td>
    <td class="value">
    <select id="online" class="" name="attribute_online" data-attribute_name="attribute_online" data-show_option_none="yes">
<option value="" title="Choose an option">Choose an option</option>
<option value="shorttext" title="shorttext" class="attached enabled">Short text</option>
<option value="VeryLongText" title="VeryLongText" class="attached enabled">VeryLongText</option>
</select>
</td>
</tr>
</tbody>
</table>

And here are two things that I've tried with css but with no success:

option {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
} 
 select > option{
  max-width: 200px !important;
  box-sizing: border-box;
  white-space: normal;
  word-wrap: break-word;
} 

The only thing that works is this Java script code, but it just trims the text if longer than 35, and this don't solve my issue:

    var optionText, array = [], newString, maxChar = 35;
$('select').each(function(){
    $(this).find('option').each(function(i,e) {
        $(e).attr('title',$(e).text());
        optionText = $(e).text();
        newString = '';
        if (optionText.length > maxChar) {
            array = optionText.split(' ');
            $.each(array,function(ind,ele) {
                newString += ele+' ';
                if (ind > 0 && newString.length > maxChar) {
                  newString += '...';

                    $(e).text(newString);
                    return false;
                }
            });

        }
    });
});
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda