A typical three-row, two-column center height Adaptive Layout: How to center the entire page content and how to automatically scale the highly adaptive content. This is the most common problem in CSS layout learning. The following is a practical example and detailed explanation. (The experience in this article is discussed by xpoint and guoshuang in the blue ideal forum .)
First, let's take a look at the a
0. Prefacebasic method of horizontal centering--Specify the width of the block and set the left and right margin of the block to auto, the upper and lower margin is 0, then the block can be horizontally centered in the parent element. The styles are for example the following: 1:margin:0px Auto2:Margin-left:auto; margin-right:auto;Vertical Centering Basic method--the upper and lower margins of the set block are equal. The styles are as follows:padding-top:20px; padding-bottom:20px;1.div
In addition to the special note, the content of this site using the Creative Commons authorized signature and non-commercial use, please respect the fruits of labor.
Original title: Vertical centering in CSS
Subtitle: Yuhu ' s definitive Solution with Unknown Height
Translation: Forestgan
Despite the vertical-align features of CSS, it does not effectively solve the problem of vertical centering of unknown heights (in the case of a DIV tag with an
Despite the vertical-align features of CSS, it does not effectively solve the problem of vertical centering of unknown heights (in the case of a DIV tag with an unknown height of text or a picture).
Standard browsers such as Mozilla, Opera, Safari, etc., you can set the parent element display to table (display:table;), the inner child element is Table-cell (Display:table-cell), It is centered vertically by the vertical-
Loading HTML Web pages, Text Center on the page, in the mobile phone with webview loaded out of the center, this should be how to solve, mobile phone-side adjustment or background adjustment
Reply content:
Loading HTML Web pages, Text Center on the page, in the mobile p
needs to be obtained. The location of the browser should be obtained by calculating the Div.$ (document). Ready (function () {jQuery.fn.extend ({center:function () {width,height} {return $ (this). CSS ("left", ($ ( window). Width ()-width)/2+$ (window). ScrollLeft ()). CSS ("Top", ($ (window). Height ()-height)/2+$ (window). scrolltop () ). CSS ("width", width). css ("height", height);});});Let it unfold by clicking on the button$ (". Login"). Click (function () {$ ("#login"). Show ().
;left:50% margin-left:-50px;The effect is as follows:the use of negative values allows the label to be close to the parent element, so that we can achieve the center effect.2 in case of high uncertainty .In fact, the principle is the same , but in the height of uncertainty, we can not select the height of half, just change the code part:Position:absolute;top:50%;left:50%;Transform:translate (-50%,-50%);This completes the centering effect as well.Let's
In fact, this is not a very difficult thing, but, if you have no experience or do not know the HTML original number in the browser display in the order, it may be a problem, do not know how to adjust.First of all, after determining the width of the left and right sides of the block, and then the width of the middle block adaptive, there is a premise, it must be the middle block last display .Css: 1 .left { float : left ; : 170px ; background : #0
The principle of using the div popup to animate content is to use CSS and HTML to hide the contents of the pop-up window first, and then use JavaScript (jquery in this tutorial) to dynamically display them. This effect not only can make full use of the limited layout space, but also can improve the user experience; More importantly, it does not affect the SEO effect (because it actually exists in the page, but initially it is not visible)
1, in the
In the development process, many requirements need us to center a Div, such as the HTML document flow of a div, such as the pop-up layer content part of this out of the flow of documents. Different situations have different centering methods, then share the next several common centers.1.text-align:center.Code:. Center { text-align:center;} Center_text { display:i
Html always shows the elements in the center. The background image is full and drag randomly without going out of the border. The background image is full.
First, write two class attributes.
Body {margin: 0; padding: 0; height: 100%; width: 100%; background-image: url (.. /Content/Images/background.jpg); background-repeat: no-repeat; background-size: cover ;}
. Login {height: 300px; width: 400px; bor
The block is centered vertically in the block(Position:absolute; top:50%; margin-top:-one-second height)
blocks are centered horizontally in blocks(child element Set margin:0 Auto or Auto)
Use Method 1 to center the vertical horizontally#box {width:100px;height:80px;Background-color:gray;Position:absolute;top:50%;left:50%;margin-top:-40px; margin-left:-50px; }
The vertical horizontal center of the bloc
Sometimes we encounter such a problem, that is, when we press F12 to use Firebug debugging, we found that the image is not centered, the page has a horizontal sliding bar appears, the picture is not able to center, the default state is just close to the left side of the page, and when we narrow the image, The image is still close to the far left of the page, all we need to center the image, whether zooming
Center HTML element Display
Margin
style= "margin:300px auto,background-color:red,width:100px,height:100px" >div>Centered relative to the parent element, the upper and lower distances need to be calculatedPS: When setting a parameter for margin represents the upper and lower left and right; two up and down \ about; three up \ about \ down.The margin of the top and bottom two adjacent elements
HTML pop-up div and move Center, detailed implementation code as follows, interested friends don't miss
The code is as follows:
/* Pop-up layer of style*/
html,body {height:100%; margin:0px; font-size:12px;}
. mydiv {
Background-color: #ff6;
border:1px solid #f90;
Text-align:center;
line-height:40px;
font-size:12px;
Font-weight:bold;
z-ind
2016-1-18 experiment, how to write an HTML with a simple specification of Notepad, and how to simplify the specification Div Center. Write a simple, Div can center the HTML
Background: The div in HTML can be said to be a layout artifact, but sometimes there is no such one step attribute to define a div to be centered. So you need to manually write CSS to debugCode:In fact, the idea of the solution is this: the first need position:absolute; absolute positioning. Instead of the layer's anchor point, use the external patch margin negative method. The negative size is the height of the layer itself divided by two. such as: A
This method can even solve the problem that the IMG content is centeredRoutines: The outermost div width is the width of the center content (usually 1170px), and it is centered (Margin:auto)The div width in the inner layer is full screen (usually 1920px;) margin-left:-368px the value equals (1170-1920)/2 = 375px, but the actual combat time will also be biased. So it doesn't have to be a death rule.The principle is not clear at the moment. Here's how:H
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.