Vertical align
- With Transform:
1 | .element { |
Demo:
works on IE 9+
This method can cause elements to be blurry due to the element being placed on a “half pixel”. A solution for this is to either set its parent element to preserve-3d. Like following:
1 | .parent-element { |
Or, you can set the perspective of the element:
1 | .element { |
- Flexbox
1 | .flex-container { |
- inline-hight
1 | .valign { |
- position: absolute && margin: auto;
1 | #container{ |
Horizontal align
- Flexbox
1 | .flex-container { |
- text-align: center;
1 | .container { |
Demo:
3.transform: translateX()
1 | .halign { |
Demo:
- margin: auto;
1 | .halign { |
Demo: