/    Sign up×
Community /Pin to ProfileBookmark

IE7: Problems with width:100% inside width:auto

Hello,

I made this very simple HTML representing a box with a title and a content layers within it. The idea is that the BOX itself will never have a fixed width so that it should expand as necesary depending on it’s content.

It is working on FIREFOX and SAFARI but it’s giving problems on IE7 and It’s getting very difficult to find a good solution

This is the XHTML code:

[code]
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd “>
<html xmlns=’http://www.w3.org/1999/xhtml’ xml:lang=’en’ lang=’en’>
<head>
<meta http-equiv=’Content-Type’ content=’text/html; charset=iso-8859-1′ />

<style>
#box {
border: 2px #000000 groove;
position:absolute;
top:30%;
left:30%;
}
#title {
width:100%;
background-color:#E0E0E0;
border-bottom:1px #000000 groove;
}

</style>
<body>

<div id=”box”>
<div id=”title”> Box title </div>
<div id=”content”> Box content goes here. The box itself and the tiele should adapt to the with of this DIV. </div>
</div>

</body>
</html>
[/code]

The #box DIV has position:absolute and width:auto; so that it will expand depending on it’s content. This is working just fine.

The problem is that the #title DIV has width:100%, wich indicates that it may expand to the 100% of it’s container (#box), this works fine in most browsers but Internet Explorer 7 seems to get conffussed if the container has a width:auto value.

If I give a fixed value (like 200px or 30%) to #box DIV, then it will work. But I cannot do that, the content is dynamically changing almost all the time.

(NOTE: Theres a JavaScript fix to this but I would love to avoid it if possible).

Thanks so much for any help!

Ed

to post a comment
CSS

5 Comments(s)

Copy linkTweet thisAlerts:
@James_liJun 24.2010 — it may help:

try to remove the width:100&#37; of #title, just keep it auto,too.
Copy linkTweet thisAlerts:
@KorJun 24.2010 — 
The #box DIV has position:absolute and width:auto; so that it will expand depending on it's content. This is working just fine.[/QUOTE]

Not really. Your #box div has [I]no specified width[/I], which is not the same thing as a width auto. DIV are block-level elements, thus they will take up the whole available width of their parent by default, if no width is specified.

It is true that IE6 and IE7 have a bug concerning the width 100&#37;. The solve is simple: use [B]width:auto[/B]. Or, as James said, don't give any width at all.
Copy linkTweet thisAlerts:
@Edu_09authorJun 24.2010 — Hello KOR, thanks for reply.

Did you try my example? The position:absolute; changes the way the a DIV with WIDTH:AUTO behaves.

When a DIV has no width specified, the defaul will be AUTO. Then, when a DIV has ABSOLUTE positioning, like #box, the "AUTO" value indicates that it will expand as necesary depending on it's contents.

Just check the example and you will see.
Copy linkTweet thisAlerts:
@KorJun 25.2010 — You were not attentive. Try [B]width:auto[/B]. Once again: [I]no width[/I] is not the same with width:auto, despite the general belief. And, as I said, IE6 and IE7 have a bug regarding the width:100&#37;

Use this:
<i>
</i>#title {
[B][COLOR="Blue"]width:auto;[/COLOR][/B]
background-color:#E0E0E0;
border-bottom:1px #000000 groove;
}
Copy linkTweet thisAlerts:
@oblFeb 10.2012 — Hi,

I tested all of these and nothing.

Here is my simple solution for width: 100% in IE7:

*min-width: 100%;

Tested it works.

Nedko Hadzhiev

Web Developer

Etaligent.Net
×

Success!

Help @Edu_09 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...