Click here to Skip to main content
15,893,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
So I'm curious, is there a way to get the div layout to be Left, Center, Right without having to put the centered div last? And no, I'm not looking for a Bootstrap solution, I'm just trying to figure this out with divs, to learn the basics. :)

What I have tried:

Given this:
<div style="width:100%">  
  <div style="float:left">Left</div>
  <div>
      <div style="float:right">Right</div>
      <div style="text-align:center;">Left, centered text, and right.  Note that the centered text must come last!</div>  
    </div>
</div>


Works great. But how is the layout engine working, because if I put the centered text before the float:right, like this:

<div style="width:100%">  
  <div style="float:left">Left</div>
  <div>
      <div style="text-align:center;">Left, centered text, and right.  Note that the centered text must come last!</div>  
      <div style="float:right">Right</div>
    </div>
</div>


Then "Right" appears on the next line. OK, that makes sense, but if I try float:left or display:inline the centered text doesn't center.
Posted
Comments
RedDk 16-Mar-16 17:35pm    
God forbid you sould be using Dreamweaver to edit HTML, but I KNOW Visual Studio JUST WORKS. And a developer doesn't even have to deal with code. Slap this there, slap that over here, and ... divs the right way.

I know, just a comment. Reverse engineer something. Do some slapping around and test various panels here and there. Basically, try and break something.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900