При выполнении этого экземпляра я пришел к идее «оптимизировать» код, пытаясь избежать использования селектора классов ».white-text» и настройки свойства «цвет: белый», используя селектор классов ».inner-box» вместо этого. Затем код выглядит следующим образом: < /p>
`
CSS Cascade
Yellow Text
White Text
Yellow Text
White Text
`
< /code>
.box { /* E */
background-color: blue;
padding: 10px;
}
p {
color: yellow; /* C */
margin: 0;
padding: 0;
}
.inner-box { /* F */
background-color: red;
color: white; /* D */
}
#outer-box {
background-color: purple;
}
< /code>
According to my understanding here the html element ("A" in the code) is less specific than the class selector ("D" in the code). But the text still displays not white but yellow, indicating that im wrong. So then i thought "maybe the style.css defines the styling, but the html applies it and in the html the is set to "yellow" ("B" in the code) because of the style for elements is applied after the "A" therefore overrides it (Position rule - in the .html - instead of Specifity rule)". That would indicate that the order in which the styling is applied inside the html is the determining factor. But then I see this: If we invert the order for "E" and "F", like the following code, then the it is the style.css's order (Position rule - in the .css -) the determinig factor and not the applied order in the html:
.inner-box { /* F */
background-color: red;
}
.box { /* E */
background-color: blue;
padding: 10px;
}
p {
color: yellow;
margin: 0;
padding: 0;
}
.white-text {
color: white;
}
#outer-box {
background-color: purple;
}
< /code>
Can someone please clarify what's going on here?
Подробнее здесь: https://stackoverflow.com/questions/796 ... se-and-why
Какой CSS Cassade имеет распространенность в этом случае и почему? [дублировать] ⇐ CSS
Разбираемся в CSS
1749415435
Anonymous
При выполнении этого экземпляра я пришел к идее «оптимизировать» код, пытаясь избежать использования селектора классов ».white-text» и настройки свойства «цвет: белый», используя селектор классов ».inner-box» вместо этого. Затем код выглядит следующим образом: < /p>
`
CSS Cascade
Yellow Text
White Text
Yellow Text
White Text
`
< /code>
.box { /* E */
background-color: blue;
padding: 10px;
}
p {
color: yellow; /* C */
margin: 0;
padding: 0;
}
.inner-box { /* F */
background-color: red;
color: white; /* D */
}
#outer-box {
background-color: purple;
}
< /code>
According to my understanding here the html element ("A" in the code) is less specific than the class selector ("D" in the code). But the text still displays not white but yellow, indicating that im wrong. So then i thought "maybe the style.css defines the styling, but the html applies it and in the html the is set to "yellow" ("B" in the code) because of the style for elements is applied after the "A" therefore overrides it (Position rule - in the .html - instead of Specifity rule)". That would indicate that the order in which the styling is applied inside the html is the determining factor. But then I see this: If we invert the order for "E" and "F", like the following code, then the it is the style.css's order (Position rule - in the .css -) the determinig factor and not the applied order in the html:
.inner-box { /* F */
background-color: red;
}
.box { /* E */
background-color: blue;
padding: 10px;
}
p {
color: yellow;
margin: 0;
padding: 0;
}
.white-text {
color: white;
}
#outer-box {
background-color: purple;
}
< /code>
Can someone please clarify what's going on here?
Подробнее здесь: [url]https://stackoverflow.com/questions/79658159/which-css-cascade-has-prevalence-in-this-case-and-why[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия