Home > Web Front-end > HTML Tutorial > Can this div be centered? _html/css_WEB-ITnose

Can this div be centered? _html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:44:24
Original
1202 people have browsed it

123

According to the html5 standard (to be compatible with mobile browsing), Based on position:relative;width:60%;min-width:500px;, is there any way to center this div?


Reply to discussion (solution)

Centering the div is very simple:

aaaaaa< ;/div>

That is, add margin:0px auto;

123

Centering the div is very simple:

aaaaaa


Sorry, I made a mistake. It was position:absolute; I tried margin:0px auto; and that’s why I asked if it didn’t work.

margin:0px auto; It didn’t work. left: 50%;width:60%; also doesn’t work, because margin-left: is difficult to determine.
Is there any good way?

The current DIV cannot be adaptively centered in the absolute state, but it can be done indirectly through some methods:


The content you want to center

The current DIV is in absolute There is no way to adaptively center in the state, but you can do it indirectly through some methods:


The content you want to center


I have also tried this, because width:100%; will block the couplets on both sides Advertisement, that’s why I want to limit width:100%;
Is there any other way? If it doesn't work, I can only modify the couplet advertisement, but it will also involve many places, because my webpage is relatively complicated.


The current DIV cannot be adaptively centered in the absolute state, but it can be done indirectly through some methods:


The content you want to center


I have also tried this, because width: 100%; will block the couplet ads on both sides, so I want to limit width: 100%;
Is there any other way? If it doesn't work, I can only modify the couplet advertisement, but it will also involve many places, because my webpage is relatively complicated.

If it doesn’t work, just use JS to calculate the positioning, but this is not recommended.
100% is just an empty box. If you put the content in a centered DIV, it will not cause occlusion.



The current DIV is in absolute There is no way to adaptively center in the state, but you can do it indirectly through some methods:


The content you want to center


I have also tried this, because width:100%; will block the couplets on both sides Advertisement, that’s why I want to limit width:100%;
Is there any other way? If it doesn't work, I can only modify the couplet advertisement, but it will also involve many places, because my webpage is relatively complicated.

If it doesn’t work, just use JS to calculate the positioning, but this is not recommended.
100% is just an empty box. If you put the content in a centered DIV, it will not be blocked.
100% empty box will still appear in many browsers even if you don’t set the color. The layer below is obscured and cannot be clicked.
js positioning is indeed not advisable and will also cause many compatibility issues. I think you are quite familiar with CSS. If there is no better way, I have to modify the underlying couplet ads and related content

The current DIV cannot be adaptively centered in the absolute state, but it can be centered through some The method is to do it indirectly:


You want to center it The content

DIV cannot be adaptively centered in the absolute state?? This is the answer
Posted
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template