Example of how CSS3 Selectors work
Learning HTML5 and CSS3 from course videos; The person who did the example in the image for CSS3 Selectors did not show what he used for ‘div{}’, which I would assume applies to all DIVs. I would like to know of certain properties that can achieve this result.
The selectors were given to me like this. In terms of ‘div{}’, I thought I could resize the inner DIVs with the ‘position’ and ‘margin’ properties.
Is it possible to adjust the size of the inner DIVs and align them in the center by just referencing ‘div’?
div {
position: relative;
top: 50%;
width: 90%;
height: 90%;
margin: auto auto auto auto;
}
div.outer-outer {
background-color: red;
}
div.outer-outer div.inner {
background-color: blue;
}
div.outer,
div.inner-inner {
background-color: yellow;
}
div#main-section {
background-color: green;
}
div.footer-section {
background-color: purple;
}
<div class="outer-outer">
Outer Outer
<div class="outer">
Outer
<div class="inner">
Inner
<div class="inner-inner">
Inner Inner
</div>
</div>
</div>
</div><br /><br />
<div id="main-section">
Main Section
</div><br />
<div class="footer-section">
Footer Section
</div>
2
Answers
A possible solution is to adjust the padding of the ‘div’ like this:
If you want to adjust the size, you would need to modify the percentage assigned to the width.
I’ve commented on the changes that i did. If you give the parent element, or as i did a general selector
div
a padding you can adjust the position of the child element.padding
has the same order for the units as margin has:And to adjust the size of an specific
div
you can give its class the wantedwidth
andheight
. If you use relative units it will adjust its size to the parent element depending on the viewport.