Solved

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

Posted on 2010-08-13
7
999 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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 

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 500 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

WordPress Tutorial 2: Terminology

An important part of learning any new piece of software is understanding the terminology it uses. Thankfully WordPress uses fairly simple names for everything that make it easy to start using the software.

Question has a verified solution.

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

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

627 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