Skip to content

Instantly share code, notes, and snippets.

@teffcode
Last active November 11, 2021 00:45
Show Gist options
  • Save teffcode/db06eeb094ffc3fd959eaf9e731b53bf to your computer and use it in GitHub Desktop.
Save teffcode/db06eeb094ffc3fd959eaf9e731b53bf to your computer and use it in GitHub Desktop.

馃憢馃徏 Welcome 馃憢馃徏

Quiz banner

Instagram | Twitter | LinkedIn


Choose your language 馃憛



English version 馃殌


What would be the width for the peach element considering the following code (HTML and CSS) and a Viewport width of 900px: A, B or C?



Click here to see the correct answer and explanation 馃憖
Correct Answer Explanation
C The browser has to choose the smallest of the values (50%, 500px). Choosing that depends on the viewport width. If 50% computes to a value more than 500px, then it will be ignored and 500px will be used instead. Otherwise, if the 50% computes to a value less than 500px, then the 50% will be used as a value for the width. Can you guess the viewport width that will make that happen? (The 50% of X = 500px). The viewport width is 1000px.

Explicaci贸n basada en 馃憠馃徏 min(), max(), and clamp() CSS Functions

Code:

HTML:

<div class="馃崙"></div>

CSS:

.馃崙 {
  background: PeachPuff;
  height: 100px;
  width: min(50%, 500px);
}

CodePen



Spanish version 馃殌


驴Cu谩l ser铆a el width para el elemento peach teniendo en cuenta el siguiente c贸digo (HTML y CSS) y un Viewport width de 900px: A, B o C?



Haz click aqu铆 para ver la respuesta correcta y su explicaci贸n 馃憖
Respuesta correcta Explicaci贸n
C min() hace que el navegador tenga que elegir el valor m谩s peque帽o dentro de esta funci贸n (ya sea 50% o 500px). Elegir esto depende del ancho del Viewport. Entonces, lo que el navegador hace es el siguiente c谩lculo: 50% de 900px = 450px, y se pregunta: Cu谩l es el valor m谩s peque帽o, 450px o 500px ? Y de ah铆, escoge el valor m谩s peque帽o (como te mencion茅 al principio) y lo pone en el width del elemento 馃崙

Explicaci贸n basada en 馃憠馃徏 min(), max(), and clamp() CSS Functions

C贸digo completo:

HTML:

<div class="馃崙"></div>

CSS:

.馃崙 {
  background: PeachPuff;
  height: 100px;
  width: min(50%, 500px);
}

CodePen



@Osstrax
Copy link

Osstrax commented Nov 11, 2021

La respuesta es la C

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment