lower div overlapping the upper div - css

Been racking my brains over this for a while now without any luck. I have a page made of two columns. the left column floats left, and the right column floats right. Inside each column are two divs that are meant to sit one above the other. In the right column they appear to do this fine, with a form above and a div underneath as it should be, but in the left column the lower div overlaps the bottom of the upper div by something like 15px or so.
Heres the index.php:
<!-- wraps entired contents of website below header -->
<div id="mainWrap">
<div id="leftColumn">
<!-- module for most recent posts -->
<article id="recentPosts">
<h1>Recent Submissions</h1>
<section id="recentPostsContent">
<p>upper right div content</p>
</section>
</article><!-- close recentPosts -->
<!-- Pagination -->
<div id="pagination">
<p>lower left div content</p>
</div>
<!-- end pagination -->
</div><!-- close left column -->
<div id="rightColumn">
<!-- Search bar -->
<form id="searchForm" action="search.php" method="post">
<input class="navSearchInput" type="text" name="searchInput" placeholder="search here.."/>
<input class="navButtonSearch" type="submit" name="submitSearch" value="Search" />
</form>
<!--end search bar -->
<!-- randomly generated image linking to a post -->
<article id="randomPost">
<h1>Hightlighted Post</h1>
<section id="randomPostContent">
<p>content</p>
</section>
</article><!-- close randomPost -->
</div><!-- close right column -->
<div style="clear:both;"></div><!-- clears floating columns -->
</div><!-- close mainWrap -->
and the related css:
#mainWrap{
margin:0 auto;
width:980px;
min-height:700px;
margin-top:20px;
}
#leftColumn{ border:1px solid green;width:700px;float:left;margin:0 0px 0 0;min-height:500px;}
#recentPosts{width:700px;height:310px;}
#recentPostsContent{
width:700px;
height:300px;
border:1px solid #dfdfdf;
border-radius:0 0 3px 3px;
margin:0 0 20px 0;
}
#recentPosts h1{
width:652px;
}
#pagination{
width:700px;
height:40px;
border:1px solid #dfdfdf;
border-radius:0 0 3px 3px;
}
#rightColumn{border:1px solid green;width:254px;float:right;min-height:500px;}
#randomPost h1{width:205px;}
#randomPost{
width:250px;
height:310px;
}
#randomPostContent{
width:253px;
height:300px;
border:1px solid #dfdfdf;
border-radius:0 0 3px 3px;
}
Why is the lower div overlapping like it is?
Here is a link to the webpage in question: www.chrismepham.com/sites/newmjbox/index.php

The problem is that you've explicitly set the height of #recentPosts to 310px, which causes the height to be capped. If you remove this, it should behave normally.

The real height of #recentPosts is more than the one you set in your CSS (310px). This causes the strange behaviour on #pagination

Related

Cant centre div in another div

I have a div in that div there are two other div. One has got to be on the left side and the other must be in the center but is with margin 0 when i check
<div class="row">
<!-- START LOGO -->
<div id="logo" class="span3">..</div>
</div>
<!-- END LOGO -->
<!-- START MENU - TOPBAR -->
<div id="nav-topbar" class="span9">...</div>
</div>
and this is the css
.row{
width:100%;
}
.span3{
float:left;
position:absolute;
width 270px;
}
.span9{
margin-left:auto;
margin-right:auto;
width:870px;
}
HTML
<div class="row">
<!-- START LOGO -->
<div id="logo" class="span3">..</div>
<!-- END LOGO -->
<!-- START MENU - TOPBAR -->
<div id="nav-topbar" class="span9">...</div>
<!-- END TOPBAR -->
</div>
CSS
Note: I have added black borders so you can see the outline of the divs.
.row{
width:100%;
}
.span3{
border:1px solid black;
float:left;
width:270px;
}
.span9{
border:1px solid black;
left:50%;
margin-left:-435px;
position:absolute;
width:870px;
}

CSS header doesn't go center

