Home > Web Front-end > CSS Tutorial > How to Align Multiple DIV Blocks Horizontally?

How to Align Multiple DIV Blocks Horizontally?

Linda Hamilton
Release: 2024-11-03 14:03:02
Original
976 people have browsed it

How to Align Multiple DIV Blocks Horizontally?

Aligning Multiple DIV Blocks Horizontally

Placing multiple DIV blocks on the same horizontal line is a common layout task in web development. To achieve this, follow the steps outlined below:

Set a Parent DIV with text-align: center; to align the child elements horizontally.

Within the parent DIV, set the child DIVs to display: inline;. This allows them to sit side-by-side on the same line.

<code class="css">#block_container {
  text-align: center;
}

#bloc1,
#bloc2 {
  display: inline;
}</code>
Copy after login

Example Content:

<code class="html"><div id="block_container">
  <div id="bloc1"><?php echo " version " . $version . " Copyright &copy; All Rights Reserved."; ?></div>
  <div id="bloc2"><img src="..."></div>
</div></code>
Copy after login

Additional Considerations:

  • Avoid placing raw content directly inside DIV elements. Use appropriate tags like

    or instead.

  • Example:
    <p id="bloc1"><?php echo " version ".$version." Copyright &copy; All Rights Reserved."; ?></p>

Demo:
https://jsfiddle.net/

The above is the detailed content of How to Align Multiple DIV Blocks Horizontally?. 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