Answer the question
In order to leave comments, you need to log in
How can such less-constructs be optimized?
For example, there is a fairly heavily nested dom tree, and since quite often class names are repeated at different levels of nesting, there is not much opportunity to shorten selectors.
This is what the css for the generic selector should look like.
.ammenu-menu-wrapper.-desktop .ammenu-main-container .ammenu-items .ammenu-item.-main.-full .ammenu-submenu .ammenu-categories-container.ammenu-categories .ammenu-item.-child .ammenu-wrapper .ammenu-link.-level1 {
content: '';
width: 100%;
height: 150px;
background-size: 120px 120px !important;
background-repeat: no-repeat !important;
display: block;
padding-top: 120px;
}
.ammenu-menu-wrapper.-desktop .ammenu-main-container .ammenu-items .ammenu-item.-main.-full:nth-child(1) .ammenu-submenu .ammenu-categories-container.ammenu-categories .ammenu-item.-child:nth-child(1) .ammenu-wrapper .ammenu-link.-level1 {
background-image: url(/pub/media/wysiwyg/pp-shop/pp-mega-menue/mm_jahresplaketten.png);
}
.ammenu-menu-wrapper {
&.-desktop {
.ammenu-main-container {
.ammenu-items {
.ammenu-item {
&.-main {
&.-full {
.ammenu-submenu {
.ammenu-categories-container {
&.ammenu-categories {
.ammenu-item {
&.-child {
.ammenu-wrapper {
.ammenu-link {
&.-level1 {
content: '';
width: 100%;
height: 150px;
background-size: 120px 120px !important;
background-repeat: no-repeat !important;
display: block;
padding-top: 120px;
overflow: visible;
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
.ammenu-menu-wrapper {
&.-desktop {
.ammenu-main-container {
.ammenu-items {
.ammenu-item {
&.-main {
&.-full {
&:nth-child(1) {
.ammenu-submenu {
.ammenu-categories-container {
&.ammenu-categories {
.ammenu-item {
&.-child {
&:nth-child(1) {
.ammenu-wrapper {
.ammenu-link {
&.-level1 {
background-image: url(/pub/media/wysiwyg/pp-shop/pp-mega-menue/mm_jahresplaketten.png);
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
Answer the question
In order to leave comments, you need to log in
Answer: limit yourself to a maximum of double nesting.
There is no point in making steam locomotives. And if there is - you have problems with the architecture.
Read about BEM. It is not necessary to follow it, but it is useful for understanding such issues.
1. You can't do such heavily nested constructions. It's not readable and it's impossible to maintain.
2. If several elements use the same styles - they must have a common class, no need to duplicate styles.
3. Use BEM. There, the maximum nesting is limited and this will force you to design code differently
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question