I'm trying to get navigation bar of height 40px on the top which I've now, Also I position:fixed; the only problem is, everything what I put inside the divs he showing up to the right and not at the center which I want, the navigation bar need to be 100%
JS Fiddle
this is my .css code:
.container{
height:auto;
margin-top:-10px;
margin-left:-7px;
}
/*========================= TOP HEADER =========================*/
.banner{
margin: 0pt auto;
width:100%;
background-color:#d9d8d6;
border-style:solid;
border-width:1px;
border-color:#000000;
position:fixed;
position: absolute;
}
.banner-container{
height:40px;
background-image:url('http://i.imgur.com/WoVWvmy.png');
background-size:40px 30px;
background-repeat:no-repeat;
position:center;
text-align:center;
}
These divs I use in index.php
<div class="container">
<div class="banner">
<div class="banner-container">
</div> <!-- END BANNER-CONTAINER -->
</div> <!-- END BANNER -->
</div> <!-- END CONTAINER -->
I restructured a little bit. Please see: JS Fiddle
HTML
<div class="banner">
<div class="banner-container"></div>
<!-- END BANNER-CONTAINER -->
</div>
<!-- END BANNER -->
CSS
body {
margin: 0;
}
/*========================= TOP HEADER =========================*/
.banner {
margin: 0pt auto;
width:100%;
background-color:#d9d8d6;
border-style:solid;
border-width:1px;
border-color:#000000;
position:fixed;
}
Here's your best bet.
Note I changed the HTML to use an img tag. It's easier to center these, and to manage them in general, than to do the same with CSS backgrounds:
<div class="container">
<div class="banner">
<img src="http://i.imgur.com/WoVWvmy.png" class="banner-container" />
</div> <!-- END BANNER -->
</div> <!-- END CONTAINER -->
CSS:
.container{
height:auto;
}
/*========================= TOP HEADER =========================*/
.banner{
width:100%;
background-color:#d9d8d6;
border-style:solid;
border-width:1px;
border-color:#000000;
text-align: center;
}

Third, right-floating div is below the middle one

I'm going for three columns (I didn't want this originally but it looks best for my project). The right-hand one is insisting on staying below the middle one even while it floats on the right. What should I change?
The whole thing will actually be put inside another div, but that doesn't seem to be relevant. I've simplified the code down to the problematic area:
<style>
.contain {
border:1px solid;
width:639px;
height:500px;
}
.subAreaLeft{
float:left;
position:relative;
width:205px;
border:1px solid;
}
.subAreaMid{
margin: 0 auto;
position:relative;
width:205px;
border:1px solid;
}
.subAreaRight{
width:205px;
position:relative;
float:right;
border:1px solid;
}
</style>
</head>
<body>
<div class="contain">
<div class="subAreaLeft" id="contactInfo">
ONE
</div>
<div class="subAreaMid">
TWO
</div>
<div class="subAreaRight">
THREE
</div>
</div>
</body>
In order for all three of the divs to float to the left, all three of the divs need float: left in the CSS.
<body>
<div class="contain">
<div class="subAreaLeft" id="contactInfo">
ONE
</div>
<div class="subAreaRight">
THREE
</div>
<div class="subAreaMid">
TWO
</div>
</div>
</body>
you just need to put middle DIV after the THird
http://jsfiddle.net/zJkHE/ check this
The solution is not to modify any CSS. Leave that alone.
Instead, move the subAreaMid div to directly after subAreaRight in the HTML.
<div class="subAreaLeft" id="contactInfo">
ONE
</div>]
<div class="subAreaRight">
THREE
</div>
<div class="subAreaMid">
TWO
</div>
This ensures that the subAreaMid div will not clear, and gives the desired result.

make div larger than container

with the code below I am trying make "ThumbNails" as large as the contet (dynamic) requires and show (only) an horizontal scrollbar if not fitting in the contining div but I am failing.
What am I doing wrong?
html:
<body>
<div id="Fascione"></div>
<div id="Wrapper">
<div id="Menu"></div>
<div id="Contenuto">
<div id="VariableImg"></div>
<div id="Back"></div>
<div id="Next"></div>
<div id="ThumbNails">
<img><img><img>
</div>
</div>
</div>
<div id="Footer"></div>
</body>
css:
body{width:1024px; margin:0px auto;}
div#Fascione{width:inherit;min-height:125px;border-bottom:2px solid black;}
div#Wrapper{width:inherit;padding:8px 0px 4px 0px;}
div#Wrapper{width:inherit;padding:8px 0px 4px 0px;}
div#Menu{float:left;width:200px;}
div#Contenuto{overflow:hidden;margin-left:208px;}
div#Back, div#Next{width:49%;cursor:pointer;text-align:center;margin:1% auto;border:1px dotted #1111cc;background-color:#ffffff;}
div#Back{float:left;}
div#Next{float:right;}
div#Back:hover, div#Next:hover{border:1px solid #1111cc;}
div#ThumbNails{clear:both;max-height:180px;overflow-x:auto;overflow-y:hidden;background-color:#f0f0f0;}
div#Footer{clear:left;width:inherit;} /* clear left needed in combination with the overflow:hidden of Contenuto */
Edited: removed old, invalid link.
As pointed out by #My Head Hurts the proper answer is to add white-space:nowrap;.

