1. Web
  2. CSS
  3. Guides
  4. Mehrspaltiges Layout

Dieser Inhalt wurde automatisch aus dem Englischen übersetzt, und kann Fehler enthalten. Erfahre mehr über dieses Experiment.

View in English Always switch to English

CSS mehrspaltiges Layout

Das CSS mehrspaltige Layout Modul ermöglicht es Ihnen, Inhalte über mehrere Spalten zu verteilen. Mit den Eigenschaften in diesem Modul können Sie die gewünschte Anzahl und Breite der Spalten, die Größe des Zwischenraums zwischen den Spalten und das visuelle Erscheinungsbild der optionalen Spaltentrennlinien (bekannt als Spaltenregeln) definieren. Sie können auch festlegen, wie der Inhalt von Spalte zu Spalte fließen soll und wie der Inhalt zwischen den Spalten aufgeteilt werden soll.

Mehrspaltiges Layout in Aktion

In diesem Beispiel wird die Rede von 1967 zum kanadischen Jubiläum, A Lament for Confederation, von Chief Dan George über mehrere Spalten angezeigt, ähnlich wie Artikel in gedruckten Zeitungen. Wenn Sie JavaScript aktiviert haben, ermöglichen Ihnen Steuerungen, die bevorzugte Spaltenanzahl und -breite, die Breite des Zwischenraums zwischen den Spalten, ob der Titel und ein Beispiel-Blockzitat in einer einzigen Spalte enthalten sein sollten oder über alle Spalten hinweg gespannt werden sollen, und ob das Aufteilen innerhalb der Absätze vermieden werden soll, zu ändern.

<article>
 <div class="title">
 <h1>A Lament for Confederation</h1>
 <p>&mdash;Chief Dan George, 1967</p>
 </div>
 <p>
 How long have I known you, Oh Canada? A hundred years? Yes, a hundred years.
 And many, many tides more. And today, when you celebrate your hundred years,
 Oh Canada, I am sad for all the Indian people throughout the land.
 </p>
 <p>
 For I have known you when your forests were mine; when they gave me my meat
 and my clothing. I have known you in your fruits and rivers where your fish
 flashed and danced in the sun, where the waters said 'come and eat of my
 abundance.' I have known you in the freedom of your winds. And my spirit,
 like your winds, once roamed this good lands.
 </p>
 <blockquote>
 <p>
 But in long the hundred years since the white man came, I have seen that
 freedom disappear just like the salmon going mysteriously out to sea.
 </p>
 </blockquote>
 <p>
 The white man's strange customs I could not understand, pressed down upon me
 until I could no longer breathe.
 </p>
 <p>
 When I fought to protect my home and my land, I was called a savage. When I
 neither understood nor welcomed this new way of life, I was called lazy.
 When I tried to rule my people, I was stripped of my authority.
 </p>
 <p>
 My nation was ignored in your history textbooks – we were less important in
 the history of Canada than the buffalo that ranged the plains. I was
 ridiculed in your plays and motion pictures, and when I drank your
 fire-water, I got drunk – very, very drunk. And I forgot.
 </p>
 <p>
 Oh Canada, how can I celebrate with you this centenary, this hundred years?
 Shall I thank you for the reserves that are left me of my beautiful forests?
 Shall I thank you for the canned fish of my rivers? Shall I thank you for
 the loss of my pride and authority, even among my own people? For the lack
 of my will to fight back? No! I must forget what is past and gone.
 </p>
 <p>
 Oh God in heaven! Give me the courage of the olden chiefs. Let me wrestle
 with my surroundings. Let me once again, as in the days of old, dominate my
 environment. Let me humbly accept this new culture and through it rise up
 and go on.
 </p>
 <p>
 Oh god, like the thunderbird of old, I shall rise again out of the sea. I
 shall grab the instruments of the white man's success – his education, his
 skills, and with these new tools I shall build my race into the proudest
 segment of your society. And, before I follow the great chiefs who have gone
 before us, I shall see these things come to pass.
 </p>
 <p>
 I shall see our young braves and our chiefs sitting in the house of law and
 government, ruling and being ruled by the knowledge and freedoms of our
 great land. So shall we shatter the barriers of our isolation. So shall the
 next hundred years be the greatest in the proud history of our tribes and
 nations.
 </p>
</article>
<fieldset id="options" class="open">
 <legend>
 <button aria-expanded="true" aria-controls="controls">
 Column options
 </button>
 </legend>
 <div id="controls">
 <p>
 <input type="range" min="0" max="5" value="5" id="colCount" />
 <label for="colCount">Max # of columns:</label>
 </p>
 <p>
 <input type="range" min="2" max="40" value="10" step="2" id="colWidth" />
 <label for="colWidth">Min width of columns:</label>
 </p>
 <p>
 <input type="range" min="0" max="10" value="1" step="0.5" id="gapSize" />
 <label for="gapSize">Gap size:</label>
 </p>
 <p>
 <input type="checkbox" checked id="colSpan" />
 <label for="colSpan">Byline spans all columns</label>
 </p>
 <p>
 <input type="checkbox" id="blockSpan" />
 <label for="blockSpan">Blockquote spans all columns</label>
 </p>
 <p>
 <input type="checkbox" id="colFill" />
 <label for="colFill">Balance columns</label>
 </p>
 <p>
 <input type="checkbox" id="break" />
 <label for="break">Don't break paragraphs</label>
 </p>
 </div>
