


Center the layout_center the background image_center the text content in DIV+CSS
1. First, let’s introduce the use of css attributes to center the overall layout:
Set the parent content of the object to be centered. What is the parent of a page here? We can imagine that the content of the entire page is composed of and . Then according to the closer parent, we set the CSS of the body to achieve the centering problem. You can center the content with text-align:center; the specific css centering code is:
body{text-aligh:center; } But even this will cause problems, because you have not set the width of the layout "width". Once you set the float: attribute in the outermost css control in your content layout, the layout will lean in the float: direction you set. The solution is that in addition to setting the centered css attribute of the body, you also need to set the layout object Set it to the center and define the width. If the width of the web page is 700px and the outermost css style is class="weicheng", then the setting should be like ".weicheng{margin:0 auto; width:700px;}" This element is useful under IE. After testing, under browsers such as Firefox, only setting text-aligh:center; in addition to the parent (body) cannot center the layout. Then we also need to set a "margin:" for the object. 0 auto; "What does this mean? It means that the top and bottom of the content are 0 distance, and the left and right are "auto" automatically, so that the web page layout can be set to be centered (here set margin: 5px auto; the same effect will not affect the experiment). The complete example is (you can copy the code to create a new html file to view the effect):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
|
CSS layout centering example browsing
2. Introduce the use of css attributes to center the background of the web page:
Centering here includes left and right centering and top and bottom centering. The centering code is as follows:
body{BACKGROUND: #FFF url(http://www.divcss5.com/img/css-logo.gif) no-repeat center;} //This passage means to let css-logo.gif The background of this picture is set to be non-repeat (no-repeat), and it will be centered (center). This centering is left and right, and vertical does not need to be set, it will be centered automatically.
3. Tutorial on how to center left, right, top and bottom introductory text and image content with css:
We know that it is easy to center the left and right. We can directly use text-align:center; to center the text and image content, but vertically, if we are The height is 120px. The image is centered vertically with the vertical-align:middle; css attribute. The text is centered by setting the line height method to center the text content. Here we set the height to 120px, which requires setting line-height:120px. ;In this way, the text and image can be centered up, down, left, and right through CSS attribute styles.
The code to center the entire website is as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



If you’ve recently started working with GraphQL, or reviewed its pros and cons, you’ve no doubt heard things like “GraphQL doesn’t support caching” or

The Svelte transition API provides a way to animate components when they enter or leave the document, including custom Svelte transitions.

How much time do you spend designing the content presentation for your websites? When you write a new blog post or create a new page, are you thinking about

With the recent climb of Bitcoin’s price over 20k $USD, and to it recently breaking 30k, I thought it’s worth taking a deep dive back into creating Ethereum

npm commands run various tasks for you, either as a one-off or a continuously running process for things like starting a server or compiling code.

The article discusses using CSS for text effects like shadows and gradients, optimizing them for performance, and enhancing user experience. It also lists resources for beginners.(159 characters)

No matter what stage you’re at as a developer, the tasks we complete—whether big or small—make a huge impact in our personal and professional growth.

I was just chatting with Eric Meyer the other day and I remembered an Eric Meyer story from my formative years. I wrote a blog post about CSS specificity, and
