In the following, I'd like to alter the CSS such that the right-sibling
is truly centered in the container
div. (Edit: without using absolute positioning).
<html>
<head>
<style type='text/css'>
#container {
width: 500px;
}
#left-sibling {
float: left;
}
#right-sibling {
text-align: center;
}
</style>
</head>
<body>
<div id='container'>
<div id='left-sibling'>Spam</div>
<div id='right-sibling'>Eggs</div>
</div>
</body>
</html>
In its current implementation, the right sibling's centering is affected by the left sibling -- you can see this by adding display: none
to the left-sibling
's style.
(Note: I'd like to avoid modifying the HTML structure because, as I understand it, the whole point of CSS is to decouple the tag structure from the presentation logic, and this doesn't seem like a really crazy request for CSS to handle.)
TIA.