div class = " div-3" > div> Note that you have added the class as an attribute to the tag by adding the class attribute and class name to each opening tag. Save the file and reload it in your browser. You should receive something like this:
Adding and Styling Text in a Container
You can put text inside a container by inserting text in between the opening and closing tags. Try adding text inside each of the elements in your index.html file:
div class = " div-1" > Blue div> div class = " div-2" > Red div> div class = " div-3" > Yellow div>
Save the file and reload it in your browser. You should now have text displayed in each of your containers:
You can add additional HTML elements to your text inside the elements. For example, try adding the HTML heading tags ( to ) to your text inside the tags in your index.html file:
div class = " div-1" > h2 > Blue h2> div> div class = " div-2" > h3 > Red h3> div> div class = " div-3" > h4 > Yellow h4> div>
Save the file and reload it in your browser. The text inside the containers should now be styled according to the default properties of the to tags:
Note that the elements have also adjusted their positions slightly. This repositioning is caused by the default margin properties of the through elements. You’ll learn more about margins in the next tutorial on the CSS Box Model, but for now it is fine to ignore them
To style text inside the containers, you can specify text property values in the rulesets for your classes. Try adding the properties and values to your rulesets in your styles.css file as highlighted in the in the following code snippet:
.div-1 background-color : blue ; height : 50 px ; width : 50 px ; font-size : 10 px ; color : white ; iu > .div-2 background-color : red ; height : 100 px ; width : 100 px ; font-size : 20 px ; color : yellow ; > .div-3 background-color : yellow ; height : 200 px ; width : 200 px ; font-size : 30 px ; color : blue ; >
Save your styles.css file and reload the index.html file in your browser. The text inside the containers should now be styled according to the CSS rules in your styles.css file:
Источник
content Свойство, с помощью которого можно добавить на страницу то, чего нет в HTML-разметке.
Время чтения: меньше 5 мин
Кратко Скопировать ссылку «Кратко» Скопировано
Когда задано свойство content , то элемент заменяется на значение этого свойства. В качестве значения могут быть переданы различные типы: изображение, градиент или текст.
Пример Скопировать ссылку «Пример» Скопировано
a::after content: "👉"; margin-right: 5px; >
a::after content : "👉" ; margin-right : 5 px ; >
Скопировать Скопировано Не удалось скопировать Как пишется Скопировать ссылку «Как пишется» Скопировано
Изображение в качестве содержимого. Может применяться к любому элементу.
div content: url("http://www.example.com/test.png"); >
div content : url ( "http://www.example.com/test.png" ) ; >
Скопировать Скопировано Не удалось скопировать Все значения ниже могут применяться ТОЛЬКО к псевдоэлементам : : before и : : after .
div::before content: "prefix"; >
div::before content : "prefix" ; >
Скопировать Скопировано Не удалось скопировать Значения счётчиков с использованием функций counter ( ) и counters ( ) :
div::before content: counter(chapter_counter); > div::before content: counters(section_counter, "."); >
div::before content : counter ( chapter_counter) ; > div::before content : counters ( section_counter, "." ) ; >
Скопировать Скопировано Не удалось скопировать Значения HTML-атрибутов с использованием функции attr ( ) :
div::before content: attr(value string); >
div::before content : attr ( value string) ; >
Скопировать Скопировано Не удалось скопировать Ключевые слова, зависящие от языка страницы и положения в тексте:
div::before content: open-quote; content: close-quote; content: no-open-quote; content: no-close-quote; >
div::before content : open-quote; content : close-quote; content : no-open-quote; content : no-close-quote; >
Скопировать Скопировано Не удалось скопировать Использование нескольких значений одновременно. Исключение — ключевые слова normal и none :
div::before content: open-quote counter(chapter_counter); >
div::before content : open-quote counter ( chapter_counter) ; >
Скопировать Скопировано Не удалось скопировать Ключевые слова, которые нельзя комбинировать с другими значениями:
div::before content: normal; content: none; >
div::before content : normal; content : none; >
Скопировать Скопировано Не удалось скопировать Как понять Скопировать ссылку «Как понять» Скопировано
Чаще всего свойство content применяется к псевдоэлементам : : before и : : after . В зависимости от значения свойства псевдоэлемент принимает тот или иной вид:
Если значением является просто строка, то она подставляется на место псевдоэлемента. Как правило, это до или после текстового содержимого тега. Есть несколько зарезервированных слов, которые также можно указывать в качестве значения. Используются они как совместно со свойством quotes , так и в автоматическом режиме: open — quote обозначает открывающую кавычку цитаты для текущего языка. Например, для русского это будет открывающая «ёлочка» ( « ); close — quote обозначает закрывающую кавычку цитаты для текущего языка. Например, для русского это будет закрывающая «ёлочка» ( » ); Вспомните, как говорили мушкетёры: Один за всех, все за одного!
blockquote > Вспомните, как говорили мушкетёры: q > Один за всех, все за одного! q> blockquote>
Скопировать Скопировано Не удалось скопировать blockquote quotes: "«" "»" "„" "”"; > blockquote::before content: open-quote; > blockquote::after content: close-quote; >
blockquote quotes : "«" "»" "„" "”" ; > blockquote::before content : open-quote; > blockquote::after content : close-quote; >
Скопировать Скопировано Не удалось скопировать «Вспомните, как говорили мушкетёры: „Один за всех, все за одного!”» no — open — quote и no — close — quote используются, когда не нужно отображать кавычки, но при этом продолжать увеличивать уровень вложенности; Если значением является результат выполнения функций counter ( ) или counters ( ) , то псевдоэлемент будет содержать вычисленное значение счётчика в текущий момент. Эти функции работают совместно со свойствами counter — reset и counter — increment ; Очень интересным значением является результат выполнения функции attr ( ) . С помощью неё можно вывести в псевдоэлемент значение любого атрибута тега:
Ваш рейтинг: 212
p > Ваш рейтинг: span data-tip = " Вычисляется на основе активности" > 212 span> p>
Скопировать Скопировано Не удалось скопировать [data-tip] position: relative; cursor: help; > [data-tip]:hover::after opacity: 1; visibility: visible; > [data-tip]::after content: attr(data-tip); position: absolute; top: 140%; left: 50%; transform: translateX(-50%); opacity: 0; visibility: hidden; >
[ data-tip ] position : relative; cursor : help; > [ data-tip ] :hover ::after opacity : 1 ; visibility : visible; > [ data-tip ] ::after content : attr ( data-tip) ; position : absolute; top : 140 % ; left : 50 % ; transform : translateX ( -50 % ) ; opacity : 0 ; visibility : hidden; >
Скопировать Скопировано Не удалось скопировать
🛠 . или красиво оформить нумерованный перечень
.benefits counter-reset: benefits; > .benefits-item counter-increment: benefits; > .benefits-item::before content: counter(benefits); position: absolute; font-size: 190px; font-weight: bold; left: 0; top: -0.35em; opacity: 0.5; color: #1A5AD7; >
.benefits counter-reset : benefits; > .benefits-item counter-increment : benefits; > .benefits-item ::before content : counter ( benefits) ; position : absolute; font-size : 190 px ; font-weight : bold; left : 0 ; top : -0.35 em ; opacity : 0.5 ; color : #1A5AD7 ; >
Скопировать Скопировано Не удалось скопировать Источник