I know this is supposed to be the fundamental reason why CSS exists but I contend that CSS fails miserably at it. It is your job to prove me wrong.
Take this example:
<html>
<head>
<title>div test</title>
<style>
html {
font: bold 20px Arial;
color: white;
}
#container {
border: 1px dotted black;
width: 90%;
}
.blue {
background-color: blue;
opacity:0.5;
float: left;
}
.red {
background-color: red;
opacity:0.5;
}
</style>
</head>
<body>
<div id="container">
<div class="blue">Here is some text</div><div class="red"> </div>
</div>
</body>
</html>
And make it so
- the red and blue div share the same line
- the red and blue div do not overlap
- the red and blue divs combined width is 100% of #container
- the blue div automatically occupies as much space as it needs to accommodate the text that is inside of it, no more or less.
- the red div automatically grows/shrinks to occupy the remaining space in #container so that #3 and #4 are both satisfied
I've been trying to do this - what should be - incredibly simple thing for about 3 hours now with no success. The only way that I can do it is by intertwining style and content and adjusting the width of each div based on the amount of text that is in the blue div.