/    Sign up×
Community /Pin to ProfileBookmark

relative positioning problem

im trying to make a div visible and bigger at a relative position, but the problem is when it becomes visible, it pushes all the text below it down… even though its relative. im lost please help me.

throw this is a .html file, then it will be really easy to understand my problem.

[CODE]
<html>
<head>
<style type=”text/css”>
.rightli {height:100px;padding:0;margin:0;width:150px;background-color:lightgrey;}
ul {list-style:none;margin:0;padding:0;width:150px;}
#dyes {background-color:black;left:161px;position:relative;margin:0;padding:0;top:5;width:0px;height:0;visibility:hidden;}
</style>
<script type=”text/javascript”>
function showmore(which)
{
show = document.getElementById(which);
show.style.height = “auto”;
show.style.width = “auto”;
show.style.visibility = “visible”;
}
function closemore(which)
{
show = document.getElementById(which);
show.style.height = “0px”;
show.style.width = “0px”;
show.style.visibility = “hidden”;
}
</script>
</head>
<body>
<ul>

<div id=”both” onMouseOver=”showmore(‘dyes’)” onMouseOut=”closemore(‘dyes’)”>
<li class=”leftli” style=”border-top:1px solid black;border-right:none;”>Dyes</li>
<div id=”dyes”>
<li class=”rightli”>all</li>
<li class=”rightli”>cool</li>
</div></div>

text that i dont want to move down when you hover over “dyes”
</body>
</html>
[/CODE]

to post a comment
CSS

7 Comments(s)

Copy linkTweet thisAlerts:
@CentauriOct 02.2008 — Relative positioning only causes an object to display in a location offset to where it actually is, and does not affect the object's ability to interact with other objects - I would suggest that what you want is absolute positioning which will remove the div from the normal document flow.
Copy linkTweet thisAlerts:
@NatdizzleauthorOct 02.2008 — thanks for the reply, yes thats how i had it a little while ago and it worked fine. although when i want to plug in into a website (or let people download my menu for free) it will be really hard to plug it in.
Copy linkTweet thisAlerts:
@CentauriOct 02.2008 — Should also point out that the only thing that can be a direct child of a <ul> is an <li>, so the div is invalid where it is, and not needed anyway.

If this is a menu system, then the submenus should be children of the main menu items in order to make sense - then there is no need for the javascript and the whole thing can be done with css suckerfish style.
Copy linkTweet thisAlerts:
@NatdizzleauthorOct 02.2008 — http://www.htmldog.com/articles/suckerfish/dropdowns/example/vertical.html

yes this exactly what im trying to do, thanks.

i have all of that made already, i was just wondering if there was a way to do it without defining top and left distance. guess not
Copy linkTweet thisAlerts:
@NatdizzleauthorOct 02.2008 — ah indeed, your right i dont need the div there if im positioning that element absolutely anyway
Copy linkTweet thisAlerts:
@NatdizzleauthorOct 02.2008 — so apparently im going to have to cross browser test and write a ton of CSS conditional statements so everything lines up.. i know theres a better way to do this, ****.
Copy linkTweet thisAlerts:
@CentauriOct 02.2008 — To make this more cross-browser friendly, don't use "auto" for the left positioning on hover (browsers have to guess the actual desired location then, and sometimes get it wrong) - use the <li> width instead. Also, specify the top position instead of top margin for the same reason :[CODE] #nav li ul { /* second-level lists */
position : absolute;
left: -999em;
[COLOR="Red"]top: 0[/COLOR];
}

#nav li:hover ul, #nav li li:hover ul, #nav li li li:hover ul, #nav li.sfhover ul, #nav li li.sfhover ul, #nav li li li.sfhover ul { /* lists nested under hovered list items */
[COLOR="Red"]left: 11em;
margin-left: 1px;[/COLOR]
}[/CODE]
×

Success!

Help @Natdizzle spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.21,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...