Solved

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

Posted on 2010-08-13
7
977 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
  • 3
  • 3
7 Comments
 
LVL 18

Expert Comment

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

Expert Comment

by:Anil Golamari
Comment Utility
<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
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:webdott
Comment Utility
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
Comment Utility
<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
Comment Utility
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
Comment Utility
thanks
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
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.
In this tutorial viewers will learn how to style a decorative dropcap for the first letter in a paragraph using CSS. In CSS, create a new paragraph class by typing "p.fancy": Then, to style only the first letter of the first sentence, include the ps…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

762 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now