Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Overlapping DIVS (PLEASE HELP)

Featured Replies

Hi guys,

 

Im adding a top bar to my site, basically it will be a fixed bar that has just a few functions so the user doesn't have to scroll right back to the top all time. Its going okay but I've hit a bit of a problem. basically when the browser window is resized all the divs on the bar seem to overlap my search box. This usually wouldn't be a problem but my site resizes itself on iphones,ipads etc so this needs to look right.

 

Ive tried all sorts of random code, adding float, clear tags etc but cannot figure this out. As you can proberly see from the code below, CSS isn't my strong point.

 

PICTURES OF PROBLEM

 

Before

 

29ok1lz.png

 

After

 

2z5ru4o.png

 

 

CSS

 

#floattop {
background-color: black;
width: 100%;
height: 39px;
z-index: 1000;
position:fixed;
left:0px;
right:0px;
overflow:hidden;

}

#topsearch {
width:30%;
margin: 0px auto;
min-width:200px;
max-width:300px;
position:relative;


}

.topsocial {
position:relative;
top:-30px;
float:right;
margin-right:2px;
padding-right:5px;
margin-left:2px;


}

#homeicon {
float:left;
position:relative;
top:-36px;

}

.login {
position:relative;
top:-32px;
float:right;
vertical-align:middle;
margin-right:2px;
margin-left:2px;
color:white;
margin-right:4px;
}

.login a {
color:white;
}

#topnav {
display:block;
float:left;
margin: 0 auto;
height:42px;
position:relative;
top:-20px;
}

 

 

Any help would be greatly appreciated. Thanks in advance

 

Jack

What does your markup look like? I can see a couple of problems in your CSS already, but helps to have both. The main issue is you're mixing relative and fixed positioning - position: fixed is like position: absolute, it removes a element from the document flow, so you can't use floats to reflow it.

change positions to absolute and place everything inside a container

so like this

 

<div class="topBar">

[indent]<div class="barcontainer">
[indent]<img src="" class="img"></img> etc. etc.[/indent]

</div[/indent]
</div>

 

then

.img{
margin-left:150px;
position:absolute;
}

 

 

et

  • Author

What does your markup look like? I can see a couple of problems in your CSS already, but helps to have both. The main issue is you're mixing relative and fixed positioning - position: fixed is like position: absolute, it removes a element from the document flow, so you can't use floats to reflow it.

 

Sorry for the late reply, was away from my computer yesterday. Anyway here is my dodgy markup lol thanks again.

 

<!-- Start Top Fixed Banner -->
	<div id="floattop">
					<div id="topsearch">
                   	<?php get_search_form(); ?>
                   	</div>

                   	<div class="login">
                   	<?php wp_loginout(); ?>
                   	</div>

                   	<div class="login">
                   	<?php wp_register('', ''); ?>
                   	</div>

                   	<div class="topsocial">
                   	<img src="<?php bloginfo('template_directory'); ?>/library/images/fb.png" title="" alt="" />
                   	</div>
                   	<div class="topsocial">
                   	<img src="<?php bloginfo('template_directory'); ?>/library/images/gplus.png" title="" alt="" />
                   	</div>
                   	<div class="topsocial">
                   	<img src="<?php bloginfo('template_directory'); ?>/library/images/twitter.png" title="" alt="" />
                   	</div>
                   	<div class="topsocial">
                   	<img src="<?php bloginfo('template_directory'); ?>/library/images/youtube.png" title="" alt="" />
                   	</div>

                   	<div id="homeicon">
                   	<img src="<?php bloginfo('template_directory'); ?>/library/images/homeicon.png" title="" alt="" />
                   	</div>

                   	<div id="nav2" class="nav">
                   	<?php wp_nav_menu( array('menu' => 'topmenu' )); ?>
                   	</div>
	</div>
	<!-- End Top Fixed Banner -->

  • Author

change positions to absolute and place everything inside a container

so like this

 

<div class="topBar">

[indent]<div class="barcontainer">
[indent]<img src="" class="img"></img> etc. etc.[/indent]

</div[/indent]
</div>

 

then

.img{
margin-left:150px;
position:absolute;
}

 

 

et

 

Hi D,

 

If you look at my markup, above (just posted) my code is all inside a container called floattop ? is that what you mean? On changing my positioning to absolute my bar went a little crazy and everything has disappeared? Any ideas what ive done wrong haha ?

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.