¿Qué hay de nuevo en css?

Edición google I/O 2024

Making things move

pero antes de comenzar

información importante

la cascada

en css

<h1 class="title" id="title-id">Carmen Ansio</h1>

cascada - herencia - especificidad

h1 {
    font-family: serif;
}

#title-id {
    font-family: sans-serif;
}

.title {
    font-family: monospace;
}
<button>Carmen Ansio</button>

orden de aparición

button {
  color: red;
}

button {
  color: blue;
}
<div class=”pink purple”> Carmen Ansio </div>
<div class=”purple pink”> Carmen Ansio </div>
.pink {
	color: pink;
}

.purple {
	color: purple;
}

cascade layers

cascade layers

capas en cascada

custom properties

nesting nativo en css

.card {}
.card:hover {}

/* can be done with nesting like */
.card {
  &:hover {
    
  }
}

nesting nativo en css

table.colortable {
    & td {
        text-align: center;
        .c {
            text-transform: uppercase;
        }
        &:first-child,
        &:first-child + td {
            border: 1px solid black;
        }
	}
  & th {
          text-align: center;
          background: black;
          color: white;
  } 
}

nesting nativo en css

nesting nativo en css

unidades de viewport dinámicas

unidades viewport

unidades viewport

container queries

.card {
  display: grid;
  gap: 1rem;

  @container (width >= 480px) {
    display: flex;
  }
}

nesting nativo con container queries

container queries

style

queries

@container style(--sunny: true) {
 .weather-card {
   background: linear-gradient(-30deg, yellow, orange);
 }

 .weather-card:after {
   content: url(<data-uri-for-demo-brevity>);
   background: gold;
 }
}

style queries

style queries

:has()

pseudoclase

:has()

card :has

nueva sintaxis nth-of

nth-of syntax

scoped styles

@scope (.card) {
  .title { 
    font-weight: bold;
  }
}

scoped styles

scoped styles

propiedades

de texto

text-wrap balance

titulos balanceados

/* text-wrap: balance y pretty */
.headline {
  text-wrap: balance;
}

.headline-pretty {
  text-wrap: pretty;
}

balance y pretty

initial-letter

propiedad initial-letter

accent color para formularios

trabajando con imágenes

.video {
  width: 100%
  aspect-ratio: 16 / 9;
}

Propiedad aspect-ratio

.video {
  width: 100%;
  padding-top: 56.25%;
}
.img {
  aspect-ratio: 1;
  width: 300px;
  object-view-box: inset(25% 20% 15% 5%);
  object-fit: cover;
}

Propiedad object-viewbox

 /* 
La propiedad overflow: hidden;, 
posicionando y escalando el contenido 
en su interior.
 */
.grid-wrapper {
	display: grid;
	grid-gap: 10px;
	grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
	grid-auto-rows: 200px;
	grid-auto-flow: dense;
}

Caso de uso masonry

img {
	max-width: 100%;
	height: auto;
	vertical-align: middle;
	display: inline-block;
	mix-blend-mode: color-dodge;
}
.container {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  grid-template-rows: masonry;
}

masonry nativo

tipografias fluidas

funcion clamp()

h1 {
  --fluid-type-min: 2.5rem;
  --fluid-type-max: 5rem;
  --fluid-type-target: 5vw;

  max-width: 15ch;
}

h2 {
  --fluid-type-min: 1.8rem;
  --fluid-type-max: 3rem;
}

h3 {
  --fluid-type-min: 1.5rem;
  --fluid-type-max: 2.5rem;
}

h2,
h3 {
  max-width: 30ch;
}

p {
  max-width: 60ch;
}
/* clamp(min, val, max) */
width: clamp(200px, 50%, 500px);
h1,
h2,
h3,
p {
  font-size: clamp(
    var(--fluid-type-min, 1rem),
    calc(1rem + var(--fluid-type-target, 3vw)),
    var(--fluid-type-max, 1.3rem)
  );
}
@font-face {
  font-family: "JobClarendon";
  src: url("job-clarendon.woff2") format("woff2 supports variations"),
       url("job-clarendon.woff2") format("woff2-variations");
  font-weight: 100 1000;
}

Formato variable fonts

:root {
  --font-fallback: "Helvetica Neue", sans-sans;
}

h1, h2 {
  font-family: "JobClarendon", var(--font-fallback);
}

google i/o 2024 ui & css

light-dark función

light-dark

:root {
  --primary-color: #333;
  --primary-background: #e4e4e4;
  --highlight-color: hotpink;
}

@media (prefers-color-scheme: dark) {
  :root {
    --primary-color: #fafafa;
    --primary-background: #121212;
    --highlight-color: lime;
  }
}
:root {
  color-scheme: light dark;
  --primary-color: light-dark(#333, #fafafa);
  --primary-background: light-dark(#e4e4e4, #121212);
  --highlight-color: light-dark(hotpink, lime);
}

mejorando componentes

uso de hr en un select

<!-- Uso de hr en un select -->
<select>
  <option>Opción 1</option>
  <option>Opción 2</option>
  <hr>
  <option>Opción 3</option>
</select>

Pseudo clases user-valid y user-invalid

/* Pseudo clases user-valid y user-invalid */
input:user-valid {
  border-color: green;
}

input:user-invalid {
  border-color: red;
}

Posicionamiento de anclaje

/* Posicionamiento de anclaje */
.button {
  position: absolute;
  anchor-name: tooltip-anchor;
}

.tooltip {
  position: anchor;
  anchor: tooltip-anchor bottom;
}

definición de popover sin js

<!-- Definición de popover -->
<button popover-target="info">Info</button>
<div id="info" popover>
  Información adicional
</div>

animaciones scroll-driven

.progress {
  animation: progress both linear;
  animation-timeline: scroll(root);
  transform-origin: 0 50%;
  }
  @keyframes progress {
    0% {
      scale: 0 1;
  }
  100% {
  scale: 1 1; }
}

Propiedad animation-timeline

¿a quién seguir?

devrel lead google

una kravets

@una

devrel google

adam argyle

@argyleink

chrome devrel google

bramus

@bramus

muchísimas gracias

¿Qué hay de nuevo en CSS? Edición 2024

By Carmen Ansio

¿Qué hay de nuevo en CSS? Edición 2024

  • 334