css horizontally centered text-align:center and margin:0 auto
These two methods are used for horizontal centering. The former is set for the parent element and the latter is for the child element. The first condition for them to work is that the child elements must not be affected by float, otherwise everything will be in vain. margin:0 auto
can also be written as margin:0 auto 0 auto. Children who don't understand can look for information about CSS abbreviations on their own.
Vertically centered line-height
What? ! Margin doesn't work in vertical centering? Obviously this is the case, we only have the usage of margin:0 auto but not auto 0. As for line-height, it also acts on the parent element. When its value is equal to the height value of the parent element
, the internal text will automatically be vertically centered. It seems that this is just text, which is a pity.
The universal position method
This method can be said to be truly omnipotent. When you are troubled by an element that cannot be centered, you can use it decisively with almost no side effects. It is definitely one of the must-have methods for front-end engineers to travel at home.
The specific method is very simple. First, write positon:relative on the parent element. This is done so that when the child element is marked with position:absolute, it will not be positioned in outer space. Next, write the height and width of the child element. This seems to be necessary
. If some browsers do not have these two values when parsing, unexpected misalignment will occur. Then comes the core of the entire method. Add top: 50%; left: 50% and margin-top: a negative number that is half the height value;
margin-left: a negative number that is half the weight value. After sorting it out, you may write css like this for your child elements (of course, the parent element must also write width and height first)
{width:100px;height:80px;position:absolute;top:50% ;left:50%;margin-left:50px;margin-top:40px}
Next, refresh the page. Your child elements are already centered.
The advantage of using this method is that no matter what form of content you have, it can be centered immediately. The disadvantage is that the element must have a certain width and height value, otherwise you may need to perform some small calculations through javascript.

This is the 3rd post in a small series we did on form accessibility. If you missed the second post, check out "Managing User Focus with :focus-visible". In

The CSS box-shadow and outline properties gained theme.json support in WordPress 6.1. Let's look at a few examples of how it works in real themes, and what options we have to apply these styles to WordPress blocks and elements.

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

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

In this article we will be diving into the world of scrollbars. I know, it doesn’t sound too glamorous, but trust me, a well-designed page goes hand-in-hand

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.


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

SublimeText3 Chinese version
Chinese version, very easy to use

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

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

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),