开发者

How to split a div into two columns as we split a table?

I actually wanted th开发者_开发技巧e two grids in one div , I mean one grid in right, other in the left .....but for now the grid is appearing down. Its same as you split in a table with two rows !! same as that I need to split a div and add two grids side by side . Hope you get my point . Thanking you all in advance for your awesome support and replies


Create two divs inside your main div

<div id="main">
<div id="left"></div>
<div id="right"></div>
</div>

With CSS, fix each one to the correct side

#left { float:left }
#right { float:right }


It all depends on the design you want to achieve for that table. There are multiple approaches, each of them yielding slightly different results.

  1. You can change the display CSS property on the divs. The best value to use would be table-cell; however, this value is not supported by any version of IE. You can also try inline or inline-block values.
  2. You can make the divs float to the left in their container.
  3. You can use absolute or relative positioning of the divs in their container; however, that approach doesn't work well with fluid designs.
  4. You can switch to span.


This is an expansion of Omar Abid's accepted answer. I started with that and had to make further modifications so it would work in my example of the stated question.

I made this work with class names instead of IDs so I could call the same CSS in multiple instances. This gave me the the ability to simulate two equal size cells. In my example, I set fixed size with ems so that it could preserve its appearance cross a range of table and desktop browser sizes (in my mobile CSS, I have a different strategy).

To align an image in the left div, I had to make a separate block (the last one in the CSS code).

This should address the question in most instances

    <div class="BrandContainer">
        <div class="BrandContainerTitle">
            <h1>...</h1>
        </div>
        <div class="BrandContainerImage">
            <img alt="Demo image" src="..." />
        </div>
    </div>

CSS:

    .BrandContainer
{
    width: 22em;
}
.BrandContainerTitle
{
    vertical-align: top;
    float: right;
    width: 10em;
}
.BrandContainerImage
{
    vertical-align: top;
    float: left;
}
.BrandContainerImage img
{
    width: 10em;
}


Use a table. It makes more sense to use tables where they are more efficient. Things like that is what tables are made for, and div is not made for.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