Google Groups Home
Help | Sign in
Div auto height
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Expand all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Harris Kosmidhs  
View profile  
 More options Dec 29 2006, 3:05 am
Newsgroups: comp.infosystems.www.authoring.stylesheets
From: Harris Kosmidhs <hkosm...@remove.me.softnet.tuc.gr>
Date: Fri, 29 Dec 2006 10:05:12 +0200
Local: Fri, Dec 29 2006 3:05 am
Subject: Div auto height
Consider the following HTML:

<div class="links">
        <img src="linkimages/logo.gif">
        <h2>title</h2>
        <span><a target="_blank" href="http://">http://</a></span>
        <p>description of link</p>
</div>

I have the following CSS:
div.links {
        width:auto;
        margin:8px;
        margin-bottom:13px;
        border-bottom:1px solid;

}

div.links h2 {font-size:110%;text-align:left;}
div.links span a{text-align:left;font-weight:bold;}
div.links p{text-align:left;font-size:80%;}
div.links img {float:left;padding:0px 10px 0px 0px;}

Now in my HTML I have plenty of <div class="links"> the one under another.

If the image is big and the description short then the image extends
outside the div. How can I overcome this behavior and have a div that
extends at 100% of the necessary height? (i have already tried
height:auto with no luck)

thanks


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ben C  
View profile  
 More options Dec 29 2006, 3:41 am
Newsgroups: comp.infosystems.www.authoring.stylesheets
From: Ben C <spams...@spam.eggs>
Date: Fri, 29 Dec 2006 02:41:14 -0600
Local: Fri, Dec 29 2006 3:41 am
Subject: Re: Div auto height
On 2006-12-29, Harris Kosmidhs <hkosm...@remove.me.softnet.tuc.gr> wrote:

height: auto is what they are already, and divs don't grow in height to
contain floats that overflow them[1]

We want the bottom border to clear the floats. We can achieve this by
making the bottom border an element in itself, and setting clear on it.

So if you change your margin on .links to

    margin:8px 8px 0 8px;

i.e. all 8px except bottom (unless I got the order wrong there).

and then create a new selector:

    div.separator
    {
        border-bottom: 1px solid;
        margin-bottom:13px;
        clear: left;
    }

Then after each <p>description</p> add

    <div class="separator"></div>

in the content.

[1] divs _do_ grow to contain the divs inside them if they are
themselves the "block formatting context boxes" for the floats, which
they are if they are floated or positioned themselves.

So we can fix this another way without moving the borders to extra
separating divs by adding this to div.links:

    float: left;
    clear: left;
    width: 100%;


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Harris Kosmidhs  
View profile  
 More options Dec 29 2006, 6:32 am
Newsgroups: comp.infosystems.www.authoring.stylesheets
From: Harris Kosmidhs <hkosm...@remove.me.softnet.tuc.gr>
Date: Fri, 29 Dec 2006 13:32:36 +0200
Local: Fri, Dec 29 2006 6:32 am
Subject: Re: Div auto height

yes it works thanks.
But I would like to clear this out a bit. How float affects div's
height? I thought float is used to position -maybe not the right word
here, forgive my english- the element to its parent element.

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ben C  
View profile  
 More options Dec 29 2006, 9:13 am
Newsgroups: comp.infosystems.www.authoring.stylesheets
From: Ben C <spams...@spam.eggs>
Date: Fri, 29 Dec 2006 08:13:09 -0600
Local: Fri, Dec 29 2006 9:13 am
Subject: Re: Div auto height
On 2006-12-29, Harris Kosmidhs <hkosm...@remove.me.softnet.tuc.gr> wrote:

Yes it is. But a float also "establishes a new block formatting
context", which means it grows to fit the floats inside it in.

In this case the float doesn't actually visibly float to the left itself
because we make it width: 100%. We make it float:left not to make it
float to the left, but just to get the sideffect of starting a new block
formatting context.

Normally floats overflow their containers. This is so you can write
content like this:

<p> text blah blah <img style="float: right;" src="foo.png"> </p>
<p> more text blah blah blah </p>

In this example, if the first paragraph grew to fit the float in,
there'd be a vertical gap between the two paragraphs. This is less
desirable than the second paragraph starting in its proper place,
immediately below the first paragraph, but also flowing around the
float.

So that's why the float overflows its containing box. But it doesn't
overflow its block formatting context box.

CSS 2.1 9.4.1:

"Floats, absolutely positioned elements, inline-blocks, table-cells, and
elements with 'overflow' other than 'visible' establish new block
formatting contexts."

And then in CSS 2.1 10.6.7 ("'Auto' heights for block formatting context
roots"):

"In addition, if the element has any floating descendants whose bottom
margin edge is below the bottom, then the height is increased to include
those edges. Only floats that are children of the element itself or of
descendants in the normal flow are taken into account, e.g., floats
inside absolutely positioned descendants or other floats are not."

Why these extra rules?

One possible reason is to make the implementation easier. Floats are
already harder to implement than most things in CSS because text in
sibling, descendent, or descendent-of-sibling blocks has to be flowed
around them. This introduces extra complexity by breaking the assumption
that you can make almost everywhere else that the layout of an element
is only affected by its ancestors and descendents. If you can keep
floats inside their block formatting contexts however, you can limit
that complexity a bit.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Bergamot  
View profile  
 More options Dec 29 2006, 3:03 pm
Newsgroups: comp.infosystems.www.authoring.stylesheets
From: Bergamot <berga...@visi.com>
Date: Fri, 29 Dec 2006 14:03:41 -0600
Local: Fri, Dec 29 2006 3:03 pm
Subject: Re: Div auto height

Harris Kosmidhs wrote:
> div.links img {float:left;padding:0px 10px 0px 0px;}

> If the image is big and the description short then the image extends
> outside the div. How can I overcome this behavior and have a div that
> extends at 100% of the necessary height?

http://www.quirksmode.org/css/clearing.html

--
Berg


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google