Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

how to align div's side by side in the center of web page

Posted on 2010-08-13
7
Medium Priority
?
1,001 Views
Last Modified: 2012-05-10
how do i align the 3 divs in the center of the page?

thanks


<html>
<head>
      <title>Untitled</title>
   
      <style type="text/css">
            #h1   {width:200px; text-align:center; float:left}
            #h2   {width:200px; text-align:center; float:left}
            #h3   {width:200px; text-align:center; float:left}
      </style>

</head>

<body>

		<div align="center" style="background-color: #E7EFEF">
		<div id="h1">hello 1<br>
		</div>
		<div id="h2">hello 2<br>
		</div>
		<div id="h3">hello 3</div>
		
		<br>

		</div>
</body>
</html>

Open in new window

0
Comment
Question by:webdott
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 18

Expert Comment

by:Anil Golamari
ID: 33433183
div#container
{
      margin-left: auto;
      margin-right: auto;
      
}
0
 
LVL 18

Expert Comment

by:Anil Golamari
ID: 33433246
<style type="text/css">
            #h1   {width:200px; text-align:center;  margin-left:auto; margin-right:auto }
            #h2   {width:200px; text-align:center;  margin-left:auto; margin-right:auto}
            #h3   {width:200px; text-align:center;  margin-left:auto; margin-right:auto}
      </style>

Try this.
0
 

Author Comment

by:webdott
ID: 33433335
i tried this;



      Untitled
   
     





            
            hello 1

            
            hello 2

            
            hello 3
            
            


            



it aligned in the center, but it aligned them on top of each other rather than side-by-side
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:webdott
ID: 33433409
sorry - that did not include the divs
<html>
<head>
      <title>Untitled</title>
   
      <style type="text/css">
      		#container	 {margin-left:auto; margin-right:auto }
            #h1   		 {width:200px; text-align:center; margin-left:auto; margin-right:auto }
            #h2  		 {width:200px; text-align:center; margin-left:auto; margin-right:auto }
            #h3  		 {width:200px; text-align:center; margin-left:auto; margin-right:auto }
      </style>

</head>

<body>

		<div style="background-color: #E7EFEF" id="container">
		<div id="h1">hello 1<br>
		</div>
		<div id="h2">hello 2<br>
		</div>
		<div id="h3">hello 3</div>
		
		<br>

		</div>
</body>
</html>

Open in new window

0
 
LVL 18

Expert Comment

by:Anil Golamari
ID: 33433460
<html>
<head>
    <title>Untitled</title>
    <style type="text/css">        
        #LeftBox
        {
            float: left;
            width: 300px;
        }
        #RightBox
        {          
           
            margin: -5px 0 0 0; /* positions the box next to the other. This will have to be adjusted depending on the LeftBox.*/
        }
        #ThirdBox
        {
              float: right;
           
            margin: -40px 0 0 0;
        }
    </style>
</head>
<body>
    <div id="LeftBox">
        <p>
             hello 1</p>
    </div>
    <div id="RighBox">
        <p>
             hello 2</p>
    </div>
    <div id="ThirdBox">
    <p>
           hello 3</p>
    </div>    
</body>
</html>

This should fix it.
0
 
LVL 16

Accepted Solution

by:
HagayMandel earned 2000 total points
ID: 33436669
If by center of the page you men horizontally centered, then this is it:
<html>
<head>
<title>Untitled</title>
<style type="text/css">
#h1   {width:200px; text-align:center; display: inline;}
#h2   {width:200px; text-align:center; display: inline;}
#h3   {width:200px; text-align:center; display: inline;}
#wrapper {clear: both; margin-right: auto; margin-left: auto; width: 100%;}
</style>
</head>
<body>
      <div align="center" id="wrapper">
      <div id="h1">hello 1</div>
      <div id="h2">hello 2</div>
      <div id="h3">hello 3</div>
      </div>
</body>
</html>
0
 

Author Closing Comment

by:webdott
ID: 33451107
thanks
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
The viewer will learn how to count occurrences of each item in an array.

664 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question