Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 8 of 8
  1. #1
    Member
    Join Date
    Apr 2011
    Posts
    81
    Member #
    27344
    Liked
    3 times
    I am trying to show up a section but with a condition:

    if($condition)

    {

    // if condition true show this section

    echo '<div>some text</div>';

    }

    else

    {

    // if condition false show nothing

    echo ' ';

    }

    but when the condition is false, i am ending up with a large white space occupying the area were i will have the div, if the condition is true.

    Can anyone indicate how i can solve this problem?

    Thank you in advance.

  2.  

  3. #2
    Senior Member Webzarus's Avatar
    Join Date
    May 2011
    Location
    South Carolina Coast
    Posts
    3,322
    Member #
    27709
    Liked
    770 times
    Depends on the CSS structure around it and if the space where the div goes. If the surrounding divs have a fixed height, I would suspect you'd see that behavior.

    Not that simple, since we cant see the surrounding CSS elements and their properties.

  4. #3
    Member
    Join Date
    Apr 2011
    Posts
    81
    Member #
    27344
    Liked
    3 times
    the div actually contains a navigation bar with buttons.

    is there any way to avoid this?

    thank you

  5. #4
    Senior Member Webzarus's Avatar
    Join Date
    May 2011
    Location
    South Carolina Coast
    Posts
    3,322
    Member #
    27709
    Liked
    770 times
    Just about anything is possible, but without seeing the code it's impossible to even begin to guess what needs to be done.

  6. #5
    WDF Staff AlphaMare's Avatar
    Join Date
    Oct 2009
    Location
    Montreal, Canada
    Posts
    4,570
    Member #
    20277
    Liked
    878 times
    Just on the face of it, I'd say you need to define what will go there for both true and false, and give the div some CSS to size it.
    Try something like this:

    if($condition)

    {

    // if condition true show this section

    echo '<div id="navbar">some text</div>';

    }

    else

    {

    // if condition false show nothing

    echo '<div id="empty">some text</div> ';

    }

    Use CSS for the empty div with a width the same as the navbar div and a height of 1px. You'll still get a white space but it'll be only 1 pixel high, and you can add a background color to it to match whatever it's on, so it won't show up.
    onlinespider likes this.
    Good design should never say "Look at me!"
    It should say "Look at this." ~ David Craib


    http://digitalinsite.ca ~ my current site . . info@digitalinsite.ca ~ my email

    If you feel that someone's post helped you fix your problem, answered your question, or just made you feel better, feel free to "Like" their post. The "Like" link is at the bottom right of each post, along side the "reply" link. And if you are being helped here, try to help someone else - pass it on!

  7. #6
    Member
    Join Date
    Apr 2011
    Posts
    81
    Member #
    27344
    Liked
    3 times
    Quote Originally Posted by AlphaMare, post: 230022
    Just on the face of it, I'd say you need to define what will go there for both true and false, and give the div some CSS to size it.
    Try something like this:

    if($condition)

    {

    // if condition true show this section

    echo '<div id="navbar">some text</div>';

    }

    else

    {

    // if condition false show nothing

    echo '<div id="empty">some text</div> ';

    }

    Use CSS for the empty div with a width the same as the navbar div and a height of 1px. You'll still get a white space but it'll be only 1 pixel high, and you can add a background color to it to match whatever it's on, so it won't show up.
    thanks a lot for the good idea !
    much appreciated.

  8. #7
    Senior Member Ronald Roe's Avatar
    Join Date
    Mar 2011
    Location
    Oklahoma City
    Posts
    3,141
    Member #
    27197
    Liked
    959 times
    Quote Originally Posted by AlphaMare, post: 230022
    Use CSS for the empty div with a width the same as the navbar div and a height of 1px. You'll still get a white space but it'll be only 1 pixel high, and you can add a background color to it to match whatever it's on, so it won't show up.
    Could also set the height of the "empty" div to 0, and you wouldn't see anything.
    Ron Roe
    Web Developer
    "If every app were designed using the same design template, oh wait...Bootstrap."

  9. #8
    WDF Staff AlphaMare's Avatar
    Join Date
    Oct 2009
    Location
    Montreal, Canada
    Posts
    4,570
    Member #
    20277
    Liked
    878 times
    Quote Originally Posted by Ronald Roe, post: 230027
    Could also set the height of the "empty" div to 0, and you wouldn't see anything.
    I thought of that but for some reason it doesn't seem to want to work on my computer - maybe I did something wrong in the code when I was trying it out...
    Good design should never say "Look at me!"
    It should say "Look at this." ~ David Craib


    http://digitalinsite.ca ~ my current site . . info@digitalinsite.ca ~ my email

    If you feel that someone's post helped you fix your problem, answered your question, or just made you feel better, feel free to "Like" their post. The "Like" link is at the bottom right of each post, along side the "reply" link. And if you are being helped here, try to help someone else - pass it on!


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 12:33 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com