Results 1 to 12 of 12

Thread: Having some trouble with properly clearing floats

  1. #1
    Join Date
    Jul 2008

    Having some trouble with properly clearing floats

    I've nearly finished a theme for Wordpress for my blog, but I've hit one final snag. The page loads strangely, rendering the content before the containing div shows up beneath it. Sort of as if the content were spilling out of the div it resides in. Once the page has loaded, it displays appropriately, however, for people with slower connections the strange load sequence will look awful.

    I figured out that the problem was due to some floats that weren't being cleared properly. Trouble is, when I clear the floats, the sidebars will no longer rest next to the main content, they're shifted down instead, but still floating to the right.

    Here's the staging page:

    Here's the markup for the main template page:

    <div id="mpage">
    	<div id="content">
    			<?php if (have_posts()) : ?>
                <?php while (have_posts()) : the_post(); ?>
                    <span class="post" id="post-<?php the_ID(); ?>">
                        <div class="post">
                            <div class="title">
                                <h1><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h1>
                            <div class="postdata">
                                <span class="date"><span class="author">Posted by <?php the_author() ?> on</span> <?php the_time('M d, Y') ?> <?php edit_post_link(__('Edit')); ?>&nbsp;//&nbsp;</span>
                                <span class="category"><?php the_category(', ') ?></span>
                            <div class="entry">
                                    <?php the_content('Read the rest of this entry &raquo;'); ?>
                                <span class="comments"><?php comments_popup_link('Leave a comment! ', 'Just 1 comment so far!', '% Comments so far, join the discussion!'); ?></span>
    						<?php the_tags( '<p>Tags: ', ', ', '</p>'); ?>
                <?php endwhile; ?>
                  <div class="navigation">
                          <div class="alignleft"><?php next_posts_link('Older Posts') ?></div>
                          <div class="alignright"><?php previous_posts_link('Newer Posts') ?></div>
                  <div class="clear"></div>
    		  <?php else : ?>
                      <h2 class="t-center">Not Found</h2>
                      <p class="t-center">Sorry, but you are looking for something that isn't here.</p>
              <?php endif; ?>
        <div id="sidebars">
                      <div class="sbar1">
                      <?php include(TEMPLATEPATH."/sidebar1.php");?>
                      <div class="sbar2">
                      <?php include(TEMPLATEPATH."/sidebar2.php");?>
        <div class="clear"></div>
    If you pull up the CSS, #content and #sidebars should float next to one another and they do, provided the floats are not cleared. But then the page loads weird. If they're cleared, they won't sit together.

    I've been combing through looking for something that I know is wrong, but I just can't find it.

    I'm hoping someone can give me a hand with this.

  2. #2
    Join Date
    Nov 2006
    Springfield, MO
    Get rid of the clearleft after #content, since you need #content and #sidebar to act as "columns", they need to be floated against each other, not cleared. You should be able to adjust #sidebar to float left, since it comes after #content, and that's floated left. You can more than likely get rid of clearleft, and just use the clear class right after you #sidebar rule ends so that your #footer can clear both of those floats.
    Ryan Butler

    Ryan Butler.org

  3. #3
    Join Date
    Jul 2008
    That resolves the problem of where the columns fall, but it brings back the problem of the awkward page rendering.

    Here's a picture of the page rendering:

    On my computer it only stays like this for a second, but on a slower connection, I'm sure it sits like this for much longer. The thick dark blue border around the top is actually all that has rendered of the containing div that holds the header, the content and the footer. Because of the floats not clearing, it's allowing the content to render before it picks up on it, so all the content has just spilled out.

    Any more ideas of what could be wrong here?

  4. #4
    Join Date
    Jul 2007
    Sounds like it could be a case of Flash of Unstyled Content.

    One quick fix (albeit not the best) is to add a blank <script></script> just before the closing </head> tag.

  5. #5
    Join Date
    Jul 2008
    Well, I tried adding the <script></script> in the head tag, but it didn't solve the problem. It seems as it's loading almost like it would if I'd not cleared a float in the header div, but then it recognizes it and corrects the problem.

    Plus, clearing the floats just after closing #content fixes the loading problem completely, it just keeps it from being able to format correctly on the page.

  6. #6
    Join Date
    Jul 2008
    No more ideas?

  7. #7
    Join Date
    Nov 2006
    Springfield, MO
    I can't replicate the problem on my end, I'm sure the T1 connection isn't helping. I cleared my cache in IE 7 and FF 2 and can't duplicate it. Is there any specific scenario when it happens? What browsers is it happening on?
    Ryan Butler

    Ryan Butler.org

  8. #8
    Join Date
    Jul 2008
    Hmm. I'm using Firefox and Safari on this end. I just realized that I'm only able to duplicate it on the live site which I'm viewing using a staging plugin. It supposed that it was because I'm using a fiberoptic internet connection and the staging site had almost nothing to load.

    Here's the live site with the staging theme:

    It could also be something in the sidebars. I looked through the installed widgets and didn't see any problem there. Maybe I missed something.

  9. #9
    Join Date
    Nov 2006
    Springfield, MO
    Yeah, I see it now. Is there a bad path somewhere in the code? More importantly, is there anything significantly different between the staging server and the live? Such as configurations? At this point, I'd be more inclined to believe there's something different between the two servers.
    Ryan Butler

    Ryan Butler.org

  10. #10
    Join Date
    Jul 2008
    No, the staging site and the live site are just independent installations of Wordpress on the same server. The only difference that I can come up with is that the live site has some plugins and widgets that don't exist on the staging site.

  11. #11
    Join Date
    Jul 2008
    Any more ideas?

  12. #12
    Join Date
    Jul 2008
    little help?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.10669 seconds
  • Memory Usage 2,973KB
  • Queries Executed 15 (?)
More Information
Template Usage (33):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (1)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (12)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (12)postbit
  • (12)postbit_onlinestatus
  • (12)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (73):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates