How Can I Horizontally Align Two Divs Without Using Tables?

Susan Sarandon
Release: 2024-11-22 13:37:10
Original
565 people have browsed it

How Can I Horizontally Align Two Divs Without Using Tables?

Horizontal Alignment of Divs

A common layout task is to align two divs horizontally, with each containing its own title and list. While tables can easily achieve this, using tables for layout is often undesirable. To align divs horizontally without resorting to tables, consider the following approach:

Floating Divs in a Parent Container

Float the divs within a parent container. Floating allows divs to be positioned next to each other horizontally. Ensure the parent container is styled as follows:

.aParent div {
    float: left;
    clear: none;
}
Copy after login
  • float: left: Floats the divs leftward within the parent.
  • clear: none: Allows the divs to flow next to each other without clearing a line.

Example

<div class="aParent">
    <div>
        <span>source list</span>
        <select size="10">
            <option></option>
            <option></option>
            <option></option>
        </select>
    </div>
    <div>
        <span>destination list</span>
        <select size="10">
            <option></option>
            <option></option>
            <option></option>
        </select>
    </div>
</div>
Copy after login

With this approach, the divs will be aligned horizontally, each containing its title and list, without the need for tables.

The above is the detailed content of How Can I Horizontally Align Two Divs Without Using Tables?. 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