{
Width: 100px;
Height: 100px;
Background: #222;
}
/* The following is the center code */
. Parent {
Display: flex;
Justify-content: center;
Align-items: center;
/* You need to set height to view the vertical center effect */
Background: # ccc;
Height: 300px;
}
How does DIV
Let's take a look at one of the most common implementation examples:
Create a new HTML page,
xml/html Code copy content to clipboard
>
HTML xmlns="http://www.w3.org/1999/xhtml">
Head >
Meta http-equiv= "content-type" Content="text/html"; charset=gb2312 " />
title > Untitled document title>
Head >
Body >
Body >
HTML >
In the middle, insert the CSS code
CSS code copy co
Vertical center of DIV content, vertical center of div
Vertical-align: middle does not work on div. For example:
1
After running, the button is not vertically centered in the DIV:
Solution: If the width and height of the
Five methods for vertical center of content in div, five methods for vertical center of div
Reposted blog: http://www.cnblogs.com/moqiutao/p/4807792.htmlI. line-height Method
If only one or several lines of text are vertically centered, it is the easiest to create, as long as the line height of the text is the same as
Method Summary of vertical center of content in div, vertical center of divI. line-height Method
If only one or several lines of text are vertically centered, it is the easiest to create, as long as the line height of the text is the same as the height of the container. For example:
p { height:30px; line-height:30px; width:100px; overflow:hidden; }
This code can
CSS sets horizontal and vertical center and css Center for row and block-level elements.
CSS settingsLine ElementHorizontally centered
Div {text-align: center}/* the row elements in t
Examples are as follows:
if ($ ("#cont1"). CSS ("position")!= "fixed" {
$ ("#cont1"). CSS ("position", "absolute");
var DW = $ (window). width ();
var ow = $ ("#cont1"). Outerwidth ();
var dh = $ (window). Height ();
var Oh = $ ("#cont1"). Outerheight ();
var L = (dw-ow)/2;
var t = (Dh-oh)/2 > 0? (DH-OH)/2:10;
var Ldiff = $ ("#cont1"). Off
The question of how the picture is centered horizontally within the box must be met frequently in the project.Here are some of the solutions I know now.Post the HTML code firstclass= "Boxblock"> src= " Http://skin.huitu.com/images/noface.gif " alt=" "/> div>Method 1:. Boxblock{width:200px;Height:200px;vertical-align:Middle;Display:Table-cell;background:Pink;text-align:Center;*font-size:174px;*display:B
HTML5: footer positioning (bottom + center) + div image Center
I am a beginner in HTML + CSS layout and try to write a Baidu homepage by myself. However, I am troubled by footer's positioning and Baidu does not have a good solution. Here I will record the gradual process. Record, Memo.
If you are a beginner, the soluti
HTML5: footer positioning (bottom + center) + div image center problem,
I am a beginner in HTML + CSS layout and try to write a Baidu homepage by myself. However, I am troubled by footer's positioning and Baidu does not have a good solution. Here I will record the gradual process. Record, Memo.
If you are a beginner, t
The css pop-up window is always vertically and horizontally centered, and css is centered.
The css pop-up window is always vertical and horizontally centered:This topic describes how to implement vertical and horizontal center in
First, the horizontal center
Kinds
Element properties
Characteristics
Example
inline element
text, Inline elements such as pictures
text-align:center to implement
.imgcenter{ Text-align:center; } "I want to center horizontally in the parent container" is a text element, and
content to center vertically. Just set the content to center horizontally (v) display:table-cell css has a property vertical-align for vertical centering, but only When the parent element is TD or TH, this vertical-align property will take effect, for other block-level elements, such as
[Bootstrap] How does bootstrap2 guide div vertical center and bootstrapdiv Center
Reference: http://www.4byte.cn/question/138712/bootstrap-how-to-center-vertical.html
Some of them refer to the method on the webpage above. Those who have used bootstrap know that in bootsrap2, the grid layout can be used to
1. Using Display:table-cell, the specific code is as follows:The HTML code is as follows:1 class= "Img_wrap">2src= " Wgs.jpg ">3div> The CSS code is as follows:1 . Img_wrap {2 width: 400px; 3 height: 300px; 4 border: 1px dashed #ccc; 5 display: Table-cell;//main Is this attribute 6 vertical-align: Middle; 7 text-align: Center; 8 }The effect is as follows:2. Using the background met
siblings and we ' re centered in a row.4 Div>5 Div>6 I ' m an element which is block-like with my siblings and we ' re centered in a row. I have the more content in me than my siblings do.7 Div>8 Div>9 I ' m an element which is block-like with my siblings and we ' re centered in a row.Ten
Implementation of the element center problem in Css, And the css element center implementation
Preface:
It is very easy to vertically center elements in a fixed height container when writing CSS, such as setting the padding of the
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.