| <!DOCTYPE html> |
| <!-- |
| | If all three of "left", "width", and "right" are "auto": first set any "auto" |
| | values for "margin-left" and "margin-right" to 0. Then, set "left" to |
| | the static position and apply rule: |
| | |
| | 3. "width" and "right" are "auto" and "left" is not "auto", then |
| | the width is shrink-to-fit . Then solve for "right". |
| | |
| | https://www.w3.org/TR/CSS21/visudet.html#abs-non-replaced-width |
| --> |
| <html> |
| <head> |
| <style> |
| body { |
| margin: 0px; |
| } |
| .first { |
| top: 10px; |
| } |
| .second { |
| top: 45px; |
| } |
| .third { |
| top: 80px; |
| } |
| .containing-block { |
| background-color: #2196f3; |
| height: 5px; |
| padding: 10px 0; |
| position: absolute; |
| width: 500px; |
| } |
| .block { |
| /* TODO: Add borders when supported. */ |
| background-color: #3f51b5; |
| display: block; |
| height: 5px; |
| left: auto; |
| padding: 0 100px; |
| position: absolute; |
| right: auto; |
| width: auto; |
| } |
| .auto-margin-left { |
| margin-left: auto; |
| } |
| .non-auto-margin-left { |
| margin-left: 50px; |
| } |
| .auto-margin-right { |
| margin-right: auto; |
| } |
| .non-auto-margin-right { |
| margin-right: 50px; |
| } |
| </style> |
| </head> |
| <body> |
| <div class="first containing-block"> |
| <span> |
| <div class="auto-margin-left non-auto-margin-right block"></div> |
| </span> |
| </div> |
| <div class="second containing-block"> |
| <span> |
| <div class="non-auto-margin-left auto-margin-right block"></div> |
| </span> |
| </div> |
| <div class="third containing-block"> |
| <span> |
| <div class="auto-margin-left auto-margin-right block"></div> |
| </span> |
| </div> |
| </body> |
| </html> |