@julienherpin
Frontend developer @
ex : formulaire de login, ...
.container { position: relative; }
.content {
position: absolute;
width: 100px;
height: 100px;
left: 50%;
top: 50%;
}
.container { position: relative; }
.content {
position: absolute;
width: 100px;
height: 100px;
left: 50%;
top: 50%;
margin-left: -50px; /* On retire la moitié de la largeur */
margin-top: -50px; /* On retire la moitié de la hauteur */
}
.container { position: relative; }
.content {
position: absolute;
width: 100px;
height: 100px;
left: 50%;
top: 50%;
transform: translate3d(-50%, -50%, 0);
// Remplace :
// margin-left: -50px;
// margin-top: -50px;
}
IE10+
.container { position: relative; }
.content {
width: 100px;
height: 100px;
position: absolute;
// WTF, it's ok !
left: 0;
right: 0;
bottom: 0;
top: 0;
margin: auto;
}
.container {
position: relative;
height: 300px;
background: #333;
// -----
display: flex;
align-items: center;
justify-content: center;
// -----
}
.content {
width: 100px;
height: 100px;
// align-self: flex-start; -> si besoin de reset dans un contenu
// align-self: flex-end; -> si besoin de reset dans un contenu
}
IE10+
et éviter que le texte dépasse
.heading {
/* 1 line vertical centering */
height: 60px;
line-height: 60px;
/* Ellipsis */
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
}
Menu de gauche
.menu {
width: 20%;
float: left;
// height: 100%; -> Non !
height: 100vh;
}
IE10+
ex : Fil de commentaires
<div class="media">
<a href="#" class="media__img">img here</a>
<div class="media__content">text here</div>
</div>
.media { width: 100%; }
.media__content { overflow: hidden; } // -> IMPORTANT !
.media__img {
display: block;
float: left;
margin-right: 20px;
}
<div class="media">
<a href="#" class="media__img">img here</a>
<div class="media__content">
<p>Lorem ipsum ...</p>
<!-- An other one -->
<div class="media">
<a href="#" class="media__img">img here</a>
<div class="media__content">Lorem ipsum ...</div>
</div>
<!-- / An other one -->
</div>
</div>
Le CSS est commun
.media {
/* Flexbox magic */
display: flex;
align-items: flex-start;
}
.media__img {
/*float: left; <- Not needed */
margin-right: 20px;
}
.media__content {
flex: 1;
}
<div class="media">
<a href="#" class="media__img">img here</a>
<div class="media__content">text here</div>
</div>
IE10+
.blur {
color: transparent;
text-shadow: 0 0 10px rgba(0,0,0,0.5);
font-size: 60px;
text-align: center;
}
et un texte transparent !
IE10+
.blur {
font-size: 60px;
text-align: center;
filter: blur(5px);
}
!IE
.rel { position: relative; }
.abs {
width: 100px;
height: 100px;
position: absolute;
top: 0;
right: 0;
}
#easy
.rel { position: relative; }
.abs {
width: 100px;
height: 100px;
position: absolute;
top: 0;
// right: 0;
// Use the opposite corner
left: 100%;
}
<div class="box">
<div class="content">16:9</div>
</div>
.box:before {
display: block;
content: "";
width: 100%;
padding-top: 56.25%; // -> 9/16 = 0.5625
}
.box > .content {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
16/9
<div class="container">
<header>header</header>
<div class="main">
<nav>nav</nav>
<article>article</article>
<aside>aside</aside>
</div>
<footer>footer</footer>
</div>
// Conteneur
.main { display: flex; }
// Contenus
nav, aside { flex: 1; }
article { flex: 2; }
IE10+
// Shorthand
flex: none | [ <'flex-grow'> <'flex-shrink'>? || <'flex-basis'> ]
// Default
flex: 0 1 auto;
<form class="form">
<input class="input" placeholder="hey..." type="text" />
</form>
.form {
width: 500px;
padding: 20px;
}
.input {
width: 100%;
padding: 20px;
}
<form class="form">
<input class="input" placeholder="hey..." type="text" />
</form>
.form {
width: 500px;
padding: 20px;
}
.input {
width: 100%;
padding: 20px;
// On change le box-model
box-sizing: border-box;
}
IE8+
*, *:before, *:after { box-sizing: border-box; }
transform: translateZ(0);
transform: translate3d(0,0,0);
perspective: 1000; backface-visibility: hidden;
Améliore la performance sur des cas particuliers.
Ne pas en abuser !
IE10+
will-change: transform;
will-change: opacity;
will-change: left, top;
Chrome 36+ / Firefox 36+
Draft
box-shadow: 0 0 0 5px black, 0 0 0 10px gold, 0 0 0 15px black;
IE9+
<div class="container">
<div>FLEX 1</div>
<div>FLEX 2</div>
<div>FLEX 3</div>
<div>FLEX 4</div>
</div>
.container {
display: flex;
flex-direction: row;
}
IE10+
.container {
display: flex;
flex-direction: row-reverse;
}
.container {
display: flex;
flex-direction: column;
}
IE10+
.container {
display: flex;
flex-direction: column-reverse;
}
/* Main align */
justify-content: flex-start;
justify-content: flex-end;
justify-content: center;
justify-content: space-between;
IE10+
/* Cross align */
align-items: flex-start;
align-items: flex-end;
@julienherpin