Home > Web Front-end > CSS Tutorial > How Can I Horizontally Center a Content Container Without Using `display: table`?

How Can I Horizontally Center a Content Container Without Using `display: table`?

Barbara Streisand
Release: 2024-12-19 00:17:15
Original
532 people have browsed it

How Can I Horizontally Center a Content Container Without Using `display: table`?

Centering Display: inline-block

In a layout consisting of a sidebar and a content container, the objective is to horizontally center the content without using fixed widths. While using display: table accomplishes this, it's not preferred. This article explores an alternative solution using display:inline-block.

To center the content, the following CSS can be applied:

In this modification, display: table is removed from .wrap. Additionally, text-align: center is added to body, ensuring that the content is centered within the available horizontal space.

This alternative method achieves the desired centering effect without the need for display:table. It's a more straightforward and flexible approach that can adapt to various layout scenarios.

The above is the detailed content of How Can I Horizontally Center a Content Container Without Using `display: table`?. For more information, please follow other related articles on the PHP Chinese website!

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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template