28
loading...
This website collects cookies to deliver better user experience
<div class="example">
<div class="number">1</div>
</div>
.example {
border-radius: 50%;
background-color: magenta;
width: 40px;
height: 40px;
box-sizing: border-box;
}
.example
element is a magenta circle of 40x40. Say we want to place this 1
exactly in the middle of the .example
div. You could do this:.example {
padding: 11px 16px;
}
.example {
display: flex;
align-items: center;
justify-content: center;
}
Internet Explorer 11 is reaching its end of life very soon, and the whole development world will breathe a sigh of relief when it does. The browser has been ridiculously outdated for a while now, and new awesome features like CSS Grid, or Flexbox, were either not implemented at all, or implemented in their own way. This resulted in many inconsistencies when comparing your page in IE11 to for example Google Chrome.
.element {
filter: opacity(0.5);
opacity: 0.5;
}
filter
, actually performs better because browsers can use hardware acceleration. However, it's not supported in IE11. So, if your users use IE11, you might want to avoid using filter
. Alternatively, some browsers offer compatibility through the use of prefixes like -webkit-animation
instead of animation
. Many projects these days use a form of Autoprefixer to automatically do this for you.<nav>
<button>Home</button>
<button>Options</button>
</nav>
nav:first-child + * {
margin-left: auto;
}
<nav>
<button>Home</button>
<button>Blogs</button> <!-- Now this element is targeted -->
<button>Options</button>
</nav>
<nav>
<div> <!-- This is now the first child, and it has no sibling -->
<button>Home</button>
<button>Options</button>
<div>
</nav>
<nav>
<img class="company-logo" src="...">
<button>Home</button> <!-- Now this element is targeted -->
<button>Options</button>
</nav>
<nav>
<button class="home-button">Home</button>
<button class="options-button">Options</button>
</nav>
nav .options-button {
margin-left: auto;
}
.options-button
in the nav
should have space to the left). It is also unaffected if for example a wrapper <div>
is added around the buttons, or if more menu items are added before it.padding
or margin
? Should the top element have margin-bottom
or should the bottom element have margin-top
? Let me explain what I mean.<button class="example-button">
<div>Click me!</div>
</button>
.example-button {
padding: 10px;
}
.example-button div {
margin: 10px;
}
<h2 class="example-header">Beautiful header</h2>
<p class="example-text">Lovely bit of text</p>
.example-header
a margin-bottom
? Or the .example-text
a margin-top
?.example-text
. Would you want the 20px space to be between the two paragraphs, or between the header and the first paragraph? By looking at it this way it makes more sense to add the margin on the bottom of the header.margin: 0 3px 6px 1px;
instead of spelling out each individual property.