CSS blokkeren
Maak een nieuw CSS-bestand in de map van het blok met de naam van het blok als bestandsnaam. Bijvoorbeeld, voor het meetapparaat blok, wordt het dossier gevestigd bij /blocks/teaser/teaser.css
.
Dit CSS-bestand wordt automatisch geladen wanneer de JavaScript van Edge Delivery Services een DOM-element detecteert op de pagina die een teasblok vertegenwoordigt.
/blocks/teaser/teaser.css
/* /blocks/teaser/teaser.css */
/* Scope each selector in the block with `.block.teaser` using CSS nesting (https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_nesting) to avoid accidental conflicts outside the block */
.block.teaser {
animation: teaser-fade-in .6s;
position: relative;
width: 1600px;
max-width: 100vw;
left: 50%;
transform: translateX(-50%);
height: 500px;
overflow: hidden;
/* The image is rendered to the first div in the block */
picture {
position: absolute;
z-index: -1;
inset: 0;
box-sizing: border-box;
img {
object-fit: cover;
object-position: center;
width: 100%;
height: 100%;
}
}
/**
The teaser's text is rendered to the second (also the last) div in the block.
These styles are scoped to the second (also the last) div in the block (.block.teaser > div:last-child).
This div order can be used to target different styles to the same semantic elements in the block.
For example, if the block has two images, we could target the first image with `.block.teaser > div:first-child img`,
and the second image with `.block.teaser > div:nth-child(2) img`.
**/
& > div:last-child {
position: absolute;
bottom: 0;
left: 50%;
transform: translateX(-50%);
background: var(--background-color);
padding: 1.5rem 1.5rem 1rem;
width: 80vw;
max-width: 1200px;
/**
The following elements reside within `.block.teaser > div:last-child` and could be scoped as such, for example:
.block.teaser > div:last-child p { .. }
However since these element can only appear in the second/last div per our block's model, it's unnecessary to add this additional scope.
**/
/* Regardless of the authored heading level, we only want one style the heading */
h1,
h2,
h3,
h4,
h5,
h6 {
font-size: var(--heading-font-size-xl);
margin: 0;
}
h1::after,
h2::after,
h3::after,
h4::after,
h5::after,
h6::after {
border-bottom: 0;
}
p {
font-size: var(--body-font-size-s);
margin-bottom: 1rem;
}
/* Add underlines to links in the text */
a:hover {
text-decoration: underline;
}
/* Add specific spacing to buttons. These button CSS classes are automatically added by Edge Delivery Services. */
.button-container {
margin: 0;
padding: 0;
.button {
background-color: var(--primary-color);
border-radius: 0;
color: var(--dark-color);
font-size: var(--body-font-size-xs);
font-weight: bold;
padding: 1em 2.5em;
margin: 0;
text-transform: uppercase;
}
}
}
}
/** Animations
Scope the @keyframes to the block (teaser) to avoid accidental conflicts outside the block
Global @keyframes can defines in styles/styles.css and used in this file.
**/
@keyframes teaser-fade-in {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
Ontwikkelvoorbeeld
Aangezien CSS in het codeproject wordt geschreven, is het hete herladen van AEM CLI de veranderingen, die het snel en gemakkelijk maken om te begrijpen hoe CSS het blok beïnvloedt.
Uw code plaatsen
Zorg ervoor u vaakuw codescheidingen plukt om het schoon en verenigbaar te verzekeren. Met koppelingen worden problemen vroegtijdig afgevangen en de totale ontwikkeltijd verkort. U kunt uw ontwikkelingswerk niet samenvoegen tot main
totdat alle problemen met koppelingen zijn opgelost.
# ~/Code/aem-wknd-eds-ue
$ npm run lint:css
Voorvertoning in Universal Editor
Als u wijzigingen wilt weergeven in de AEM Universal Editor, voegt u deze toe, past u ze toe en duwt u ze door naar de vertakking Git-opslagplaats die door de Universal Editor wordt gebruikt. Deze stap helpt ervoor te zorgen dat de blokimplementatie de ontwerpervaring niet verstoort.
# ~/Code/aem-wknd-eds-ue
$ git add .
$ git commit -m "Add CSS-only implementation for teaser block"
$ git push origin teaser
U kunt nu een voorvertoning van de wijzigingen weergeven in de Universal Editor wanneer u de queryparameter ?ref=teaser
toevoegt.