bumbleshoot
bumbleshoot

Reputation: 1160

Div within a div still taking up space even though display:none?

<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
$("select#choosebook").change(function(){
    $(".title").slideDown("medium");
});
</head>

<body>
<div class="booktitle">
    <p>
    <font color="red">*</font>Book:
    <select id="choosebook">
        <option>Choose a Book...</option>
        <option>Add new Book...</option>
    </select>
    <div class="title" style="display:none">**
        <font color="red">*</font>Title: <input type="text">
    </div>
    <font color="red">*</font>Page: <input type="text" class="page">
</div>
</body>
</html>

The div with class "title" still takes up space between the "Book:" input and the "Page:" input, even though it's hidden! Other divs on this web page don't. How can I make it take up no space until the javascript is activated to slide it down?

Thank you!

EDIT: As requested, here is a screenshot of the problem. I'm trying to get rid of the gap between the Book input and the Title input. Before the 'title' input slides down: The stupid gap before the 'title' input slides down. After the 'title' input slides down: The stupid gap after the 'title' input slides down.

And here is my CSS:

<style type="text/css">
    @import url("layout.css");
    .page {
        width: 50px;
    }
    .URL, .booktitle {
        margin-left: 24px;
        display:none;
    }
    .title {
        display: none;
    }
    .newtag {
        display:none;
    }
    .amount, .addtag {
        width: 100px;
    }
    .details {
        width: 275px;
    }
</style>

Upvotes: 5

Views: 4976

Answers (3)

sarcastyx
sarcastyx

Reputation: 2219

If you are talking about the huge space under the Book drop down then that is because of the p tag that you have open in the HTML but forgot to close it. The p tag is adding the default margin. Hence the space. Remove the p tag and the margin should go away.

Also as I mentioned in the comments to your question always add a doctype to you page.

Upvotes: 1

Allan Kimmer Jensen
Allan Kimmer Jensen

Reputation: 4389

The font element is deprecated, use span here. You did not close your script element.

I cleaned up a bit and now you got this:

<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
$("select#choosebook").change(function(){
    $(".title").slideDown("medium");
});
</script>
</head>

<body>
<div class="booktitle">
    <span style="color:red">*</span>Book:
    <select id="choosebook">
        <option>Choose a Book...</option>
        <option>Add new Book...</option>
    </select>
    <div class="title" style="display:none">
        <span style="color:red">*</span>
        Title: <input type="text" />
    </div>
    <span style="color:red">*</span>
    Page: <input type="text" class="page">
</div>
</body>
</html>

You can see the fiddle here: http://jsfiddle.net/Allan/cJ6Jq/ works for me.

Upvotes: 0

JJJ
JJJ

Reputation: 33163

It's not the div that's creating the space, it's the <br> you have right after it.

And please, get rid of the <font> tags. My eyes are bleeding.

Upvotes: 7

Related Questions