Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 622871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:01:52+00:00 2026-05-13T19:01:52+00:00

I have this markup: <div class=myToggledDiv> <div>content</div> </div> <div style=margin-top: 10px;> content </div> Via

  • 0

I have this markup:

<div class="myToggledDiv">
    <div>content</div>
</div>

<div style="margin-top: 10px;">
    content
</div>

Via jQuery, I’m doing a .slideToggle to show/hide the top div.

I’d like there to be the 10px space between the two divs at all times, whether collapsed or expanded.

The behavior, however is that as the top div slides down, the 10px margin remains but as soon as the top div is finished sliding down the 10px margin disappears. It appears to be a margin collapse issue perhaps.

The solution I came up with is this:

<div class="myToggledDiv">
    <div>content</div>
</div>

<div style="font-size: 1px">&nbsp;</div>

<div style="margin-top: 10px;">
    content
</div>

The &nbsp; is the key as there needs to be content in the div to ‘separate’ the two and retain the 10px of margin.

I tried the .clearfix:after approach as well, but that doesn’t work in this scenario, so perhaps this is a jQuery centric issue. Has anyone ran into this and found a more elegant solution than the extra div?

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T19:01:53+00:00Added an answer on May 13, 2026 at 7:01 pm

    Believe it or not, you just need to add a 1px padding to the top of the parent container. The problem is, at the end of slideToggle the first div is set to display:none which causes the second div to be smack dab against the parent. Now, its just a CSS bug. If there is no padding set on the parent item, the child items margin will go outside of the parent, and push both items down. By applying a 1px margin to the parent element, you force the margin to stay inside the element:

    <body style="padding-top: 1px">
      <div class="myToggledDiv">
          <div>content</div>
      </div>
    
      <div style="margin-top: 10px;">
          content
      </div>
    </body>
    

    Obviously, you want to remove all of those inline styles and use a separate stylesheet and id’s/classes as needed.

    If you need to offset the extra padding (depending on your layout) you might just be able to use this:

    { margin-top: -1px; padding-top: 1px }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have this html markup: <div id=wrapper> <pre class=highlight> $(function(){ // hide all
I have a markup like this: <div class=sentence> <ul title=list 3> <li> <ul title=list
I have my markup like this (for argument's sake) <div id=content></div> <div id=layout></div> <div
I have this markup x 3: <div class=features> <span class=overlay><img src=img/webdesign.png /></span> <h2>Web Design</h2>
Say i have this markup: <div class='current'> </div> <div class='current'> </div> <div class='current'> </div>
I have markup that looks like this <div class=myDiv><ul> <li><img src=img1.jpg/></li> <li><img src=img1.jpg/></li> .
I have this markup: <div id=container> <h1>Heading</h1> <p>Some text</p> <div class=foo>Some stuff</div> <div class=foo>Some
I have the fallowing markup: <div class=container> <div style=display:none>1</div> <div style=display:none>2</div> <div style=display:none>3</div> </div>
I have the following markup <div class=question> <h2>Title 1</h2> <div class=answer>content 1</div> </div> <div
I have a html markup with some <div> elements like this: <div id=1 class=classic>i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.