Js + CSS Implementation Method to bring up a translucent div layer with a center background
This article mainly introduces how to use javascript + CSS to pop up the center background translucent div layer. It involves the operation skills of javascript operations to pop up the div
The text in the Div is absolutely centered before always use the table, now have a very good solution line-height can be easily realized, interested friends can refer to, I hope to help you
After so long, did not know how to do, always use the form, today finally figure out ...Horizontal Center:vertically centered:The combination of the two can be absolutely centered:
Copy Code code as follows:
But for the vertical
The most common form of DIV+CSS Web page layout: Upper, middle left, middle right, bottom four modules, width 760px, the overall page center.
Structure code, top left right foot four modules are all independent and not nested.
The top is part of the general definition.
#top {height:100px; background: #ccc; width:760px; margin:auto; text-align:center;}
Method A: The outer left is defined to be 760px
IE7 and IE6 do not recognize Display:table-cell (but support css1 properties such as Display:block!)
IE8 and later versions can be identified!
IE7 and IE6 can identify vertical-align:middle;
If the box model has only a few paragraphs of text, set Line-height can be achieved center display!
If you want to center the Div in the box model, you can refer to the f
HTML to write a div, CSS to the div fixed width and background color:The picture above is a light gray box with a background color of 200 for a wide height.Now let the div be centered relative to the browser, implemented through a piece of JavaScript code:varW = document.body.clientWidth;//Browser's width varh = window.innerheight;//Browser's HighC
JQuery provides us with easy and simple control methods. For example, we can use $ (document) to set a horizontally vertical center layer ). width () and $ (document ). height () to obtain the width and height of the window. Then, a simple calculation is performed to center the layer horizontally and vertically.
Horizontal vertical center
Div + css implement vertical horizontal center of unknown width and height elements, divcss
Div + css enables vertical horizontal center of unknown width and height elements. Many people will encounter this problem during the interview: How to Use div + css to implement vert
Code example for vertical center effect of div implemented by css, cssdiv
Code example of div vertical center effect implemented by css:The vertical center effect of div has been described on the Internet.This section uses code e
1, in general, the center of the div fails because the DTD statement is not writtenAt the top of the page, add:! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">Http://www.100sucai.comYou can do it! In fact, many other CSS problems are also caused by not adding a DTD statement.2. Use margin to cente
Maybe I like it too much. My blog has been changing for three days. I think it is better to center navigation by using jquery + css at the front end. At the beginning, css wrote: div {position: fixed;
Maybe I like it too much. My blog has been changing for three days. I think it is better to center navigation by using jquery + css at the front end.
At the begin
css| Solution
Original title: Vertical centering in CSSsubtitle: Yuhu ' s definitive Solution with Unknown Height
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
Center up or downCode to copy code as followsdiv{position:fixed;Margin:auto;left:0;right:0;top:0;bottom:0;width:200px;height:150px;}If only the left and right center, then the bottom:0; or top:0; You can delete it.If you only need to center up and down, then put left:0; or right:0; CanThe following is a DIV element cen
Here's the absolute Center for inserting the picture, and if you just want to center the picture, the easiest way is to set it as a background image, such as:
div {width:500px;border:1px solid #f00;height:500px;Background:url ("/images/logos.gif") Center No-repeat}
Say to turn, please see the following code to implem
1, first give it the outer div positioning and left:position:absolute;left:50%;2. Get the width of the current element div and divide by 23. Change its css:margin-left:-(to get the width of the current element div divided by 2).function width (obj) { Obj.each (function() { var pagingwidth=$ (this). Width (); // pagination
the body of the HTML is only a Div, the rest of the content in this Div, set the div style as follows:Div {Position:absolute;background: #404040;width:500px;height:400px;top:50%;left:50%; margin-top: -200px; the value is half the height margin-left: -250px; // value It's half the width. }This allows the div to be cent
css| Page | questions
1. Single text
Set the height of the div is the same as the line height of the text can be, that is, line-height and the height of the value is the same, and finally give Div a over-flow:hidden, so that the excess part of the hidden.
This method supports block-level and inline-pole elements as well as all browsers, but only one row, and IE does not support the
First look at the effect:Http://www.keleyi.com/keleyi/phtml/fixedcenter.htm
KeyCodeYes: # topmenu_keleyi_com {position: fixed; left: 0px; Right: 0px; width: 706px; margin-left: auto; margin-Right: auto ;}
Complete code:
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 > Title > Center The position: Fixed
Center up or down
The code is as follows
Copy Code
div{position:fixed;Margin:auto;left:0;right:0;top:0;bottom:0;width:200px;height:150px;}
If only need to center, then put bottom:0; or top:0; You can delete it.If you only need to center up and down, then put the left:0; or right:0
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.