I. Line-height MethodIf 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 align the text vertically in a paragraph. Ii. padding methodAnother method is similar to the line height method. It is also suitable for vertical
The div vertical and horizontal center instance Code implemented by jQuery, jquerydiv
Code of the div vertical and horizontal center instance implemented by jQuery:There is a div element in the window. The following describes how to use jQuery to set it to horizontal and ver
html> head> meta charset="UTF-8"> title>Edith Academy Small exampletitle> head> style type="Text/css">/ * Full-frequency transparent div*/of this style settingDiv { position: Absolute ; z-index: 1 ; width: 100% ;/ * The benefit of pressing the% ratio by the available width of the body is that it can be changed with the window size * / height: 100% ;/ * Press the body's available height * /Left : 0% ; top: 0% ; background-color: #000000
Unknown height div compatible with each browser vertical center effect:It is not as simple to have a div centered vertically with its parent as to have the div centered horizontally in the parent element, as long as it is simple to set margin:0px auto for this element, although some properties can be used in conjunctio
Method One: The display of some div is set to a table, so we can use the Vertical-align property of the table.
The structure effect is as follows:Css
The code is as follows:
Div#wrapper {
display:table;
width:500px;
height:500px;
Background-color: #c00;
}
Div#row {
Display:table-row;
}
declarations?
1. Pixy once invented underscore hack, which is to add an underscore (_) before each CSS attribute. This hack is specifically for IE6 and earlier versions, which means IE7 cannot understand. For example: _ Position: absolute; so this kind of hack will pass!2. the "#" statement before the attribute can only be understood by IE7 and earlier versions, but cannot be understood by any other browser "#", therefore, the "#" statement will be ignored by other browsers. OK ~~ That's it!
hidden. If your browser supports font amplification, you can zoom in the font to see what will happen.2. Multi-line content is centered and the container height is variableIt is also very easy to give consistent padding-bottom and padding-top. The code is as follows:Copy code . Middle-demo-2 {Padding-top: 24px;Padding-bottom: 24px; } Advantages:1. Both block-level and inline polar elements are supported.2. Supports non-text content3. Support for all browsersDisadvantages:Container cannot b
Summary: Although CSS provides the Vertical-align property to set the center, it is used only for elements that provide vertical-align characteristics, such as .First, the DIV Center implementation method:1. When only one single element is displayed in the
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->
Div ID
=
"
Container
"
>
Div ID
=
"
Content
"
>
Div
>
Div
>
To center the content layer in the container layer, you only ne
Method One:Idea: Use the Text-align property to center the picture horizontally, and then set the value of the Padding-top to center vertically.The structure is as follows:CSS styles are as follows:div {width:300px; height:150px; Background-color: #CCC; border: #000 1px solid; text-align:center; padding-top:50px;}The results of the operation are as follows: Meth
How does css implement vertical and horizontal center of images in an unknown wide-height div? cssdiv
How does css implement vertical horizontal center of images in an unknown wide-height div:In some cases, we may want to align an image vertically and horizontally in the div
Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
>
Html
Xmlns
= "Http://www.w3.org/1999/xhtml"
>
Head
>
Meta
HTTP-equiv
= "Content-Type"
Content
= "Text/html; charset = gb2312"
/>
Title
>
Example of vertical center of an image in a div
Title
>
Style
Type
= "T
The horizontal center is very simple, set the text-align:center on it, but the vertical center has not been able to solve.
Always tried to adjust padding-top, but sometimes, more time not, today again, when the height value is not large, increase the padding-top will increase the entire div or span height, very annoyed.
Think theoretically vertical-
Css implements DIV vertical center on the screen, cssdiv
Address: http://www.manongjc.com/article/374.html
This section describes how to align a div element horizontally and vertically in full screen mode. The Code is the most convincing and you can directly look at the code.
The Code is as follows:
Online oper
When building a webpage layout, we often face a problem, that is, to align a div horizontally and vertically. Although there are several ways to achieve it, my favorite method is introduced today, implemented through CSS and jquery.
1. Implement horizontal center through CSS:
. Classname
{
Margin
:
0 auto
;
Width
:
200px
;
Height
:
200
div Vertical Horizontal Center Instance code:About let Div vertical horizontal center of effect too much, here does not introduce, nonsense say, directly give code.The code example is as follows:DOCTYPE HTML>HTML>Head>MetaCharSet= "Utf-8">Metaname= "Author"content= "http://www.softwhy.com/" />title>Vertical Horizontal
1. center a single line of contentIt is easiest to consider a single row. No matter whether or not the container is given a fixed height, you only need to set the line-height and height for the container and make the two values equal, plus over-flow: hidden:. Middle-demo-1 {Height: 4em;Line-Height: 4em;Overflow: hidden;}
Advantages:1. Both block-level and inline polar elements are supported.2. Support for all browsersDisadvantages:1. Only one row ca
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.