Margin-top sub html but active parent html
The parent selector,
Show 5, is a special selector invented by Sass that’s used in to refer to the outer selector. It makes it possible to re-use the outer selector in more complex ways, like adding a pseudo-class or adding a selector before the parent. When a parent selector is used in an inner selector, it’s replaced with the corresponding outer selector. This happens instead of the normal nesting behavior. SCSS Syntax
Sass Syntax
CSS Output
⚠️ Heads up!Because the parent selector could be replaced by a type selector like
6, it’s only allowed at the beginning of compound selectors where a type selector would also be allowed. For example,
7 is not allowed. We’re looking into loosening this restriction, though. If you’d like to help make that happen, check out this GitHub issue. Adding SuffixesYou can also use the parent selector to add extra suffixes to the outer selector. This is particularly useful when using a methodology like BEM that uses highly structured class names. As long as the outer selector ends with an alphanumeric name (like class, ID, and element selectors), you can use the parent selector to append additional text. SCSS Syntax
Sass Syntax
CSS Output
In SassScriptThe parent selector can also be used within SassScript. It’s a special expression that returns the current parent selector in the same format used by : a comma-separated list (the selector list) that contains space-separated lists (the complex selectors) that contain unquoted strings (the compound selectors). SCSS Syntax
Sass Syntax
CSS Output
If the
5 expression is used outside any style rules, it returns
9. Since
9 is , this means you can easily use it to determine whether a mixin is being called in a style rule or not. SCSS Syntax
Sass Syntax
0 CSS Output
1 Advanced NestingYou can use
5 as a normal SassScript expression, which means you can pass it to functions or include it in interpolation—even in other selectors! Using it in combination with and the
2 rule allows you to nest selectors in very powerful ways. For example, suppose you want to write a selector that matches the outer selector and an element selector. You could write a mixin like this one that uses the to combine
5 with a user’s selector. SCSS Syntax
2 Sass Syntax
3 CSS Output
4 ⚠️ Heads up!When Sass is nesting selectors, it doesn’t know what interpolation was used to generate them. This means it will automatically add the outer selector to the inner selector even if you used
5 as a SassScript expression. That’s why you need to explicitly use the
2 rule to tell Sass not to include the outer selector. Does marginTop and bottom margins do not affect inline elements because inline elements flow with content on the page. You can set left and right margins/padding on an inline element but not top or bottom because it would disrupt the flow of content. How do I ignore parent padding?In CSS, you can ignore parent padding by using the `box-sizing` property. By default, the `box-sizing` property is set to `content-box`, which means that the size of an element's box is determined by its content, padding, and border. Why are my margins not working in HTML?It is because the elements are inline elements. If you set them to inline-block (or block) the margin will work as expected. How do I set the top margin in HTML?Style marginTop Property. Set the top margin of a element: document. getElementById("myDiv"). ... . Change the top margin of a element back to "normal": document. getElementById("myDiv"). ... . Return the top margin of a element: alert(document. ... .
Difference between marginTop and paddingTop: function changeMargin() {. |