nbratina Posted September 2, 2013 Share Posted September 2, 2013 Hi! I have this issue: i need to align two different divs inside some tds. One has to be aligned left the other one needs to be aligned absolute center. How can i do it? Example: <table> <tr> <td> <div>Div 1</div> </td> <td> <div>Div 2</div> </td> </tr> </table> Div 1 needs to be aligned left while Div 2 needs to be aligned center (1/2 width). Thank You! Link to comment Share on other sites More sharing options...
Mudsaf Posted September 2, 2013 Share Posted September 2, 2013 (edited) Have you tried this? <table border="1" width="100%"> <!-- Example 100% width, border is for visibility reasons you can remove. --> <tr> <td width="50%" style="text-align:left;"> <!-- Aligns text left (Prob not needed by default) --> <div style="background-color:#CCC; display:inline-blcok;">Div 1</div> <!-- Background set for display reasons, remove if want. --> </td> <td width="50%" style="text-align:center;"> <!-- Centers the div element inside --> <div style="background-color:#CCC; width:200px; text-align:left; display:inline-block;">Div 2</div> <!-- Background for display reasons, text-aligned for left, display inline-block so text-align will apply. --> </td> </tr></table> Either set width to whole table or td's. Edited September 2, 2013 by Mudsaf Link to comment Share on other sites More sharing options...
davej Posted September 2, 2013 Share Posted September 2, 2013 <!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><title>title</title><style>td{width: 200px;border: 1px solid black;}.tcent{text-align: center;}.cent{margin: 0 auto;}div{border: 1px dotted red;width: 100px;}</style></head><body><table><tr><td><div class="cent">Div 1</div></td><td><div class="tcent">Div 2</div></td><td><div class="cent tcent">Div 3</div></td></tr></table></body></html> Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now