Examples of vertical center and vertical scroll bars in css3

Source: Internet
Author: User

Vertical content concentration

It is difficult to control the content in the vertical direction relative to the content in the horizontal position, especially when the scroll bar is taken into account. This pure CSS code can work well.

. Container {
Min-height: 6.5em;
Display: table-cell;
Vertical-align: middle;
}

Vertical scroll bar

This code ensures that your HTML elements are always slightly higher than the position where the browser scroll bar stays.

Html {height: 101%}

CSS3 Transforms implements vertical and horizontal center

Code for horizontal and vertical center

. Parent {
Width: 200px;
Height: 200px;
Background-color: black;
}
. Child {
Position: relative;
Height: 100px;
Width: 100px;
Top: 50%;
Left: 50%;
Background-color: red;
-Webkit-transform: translateX (-50%) translateY (-50% );
-Moz-transform: translateX (-50%) translateY (-50% );
-O-transform: translateX (-50%) translateY (-50% );
-Ms-transform: translateX (-50%) translateY (-50% );
Transform: translateX (-50%) translateY (-50% );
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.