width
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
Das width
CSS Media-Feature kann verwendet werden, um die Breite des Viewports (oder des Seitenrahmens, für paginierte Medien) zu testen.
Syntax
Das width
-Feature wird als <length>
-Wert angegeben, der die Breite des Viewports repräsentiert. Es ist ein Bereichs-Feature, was bedeutet, dass Sie auch die mit Präfix versehenen Varianten min-width
und max-width
verwenden können, um Mindest- bzw. Höchstwerte abzufragen.
Beispiele
HTML
html
<div>Watch this element as you resize your viewport's width.</div>
CSS
css
/* Exact width */
@media (width: 360px) {
div {
color: red;
}
}
/* Minimum width */
@media (min-width: 35rem) {
div {
background: yellow;
}
}
/* Maximum width */
@media (max-width: 50rem) {
div {
border: 2px solid blue;
}
}
Ergebnis
Spezifikationen
Specification |
---|
Media Queries Level 4 # width |