Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Positioning one div to the right of another

Tags:

html

css

I have the following html and css. But what I can't figure out is how to have the tabs div at the right of the main div. So that they stick out the right like bookmarks.

.main {
    -moz-border-radius:10px;
    height: 75%;
    width: 60%;
    position: absolute;
    top: 15%;
    left: 20%;
    right: auto;
  }
.tabs {
    width: 50px;
    height: 1.3em;
    position: absolute;
    float: right;
}
 #tab { margin: 10px 10px 10px 0px;}

And the html:

<div class="main">
    <div id="content">
       Some main content
    </div>
 </div>
 <div class="tabs">
     <div class="tabs" id="tab1">
         <a href="#" alt="Home">
             Home
         </a>
      </div>
      <div class="tabs" id="tab2">
          <a href="#" alt="About">
              About
          </a>
      </div>
</div>
like image 765
Jonno_FTW Avatar asked Mar 12 '10 07:03

Jonno_FTW


People also ask

How do I position one div next to another?

With CSS properties, you can easily put two <div> next to each other in HTML. Use the CSS property float to achieve this. With that, add height:100px and set margin.

How do you position an element on the right side?

If position: absolute; or position: fixed; - the right property sets the right edge of an element to a unit to the right of the right edge of its nearest positioned ancestor. If position: relative; - the right property sets the right edge of an element to a unit to the left/right of its normal position.

How do I align two divs side by side?

The most common way to place two divs side by side is by using inline-block css property. The inline-block property on the parent placed the two divs side by side and as this is inline-block the text-align feature worked here just like an inline element does.


1 Answers

There are two general approaches to putting blocks left to right:

  1. Make them inline; or
  2. Use floats.

(1) would be:

div.main, div.tabs { display: inline; }

(2) would be:

div.main, div.tabs { float: left; }

If you do (2) put the divs in a container and add:

div.container { overflow: hidden; }

Each method has particular merits. Most notably inline elements can't have margin attributes applied to them. This is just one of the several constraints on inline vs block layout in HTML.

like image 108
cletus Avatar answered Sep 28 '22 02:09

cletus