centering - Is it possible to center a div with an unspecified width that contains two floating div also with unspecified widths -
i trying 2 elements sit side side inside div or other element, both 2 elements centered in page.
here's catch... cannot use fixed widths, dynamically generated javascript. seem reading other posts not possible without fixed widths, wanted see if 1 had other ideas achieve same result.
html:
<body> <div class="centerdiv"> <div class = float1></div> <div class = float2></div> </div> </body> css:
body {text-align: center; width: 100%;} .centerdiv {margin: 0 auto;width: 100%} div.float1 {float:left; display:inline;} div.float2 {float:left; display:inline;}
you can use follwing code center div side side.
<html> <head> <style type="text/css"> body {text-align: center; width: 100%;} .centerdiv {margin: 0 auto;width: 100%;margin-left:40%;} .float1{border:1px solid black;width:10%;float:left;} </style> </head> <body> <div class="centerdiv"> <div class = float1>hello</div> <div class = float1>hai</div> </div> </body> </html> hope helps!!!!!!
Comments
Post a Comment