code_junkie

Can you find a solution using just css, to make an element centred when it appears on its own, and aligned to the right when it appears with another element?

Nov 12th, 2011
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. <div id="container">
  2. <div id="element1">content</div><div id="element2">content</div>
  3. </div>
  4.  
  5. <div id="container">
  6. <div id="element2">content</div>
  7. </div>
  8.  
  9. div#element2{
  10. width:100px;
  11. margin:0 auto;
  12. }
  13. div#element1{
  14. width:50px;
  15. float:left;
  16. }
  17. div#element1 + div#element2{
  18. width:50px;
  19. float:left;
  20. margin:0;
  21. }
  22.  
  23. div#container div#element2:last-child {
  24. width:100px;
  25. margin:0 auto;
  26. }
  27.  
  28. div#element1{
  29. width:50px;
  30. float:left;
  31. }
  32.  
  33. div##element2{
  34. width:50px;
  35. float:left;
  36. margin:0;
  37. }
  38.  
  39. #container {
  40. text-align:center;
  41. }
  42. #element1, #element2 {
  43. display:inline-block;
  44. }
  45.  
  46. <style>
  47. #container {
  48. margin:0 auto;
  49. width:100px;
  50. }
  51.  
  52. #container table{
  53. width: 100%;
  54. text-align:center;
  55. }
  56.  
  57. #element1{
  58. background-color:#0000ff;
  59. }
  60.  
  61. #element2 {
  62. background-color: #ff0000;
  63. }
  64. </style>
  65.  
  66. <div id=container>
  67. <table cellspacing=0 cellpadding=0>
  68. <tr>
  69. <td id="element1">content</td>
  70. <td id="element2">content</td>
  71. </tr>
  72. </table>
  73. </div>
Add Comment
Please, Sign In to add comment