Css achieves horizontal vertical center of unknown height, while css achieves horizontal vertical center of unknown height
In page design, it is often necessary to implement horizontal and vertical center of elements. There are many css
element is not allowed floating elements to the left, so Div2 is forced to move down one line.So if there are only two elements in the page DIV1, Div2, are they all floating right? Readers should now be able to speculate on their own scenarios, as follows:Now, if you want to move div2 down to Div1, how do you do it?Also based on the side-dish conclusion, we want to move the DIV2, we must call the float in the div2 CSS style, because the float only af
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 Div> One Main>1 Mainclass= "Flex-center">2 Div>3 I ' m an element which is block-like with my siblings and we ' re centered in a row.4 Div>5 Div>6 I
Transferred from: http://www.cnblogs.com/fu277/archive/2012/09/13/2400118.html1. Center Horizontally(1) Horizontal centering of elements in text, picture, etc.Setting Text-align:center to the parent element enables horizontal centering of elements in the text, picture, and so on.(2) Horizontal centering of block-level elements to determine widthby setting Margin-left:auto; and margin-right:auto; to achieve.
Vertical center Method in CSS, vertical center Method in CSS
Yesterday I summarized the method of water in css. Today I will summarize the method of vertical center in css.
Line-heigh
In the past, JS was used to implement horizontal and vertical center of pages during webpage layout.
Code . This is a good method, but it is also difficult for friends who are unfamiliar with JS Code. Today, let's talk about how to use Div + CSS to implement the horizontal and vertical layout. Let's take a look:
Here I just cut a picture to demonstrate it. Use Div +
List Set the display:inline of the DOCTYPE HTML>HTML>Head>MetaCharSet= "Utf-8">title>Another way to arrange the list horizontallytitle>styletype= "Text/css">ul Li{Display:inline;background:#F93;padding:5px;}}style>Head>Body>ul> Li>Item1Li> Li>Item2Li> Li>Item3Li> Li>Item4Li>ul>Body>HTML>Effect:Wait, why is there a gap between Li???The solution is: write Li as a lineul> Li>Item1Li>Li>Item2Li>Li>Item3Li>Li>Item4Li>ul>Yes, it's written lik
How CSS sets the background image to repeat horizontally and vertically:Setting the horizontal tile of the background picture or vertical tiling is very simple, using both ends of the code, the code is as follows:Background:url ("Photo.gif") repeat-y;The above code allows the background image to be tiled vertically.Background:url ("Photo.gif") repeat-x;The above code allows the background image to be tiled
. Demo{Border:1px #ddd Solid;width:267px;Height:267px;Overflow:Hidden;text-align:Center;Display:Table;float: Left;margin:50px;position:relative;}. Demo a{Display:Table-cell;vertical-align:Middle;width:267px;Height:267px;}. Demo a img{margin:0 Auto;Max-width:267px;Max-height:267px;}Pure CSS implementation of the image horizontally vertically centered on the div (picture unknown width height)Pure
Instance
code is as follows
copy code
HTML code Example 2
DescriptionVertical-align:middle indicates that the line is centered vertically, we increase the spacing to be as high as the entire Div line-height:200px, and then insert the text and center it vertically.
There is also a solution
The following are the styles that let Div appear in the middle of the browser
code is as
Method OneIdea: The display setting parent element is: table, child element: cell-table, so you can use Vertical-align:center to achieve horizontal centerAdvantage: Parent element can dynamically change height (attribute of Table Element)Cons:IE8 not supported belowClass= "Parent1" > class= "Child" >hello world-1 Method Two:Idea: Use an empty label span to set his vertical-align baseline to the middle, and let him be the Inline-block, with a width of 0Cons: More than a useless empty label
There are many ways to achieve horizontal vertical centering of an element:
Element Unknown width high
Fit-content values for width and height only support Chrome and Firefox browsers1 . Box{2 position:Absolute;3 Top:0;4 Left:0;5 Bottom:0;6 Right:0;7 margin:Auto;8 width:fit-content;9 width:-webkit-fit-content;Ten width:-moz-fit-content; One Height:fit-content; A Height:-webkit-fit-content; - Height:-moz-fit-content; - Overflow:Hidden; the text-align:Center; - Background-color:#ee
Original link] (http://www.cnblogs.com/yaliu/p/5190957.html)Horizontal vertical centering method of floating layer(i) using absolute positioning and transformPosition the parent element (relative) with the following child elements. children{Position:absolute; top:50%; left:50%; -webkit-transform:translate ( -50%,-50%); Background:black; }(ii) utilization of Flexbox. Parent { justify-content:Center; align-items:Center; display: -webkit-flex; }[Web Front end]
height of the container is also 500px, can also achieve vertical center, but with it to achieve vertical center, there are shortcomings, that is, if the content too much, the text will run to the next line, then the content can not be vertically centered.2, the use of absolute positioningThis method has a drawback I have to point out that is the outside of the block element, must specify the height, so if
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" Lang = "ZH-CN" > Head > Meta HTTP-equiv = "Content-Type" Content = "Text/html; charsets = UTF-8" /> Title > Horizontal vertical center Div demonstration effect Title > Style Type = "Text/CSS" > . Align
Use CSS style position: fixed to scroll horizontally
This article describes how to use the CSS style position: fixed for horizontal scrolling. For more information, see
You can use the CSS style "position: fixed" to fix the div block in a fixed position without changing its position even if a scroll bar exists. Positi
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.