CSS - Test Your CSS Skills Number 33 :

CSS - Test Your CSS Skills Number 33 : Quiz now ended - solution in post #44

The last quiz was fantastic but was a little complicated for some so this time we are coming down to solve something a lot easier so that all levels can have a go.

In this quiz we are going to solve a real life problem that affects IE7 and IE6 (and is a real pain at times).

If you look at the attachment called “ff-leftandright” you will see the type of display I am looking for. If you then look at the attachment “ie7-leftandright” you will see what a hash IE7 has made of this simple task.

All we have is a parent that is floated to the left but without a width so that it shrinks wraps its content. Then we place a fixed width element such as an image into the mix. Lastly we float two elements, one left and one right to line up with the element above’s side edges.

All is well in all browsers except IE7 and IE6 and the problem is that a right floated element in a width-less left floated parent will stretch the element to 100% width. The effect is ruined in completely in IE7 and the first element is stretched 100% wide but rather more strangely the second and third elements are broken in a different way to the first.

It just goes to show how badly IE7 gets this wrong.

Your task, should you accept, is to duplicate the FF-leftandright screenshot and make it work in IE6 and IE7 and to look exactly the same and have the same capabilities.

You have to use the html that I provide but you can change the css as much as you want (although one answer doesn’t really require much to be changed at all).

There are some rules (there are always rules):

The main thing is that the parent (.wrap) must be floated left and must have no width.

The second main thing is that the fixed width element could be any size that you define but the layout must work without changing anything else. The point being that you cannot float the right element to the left and then use a fixed margin to push it into position.

You can’t change the html except for the css styles.

It must
work with variable sizes (such as a dynamic image of varying widths) as shown in my example where the same code works with the three different sized elements.

Scripting, images, expressions etc are not allowed.

If any of the above is unclear then just shout and I will clarify.

I reserve the right to plug loopholes should they arise :slight_smile:

Here is the basic html


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
<style type="text/css">
p {
    margin:0
}
.wrap {
    float:left;/* no width allowed*/
    clear:left;
    border:1px solid #ccc;
    padding:10px;
    margin:0 0 10px;
    background:#f2f2f2;
}
.image {
    height:150px;
    border:1px solid #000;
    background:red;
    line-height:150px;
    text-align:center;
}
.i1 {width:300px}/* cater for any width automatically*/
.i2 {width:400px}
.i3 {width:200px}
.f {
    width:75px;
    height:75px;
    border:5px solid red;
    text-align:center;
    margin:1px 0 0;
    background:#ffc;
}
.fl {float:left}
.fr {float:right}
</style>
<!--[if lte IE 7]>
<style type="text/css">

</style>
<![endif]-->

</head>
<body>
<div class="wrap">
    <p class="image i1">Image</p>
    <p class="f fl">Text Left<br>Text Left</p>
    <p class="f fr">Text Right<br>Text Right</p>
</div>
<div class="wrap">
    <p class="image i2">Image</p>
    <p class="f fl">Text Left<br>Text Left</p>
    <p class="f fr">Text Right<br>Text Right</p>
</div>
<div class="wrap">
    <p class="image i3">Image</p>
    <p class="f fl">Text Left<br>Text Left</p>
    <p class="f fr">Text Right<br>Text Right</p>
</div>
</body>
</html>

[B]

[edit]
[/edit][/B][edit][B]To plug the loophole:

I want you to also be able to change the width and height of those 2 little boxes at the bottom and for the layout to still work without having to change the code again. It has to be automatic.[/B]
[/edit][B]

Remember this is just for fun[/B] and there are no prizes.

Don’t post your answers in this thread but PM with the details instead so that all can have a go.

Have fun.:slight_smile:

PS. : In case you missed the other tests you can find them all listed here:

Another correct solution from poetro so well done.:slight_smile:

As mentioned in previous posts It is not the optimal solution that I mentioned before though but similar to a few entries I have had. :slight_smile:

Quick and dirty solution sent.

cheers,

gary

Thanks Gary - that definitely works - well done :slight_smile:

There is another solution (or maybe more) so all entries gratefully received.

There had been a niggling at the back of my mind that there was a more elegant solution. Well, it came to me, and it should have been the first solution.

cheers,

gary

Another quick and dirty solution sent.

Well I’m late to the party but my solution has been submitted as well.

Thanks Gary and Ray have the solution that I wanted :slight_smile: Well done to both.

Eric has a different solution which is quite inventive but not quite as flexible as the other solution. Well done Eric:)

[B]To plug the loophole:

I want you to also be able to change the width and height of those 2 little boxes at the bottom and for the layout to still work without having to change the code again. It has to be automatic.[/B]

Yay a classic simple quiz!
Oh darn, was away (so busy with work) so now im sooo late…
I will have a look later today :smiley:


OH its THIS bug again! I know this one!

Hi Timo - no rush have a go when you can :slight_smile:

I have another entry from Eric Watson which is the same as Gary’s first entry. Well done - but it can still be improved :wink:

Alright! Third solution submitted - that one has to be it?

Quick solution sent before I leave for a few days :slight_smile:

Hi,

Eric yes that’s the right one now well done :slight_smile:

Ryan that is a solution but is the same as the first attempts from Gary and Eric and therefore could be improved but well done anyway :slight_smile:

I like this kind of quiz – usable in the real world and doesn’t take all day to figure out…

  John

Thanks John :slight_smile:

I have your entry and it’s correct - well done and thanks for taking part.:slight_smile:

Submitted my solution :slight_smile:

That was absolutely easy. Only took 3 properties and doesn’t require IE conditionals.

Well done Catharsis that was the correct solution :slight_smile:

Thanks for your entry kingkool68 and that works also but is not the optimal solution but well done anyway. (It’s the same solution that some of the others first gave me.)

Thanks to all entries so far and glad to see some different names for a change :slight_smile:

Right… I’ll see what I can do… it’s been so long since I touched this (the last few months have been less web-wise that I wanted) that I need to refresh my skills (again :D).

It will have to be tomorrow though :smiley:

No Rush Nuria :slight_smile: