2

Tengo un select que cuando se elije una opción, debe mostrar en un div el detalle de dicha opción.

EL div debe ocupar todo el ancho disponible, pero en vertical debe hacer visibles en forma fija un máximo 5 líneas. Si la descripción ocupa más de 5 líneas, con el scroll vertical debe poder ir desplazándose para ver las restantes líneas del detalle.

El problema es que no he dado en cómo poder definir el máximo de las 5 líneas a mostrar en el DIV, por lo cual el tamaño vertical crece y no es el comportamiento que necesito. Para el div puse:

                                <div class="container-fluid row">
                                <div class="col-12 align-self-start">
                                    <p>DETALLE DE LA SELECCION</p>
                                </div>
                                <div id="detalleseleccion" name="detalleseleccion" style="overflow-x: hidden; overflow-y: scroll; width: 100%; border: 1px solid">
                                    <p>There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc.There are many </p>
                                    </div>
                            </div>

Esa es la salida que estoy obteniendo:

introducir la descripción de la imagen aquí

1
  • Esto es solo una sugerencia pero, si solamente es para mostrar podrias utilizar un textarea con atributos disabled-rows="4" para obtener lo que quieres. el 6 ene. 2021 a las 15:54

2 respuestas 2

1

para el resultado que estás esperando, he usado height y line-height,
El primero para limitar las filas, y el segundo para el tamaño del texto. Es decir que si duplicas el tamaño del texto, debes duplicar la altura y así.

Agrego que he quitado el texto de dentro de <p> dado que este agrega una línea extra al div.

.este {
  height: 5em;
  line-height: 1em;
  overflow-x: hidden;
  overflow-y: scroll;
  width: 100%;
  border: 1px solid;
}
<div class="container-fluid row">
  <div class="col-12 align-self-start">
    <p>DETALLE DE LA SELECCION</p>
  </div>
  <div id="detalleseleccion" name="detalleseleccion" class="este">
    There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc.There are many
  </div>
</div>

1
  • 1
    muchas gracias, funcionó muy bien. el 6 ene. 2021 a las 16:12
0

Solo basta con agregar un 'height' del tamaño que desees o te quede bien en tu pagina. Yo le puse 5em (5 lineas). Tambien debes agregar un 'overflow-y: auto'. Prueba con lo siguiente:

<div class="container-fluid row">
                                <div class="col-12 align-self-start">
                                    <p>DETALLE DE LA SELECCION</p>
                                </div>
                                <div id="detalleseleccion" name="detalleseleccion" style="overflow-x: hidden; overflow-y: auto; height: 5em; border: 1px solid"><p>There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc.There are many </p>
                                    </div>
                            </div>

3
  • Por favor recuerda añadir que cambios has hecho, y como has logrado obtener el resultado. Ahora, creo que solo has limitado el tamaño del div a 100px, corrigeme si no es así. Si el texto cambia de tamaño, la regla se rompera.
    – Excorpion
    el 6 ene. 2021 a las 15:01
  • Ok, lo has hecho, pero recuerda no copiarte de otros ejercicios. Si alguien lo ha hecho de mejor manera, recomiendo (por que yo lo he hecho) borrar la respuesta para evitar duplicados y demases. Además, aún no controlas la excepción donde cambie el tamaño del texto.
    – Excorpion
    el 6 ene. 2021 a las 15:04
  • 1
    muchas gracias, funciona bien. el 6 ene. 2021 a las 16:13

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.