padding-top: 50%
property to it padding-top: 50%
? Intuitively, this property sets the size of the field from the top edge of the contents of the element, the size of which is 50% ... What does this 50% do? As a matter of fact, at a certain moment intuition turns out to be useless when analyzing the features of this property. The fact is that these 50% are taken from the width of the parent element of the element to which the top field is assigned.padding-bottom
property. Knowledge of this feature, in particular, allows you to create responsive elements that preserve the aspect ratio: .square { width: 100%; height: 0; padding-bottom: 100%; }
20px
, not 40px
: <div style="margin-bottom:20px">foo</div> <div style="margin-top:20px">foo</div>
overflow
parameter set to any value other than visible
(they do not close indents with their descendant elements).clear
rule applied (their upper indents do not collapse with the lower indents of their parent blocks).<div>
elements, each of which is absolutely positioned. They contain other elements that are assigned a z-index
property with values ​​from 1 to 3. Each next such element is displayed on top of the previous one. If you now assign the z-index: 10
to the lowest element, it will be displayed on top of the other two, the order of which will not change. So far, everything looks as expected. If you now assign the first element <div>
, the one that is now above the others, the opacity: 0.99
property, it will be under the other two. // :root { --foo: #000; } button { background-color: var(--foo); // }
.foo { color: var(—-my-var, 'blue'); }
::root { --default-color: #000000; } header { --primary-color: #ff0000; } a { color: var(--primary-color, --default-color); } <a href="">this is black</a> <header> <a href="">this is red.</a> </header>
// inline- element.style.getPropertyValue("--my-var"); // inline- element.style.setProperty("--my-var", jsVar + 4);
vertical align: top | middle | bottom
vertical align: top | middle | bottom
vertical align: top | middle | bottom
works only for inline elements (including inline-block
) and table-cell
elements. This method is not suitable for aligning elements within their parent elements. To do this, you need to use the flexbox layout tool, or what is known as “douchebag vertical align” (we’ll talk about it below).height: 100%
property height: 100%
. In many cases, setting this property does not lead to what the developer expects. The reason for this lies in the fact that the height of the parent element is not specified. Consider an example: <html> <body> <div style="height:100%;background:red;"></div> </body> </html>
<div>
element shown here will not fill the entire page in red. To achieve this, you need to set the height
property to 100%
for both the <body>
element and the <html>
element..foo.bar
override the rules set separately for .foo
and for .bar
. #foo { color: red; } .bar { color: green; } <h1 id="foo" class="bar">this will be red not green</h1>
src
or href
attributes. // zip- ( ) a[href$=".zip" i] { } // google.com [href*="google.com"] { color: red; }
img
elements with an empty alt
attribute: img:not([alt]) { border: 2px dashed red; } img[alt=""] { border: 2px dashed red; }
[ng-click]
. Or, if necessary, you can visually separate links to local resources, and links that begin with http
or https
.padding: 10px 20px; 10px
padding: 10px 20px; 10px
is the top and bottom 20px
, 20px
is the right and left margins. This is what it looks like when setting up margins, indents, borders, in general - this is true for almost everything, with the exception of the border-spacing
in tables where values ​​are arranged exactly the opposite: the first number sets the value horizontally, the second - vertically. background: url(example1.png') no-repeat center 50px, url('example2.jpg') no-repeat bottom top;
@keyframes foo { 0% { opacity: 0; } 100% { opacity: 1; } } @keyframes bar { 0% { transform: translateX(-100px); } 100% { transform: translateX(0px); } } .element { animation: foo 2s 0s, bar 1s 0s; }
translateZ(0);
to a container that includes an element with the property position: fixed;
aligns the element with the container, rather than with the window.:target
can be used to style the elements to which the transition is made when clicking on a link with a grid symbol. For example, clicking on a link like <a href="#foo">Go to Foo</a>
scroll the page to the element <div id="foo">foo</div>
. Now, if you included in the CSS a rule like #foo:target { color: red; }
#foo:target { color: red; }
, the <div> #foo
will be colored red.www.example.com/#foo
. With this approach, the browser scrolls the page to the desired element and this element will be highlighted. Nowadays they rarely do this, but this technique can improve the user experience of working with the site. <div data-text="foo"></div> div:before { content: attr(data-text); }
attr()
you can only work with content. Although it is possible the emergence of support for this design other properties. Moreover, the values ​​obtained from attr()
are strings, so they are intended primarily for content and cannot be used for size properties (for example, font-size
) or for links (for example, content: url()
) By the way, let's talk about it. <div></div> div:before { content: url(image.jpg); }
<div style="--background-image: url('http://via.placeholder.com/150x150');"></div> div:after { content: ''; background-image: var(--background-image); }
content: counter()
construct can be used for incremental pseudo-element numbering: p { counter-increment: myIndex; } p:before { content:counter(myIndex); } <p>foo</p> <p>bar</p>
content
property of pseudo classes like :before
and :after
can be used to add opening and closing quotes to elements: q:before { content: open-quote; } q:after { content: close-quote; }
quotes
property: html[lang="fr"] q { Quotes: "«" "»"; }
font
property allows, in an abbreviated format, to set font parameters: h1 { font-weight: bold; font-style: italic; font-size: 1rem; //etc… } // h1 { font: italic lighter 1rem/150% Verdana, Helvetica, sans-serif; } // // font: font-style font-variant font-weight font-size/line-height font-family;
@supports
directive can be used to check if the browser supports features of interest to the developer. Let's say if display:flex
is planned to be used only if there is confidence in the browser support for this feature, you can apply the following construction: @supports (display: flex) { div { display: flex; } }
<div class="justify-start sm:justify-center md:justify-end lg:justify-between xl:justify-around"> <button class="bg-blue hover:bg-blue-dark text-white hover:text-blue-light">Button</button>
.sm\:justify-center { }
* + * { margin-top: 2rem; }
li + li { margin-top: 1rem; } // li { margin-bottom: 1rem; } li:last-of-type { margin-bottom: 0; }
.element { position: relative; top: 50%; transform: translateY(-50%); }
font-feature-settings: "tnum"; font-variant-numeric: tabular-nums;
p { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
Source: https://habr.com/ru/post/350658/
All Articles