How to layout a image gallery?

I am making an image gallery, and I need to display images in a grid like layout. I don't want to use any frameworks, and would prefer to do things from scratch. Also, I would prefer not to use tables for the layout, since it will be a pain to add images to the table dynamically.
The layout consists of divs, like:
<div id="gallery">
<div class="uPic">
<img src="1.png">
<p> description </p>
</div>
<div class="uPic">
<img src="2.png">
<p> description </p>
</div>
....
......
....
</div>
to achieve the grid look, I simply "float"-ed all .uPics to left....and given some padding and margin to the #gallery. So far everything works great.
The PROBLEM starts, when I try to give a hover effect to the images. initially the <p> is hidden, and I use jQuery to show it on hover. but on doing so, the images below the one I am hovering over, shifts towards the right instead of moving down. Any ideas?
If the height of your divs is variable then I would recommend either using clear:both on the first element of each new row OR putting each row in its own container div. Otherwise, as you've noticed, the divs under the selected one will probably be pushed to the side of the higher div instead of shifting down.
I'd also consider Matt's solution as divs moving around on mouseover imho gives a very chaotic look to a page.
But if you're set on doing it this way, check out this example:
<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">
$(document).ready( function() {
$('#gallery .image p').hide();
$('#gallery .image').hover(
function() { $(this).find('p').show() },
function() { $(this).find('p').hide() }
);
});
</script>
<style>
#gallery {
width: 800px;
}
#gallery .image {
width: 200px;
float: left;
background: #eee;
margin-bottom: 10px;
}
#gallery .image.newline {
clear: both;
}
#gallery .image .placeholder {
width: 180px;
height: 200px;
margin: 10px;
background: #ccf;
}
#gallery .image p {
margin: 10px;
background: #fcc;
}
</style>
</head>
<body>
<div id="gallery">
<div class="image">
<div class="placeholder"></div>
<p>My description</p>
</div>
<div class="image">
<div class="placeholder"></div>
<p>My description</p>
</div>
<div class="image">
<div class="placeholder"></div>
<p>My description</p>
</div>
<div class="image">
<div class="placeholder"></div>
<p>My description</p>
</div>
<!-- NOTE the added "newline" class where the new line starts! -->
<div class="image newline">
<div class="placeholder"></div>
<p>My description</p>
</div>
<div class="image">
<div class="placeholder"></div>
<p>My description</p>
</div>
<div class="image">
<div class="placeholder"></div>
<p>My description</p>
</div>
</div>
</body>
</html>
The w3schools has a sample image gallery all in CSS. They add a border on hover of the image.
I would maybe set the width and height of the paragraph, and fix it using absolute positioning relative to the enclosing uPic div. That way you can have the paragraph of description appear "above" the image on hover without disturbing the flow. So, add position: relative; to the uPic, add something along the lines of position: absolute; left: 0px; top: 0px; to the <p>, and then adjust other things to suit.
I suggest that you choose a fixed height and width for your div :
It may fix your problem
It is not convenient for the user when a whole part of the grid is moving just to show up a little description, whether it is downward or to the right
I think this may be helpful
<style type="text/css" ><!--
#gallery_box{
width:728px;
height:545px;
border:solid #cccccc 1px;
margin:20px auto 0px;
padding:5px;
-moz-box-shadow:0px 18px 40px #ccc;
-webkit-box-shadow:0px 14px 40px
#ccc;
box-shadow:0px 5px 30px #ccc;
}
#thumbnail{
width:160px;
height:160px;
background:#f6f6f6;
border:solid #cccccc 1px;
border:solid #cccccc 1px;
margin:5px;
padding:5px;
float:left;
text-align:center;
position: relative;
line-height: 156px;
-moz-box-shadow:4px 4px 4px
#ccc;n-webkit-box-shadow:4px 4px 4px #ccc; box-shadow: 4px 4px 4px #ccc; } img {
border:none;
-moz-box-shadow:0px 8px 10px #ccc;
-webkit-box-shadow:0px 8px 10px #ccc; box-shadow: 0px 8px 10px #ccc; }
a{
color:#0066FF; text-decoration:none;
} a:hover{
color:#0099FF; }
--></style><pre>
<div id="gallery_box" >
<div id="thumbnail">
<a href="" ></a>
</div>
</div>

Resources