</fieldset>
const page = document.querySelector("article");
const title = document.querySelector(".title");
const options = document.querySelector("#options");
const legend = document.querySelector("#options > legend");
const legendBtn = document.querySelector("#options > legend > button");
const blockquote = document.getElementsByTagName("blockquote")[0];
const colCount = document.getElementById("colCount");
const colWidth = document.getElementById("colWidth");
const gapSize = document.getElementById("gapSize");
const colSpan = document.getElementById("colSpan");
const blockSpan = document.getElementById("blockSpan");
const colFill = document.getElementById("colFill");
const breakP = document.getElementById("break");
// make options visible if js is enabled
options.style.display = "revert";
legendBtn.addEventListener("click", () => {
 showAndHideMenu();
});
colCount.addEventListener("change", () => {
 page.style.columnCount = colCount.value;
});
colWidth.addEventListener("change", () => {
 page.style.columnWidth = `${colWidth.value}em`;
});
gapSize.addEventListener("change", () => {
 page.style.gap = `${gapSize.value}em`;
});
colSpan.addEventListener("change", () => {
 setColSpan(colSpan, title);
});
blockSpan.addEventListener("change", () => {
 setColSpan(blockSpan, blockquote);
});
colFill.addEventListener("change", () => {
 if (colFill.checked) {
 page.style.columnFill = "balance";
 } else {
 page.style.columnFill = "auto";
 }
});
breakP.addEventListener("change", () => {
 if (breakP.checked) {
 page.classList.add("breakInside");
 } else {
 page.classList.remove("breakInside");
 }
});
function showAndHideMenu() {
 if (legendBtn.getAttribute("aria-expanded") === "true") {
 // close it
 legendBtn.setAttribute("aria-expanded", "false");
 legend.classList.add("closed");
 legend.classList.remove("open");
 } else {
 // open it
 legendBtn.setAttribute("aria-expanded", "true");
 legend.classList.remove("closed");
 legend.classList.add("open");
 }
}
function setColSpan(control, element) {
 if (control.checked) {
 element.style.columnSpan = "all";
 } else {
 element.style.columnSpan = "none";
 }
}
article {
 column-count: 5;
 column-width: 8em;
 widows: 3;
 orphans: 3;
 gap: 1em;
 column-rule: 2px dashed #666666;
 height: 50em;
}
.title {
 column-span: all;
 display: flex;
 align-items: baseline;
 gap: 1em;
 flex-wrap: wrap;
}
p {
 margin: 0 0 1em 0;
 line-height: 1.4;
}
.breakInside * {
 break-inside: avoid;
}
#options {
 position: fixed;
 top: 1rem;
 right: 1rem;
 background: white;
 display: none;
}
fieldset p {
 margin-bottom: 0.25em;
}
legend {
 position: relative;
 top: 0;
 transition: 200ms;
}
legend.closed {
 top: 0.75em;
}
legend.closed + #controls {
 display: none;
}
legend {
 background-color: #dedede;
 padding: 0.5em;
}
legend > button {
 all: unset;
 cursor: pointer;
}
legend.closed {
 margin: -1em;
 display: inline-block;
}
blockquote {
 border: 2px dashed red;
 margin: 0 0 0.25em 0;
}
blockquote p {
 margin-bottom: 0;
}
blockquote p::before,
blockquote p::after {
 content: '"';
 font-size: 1.2em;
 vertical-align: baseline;
 color: red;
}

Hinweis: Mehrspaltiges Layout steht in engem Zusammenhang mit Seitenmedien. Jede Spaltenbox ist ein Fragment, ähnlich wie jede gedruckte Seite ein Fragment eines Dokuments ist. Mithilfe der im Modul CSS-Fragmentierung definierten Eigenschaften können Sie steuern, wie Inhalte zwischen Spalten und Seiten aufgeteilt werden.

Referenz

Eigenschaften

Hinweis: Beachten Sie, dass das Setzen der Containerhöhe und der Zeilenlänge Herausforderungen für Menschen mit Seh- oder kognitiven Behinderungen darstellen kann. WCAG Erfolgskriterium 1.4.8 besagt, dass auch bei verdoppelter Schriftgröße der Inhalt nicht gescrollt werden sollte.

Selektoren und Pseudoelemente

Leitfäden

Grundkonzepte von mehrspaltigen Layouts

Übersicht über die Spezifikation des mehrspaltigen Layouts.

Verwendung von mehrspaltigen Layouts

Anleitung zur Verwendung von mehrspaltigen Eigenschaften zur Texterstellung.

Stilierung von Spalten

Anleitung zur Stilierung von Spalten und zur Verwaltung des Abstands zwischen Spalten.

Spannweite und Balance

Wie Sie Elemente über alle Spalten spannen und die Füllung der Spalten steuern können.

Umgang mit Überläufen in mehrspaltigen Layouts

Was passiert, wenn ein Element die Spalte, in der es sich befindet, überläuft und was passiert, wenn zu viel Spalteninhalt vorhanden ist, um in einen Container zu passen.

Umgang mit Inhaltsunterbrechungen in mehrspaltigen Layouts

Einführung in die Fragmentierungsspezifikation und wie gesteuert werden kann, wo Spalteninhalte unterbrochen werden.

Erstellung von CSS-Karussellen

Erstellen Sie reine CSS-Karussell-Benutzeroberflächenfunktionen mit Scroll-Buttons, Scroll-Markern und erzeugten Spalten.

Verwandte Konzepte

CSS-Gaps Modul

CSS-Fragmentierung Modul

CSS-Box-Ausrichtung Modul

CSS-Box-Modellierung Modul

CSS-Überlauf Modul

CSS-Display Modul

Spezifikationen

Spezifikation
CSS Multi-column Layout Module Level 1
CSS Multi-column Layout Module Level 2

Siehe auch

Help improve MDN

Erfahren Sie, wie Sie beitragen können Diese Seite wurde automatisch aus dem Englischen übersetzt.

AltStyle によって変換されたページ (->オリジナル) /