Code for moving the div center of a page, and code for centering a page div
View results online:Http://hovertree.com/texiao/mobile/4.htmAvailable in Mobile browsersThe following is an HTML file:
Web Front-end: http://www.cnblogs.com/jihua/p/webfront.html
Reprinted from the Nameless station like JS
For example, a parent div (w:100%;h:400px) has a sub-div (w:100px;100px;). To center it up or down.
Method One (varticle-align) conceptUse the Center property of the table cell.Steps
The parent
How to align the DIV layer horizontally with CSSThese two days began to make drastic changes to the website.Today, I encountered a very difficult problem. Div itself does not define its own center attribute,Many methods on the Internet are described using the upper-level text-align
To obtain the following page effects, for example, the position control for the mask layer:
PageCode:
DivClass= "Divouter"> DivClass= "Divinner">Divinner is the center block on the page.Div> Div>
After several attempts, we finally adopted the following solution (not compatible with ie5.5 ):
. Divouter { Position :Relative ; Margin : 0 auto ; /* Ie5.5 not supported */ Margin-top : 25% ; /* If
It is easy to center Div horizontally and set CSS styles.Text-align: center;You can.
Vertical center also has an attributeVertical-align: middle;This attribute has no effect on normal settings.
Method 1: Use a blank image to
How to center Div, table, and webpage display
There are many different methods to use CSS to implement vertical center of objects. It is difficult to choose the correct method. I will explain the good methods I have seen and how to create a good Center website. It is not easy to use CSS to implement vertical
centered vertically in a div
Use the background method. Example:
body{Background:url (background image path) #FFF No-repeat Center;
The key is the final center, which defines the location of the picture. It can also be written as "top left" or "bottom right", or you can write the value "50 30" directly.
How do I align
The use of CSS to achieve the vertical center of objects There are many different ways, it is difficult to choose the right method. Let me explain the good way I see it and how to create a good center site.
It's not easy to use CSS to center vertically. Some methods are not valid in some browsers. Let's look at the 5 different methods that make objects
Although the DIV layout has basically replaced the table layout, the table layout and Div layout still have their own advantages and mutual advantages. For example, vertical center in table layout is a weakness of Div layout, but fortunately, the ever-changing CSS can be used flexibly to produce a quasi-vertical
Source: http://www.knowsky.com/442392.html
In general, it is more convenient to specify the vertical and horizontal center of the DIV with a height, but it is a little troublesome if the height is not fixed. I tried it and achieved absolute center through two auxiliary Divs, compatible with standard browsers such as IE and ff. CSSCode:
Code highlighting p
document in HTML instead of XHTML.The problem is not in CSS but in the XHTML page itself.You need to add such a code to make the above settings effective:Consult the documentation if you want more stringent XHTML 1.0 Strict or XHTML 1.1.These tests are based on the Windows XP SP2 version IE6 and Firefox 1.0 final version.How do I make a div centeredThe main style definitions are as follows:
Copy Code code as follows:
body {text-align:center;}
#
First, using automatic margin to achieve the center
The preferred way to center elements horizontally in CSS is to use the margin property-set the Margin-left and Margin-right properties of the element to auto. In practical use, we can create a container-scoped div for these elements that need to be centered.
It is important to note that you must specify a wid
How does CSS align the DIV layer horizontally? Today, CSS is a very tricky problem. Div itself does not define its own center attribute. Many Methods on the Internet are to use the upper-level text-align: center then nest a
The main style definition is as follows: body {text-align: center ;}
# Center {margin-Right: auto; margin-left: auto ;}
Note:
First, define text-align: center in the parent element. This means that the content in the parent element is centered. for IE, this setting is enoug
Position: fixed in css implements div center and fixeddiv
Center between top, bottom, and left
The Code is as follows:Div {Position: fixed;Margin: auto;Left: 0;Right: 0;Top: 0;Bottom: 0;Width: 200px;Height: 150px;}
If you only need to center in the left-right corner, delete bottom: 0 or top: 0.If you only need to
When it comes to this question, perhaps someone will ask that CSS does not have the Vertical-align property to set the vertical center? Even some browsers do not support I just need to do a little CSSHack technology can be AH! So here I have to say two more words, CSS does have a vertical-align property, but it only for the (X) HTML element has the valign attribu
1. DIV CenterBody {text-align: center ;}Div {margin-right: auto; margin-left: auto ;}Note:For IE, define "text-align: center;" in the parent element.For other browsers such as FF, the data cannot be centered. You need to
jquery implements the div vertically horizontally centered instance code:There is a DIV element in the window, and here's how to use jquery to set it to align horizontally and vertically, hoping to bring some help to your friends.The code example is as follows:DOCTYPE HTML> HTML> Head> MetaCharSet= "Utf-8"> Metaname= "Author"content= "http://www.softwhy.com/"
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.