Remove gaps between DIVs - html

This website is designed for tablets, and the problem is, when the window is resized, there is a margin, or some kind of gap between the three divs and their background images (they are stacked vertically). The image is a chalkboard in three pieces. The middle div needs to be able to expand with text input while the top is static and bottom piece gets pushed down as the middle expands.
Link to site:
url no longer available
CSS for the Divs so far
.blackboard1 {
background:url(../img/chalkboardtop.png);
height: 28px;
background-size:100% auto;
background-repeat:no-repeat;
z-index:9999999;
}
.blackboard2 {
background-size:100% auto;
background:url(../img/chalkboardmiddle.png);
background-size:100% auto;
background-repeat:repeat-y;
z-index:-9999999;
padding-top:28px;
padding-bottom:35px;
overflow:visible;
}
.blackboard2 p{
color:#fff;
background-color:none;}
.blackboard3 {
background-size:100% auto;
background:url(../img/chalkboardbottom.png);
height: 28px;
background-size:100% auto;
background-repeat:no-repeat;
z-index:9999999;
}
#blackboardWrap {
background:url(../img/chalkboardmiddle.png); */
background-size:100% auto;
background-repeat:repeat-y;
}
One solution I used which i don't think is optimal, is to have the image that serves as the middle image, also serve as a fourth background that wraps around all three divs and sits behind them. This way when there are "cracks" between the divs, you can't notice as much. Using this solution it seems like it will add to loading time and also doesn't quite look right.

Gaps are because of margins:
p {
margin: 0 0 10px;
}
please remove those margins and see if gaps are still there or not.

Related

CSS basic template issues

in my website there is 3 vital parts
Top Bar (must remain in the top, not fixed, 40px height, 100% width)
Timeline this is always floating left to the main area, the timeline is not re sizable, it is neutral in size
main area re sizes with the window it is Horizontally scrolled so it can be small width as long as you can still keep scrolling right/left
here is my progress so far......
JSFiddle
My issues:
the top bar child elements are not aligned. like those simple inputs/text is at the bottom of the topbar and part of it is hidden, this doesnt happen with the image removed?? i need the top bar to always keep elements inline vertically centered and never resize in height
i cant get timeline and main area to take up the remaining height, i have them at 800px because nothing was working.
width: 100%;
height: 100% !important;
margin: 0px;
I added a padding and checked your fiddle it looks much better. Is it this what you are after?
.top_bar
{
z-index:100;
width:100%;
height:40px;
max-height:40px !important;
background-color:#ffff00;
color:black;
padding:40px;
overflow: auto;
}
For your top bar just float your image:
.wtblogo {
float:left; /* Add this to your current CSS */
}
and add a line height equal to your top bars height to vertically align objects with in it:
.top_bar {
line-height: 40px; /* Add this to your current CSS */
}
I am not sure what you mean for your second issue.
For #1 you can easily fix it by adding:
vertical-align: middle;
to your image class.
So you'll have:
.wtblogo {
height: 40px;
vertical-align: middle;
}
For #2, I'm not sure what you're trying to do. Could you clarify?

Fix left and right floating images in HTML

Here's what I'd like to do: have a banner across the top of a website which stretches all across. On the left is a menu, and on the right a logo image; the menu floats left, the image floats right.
The problem is the resizing of the browser window. Because the image floats right, it correctly moves as the window gets smaller. However, at some point it begins to float into the menu. Here is a Fiddle that illustrates this effect with two floating images. Resize the browser window to see how the two images overlap.
Setting
body {
min-width: 800px;
}
I can now make sure that the scrollbar appears as the browser window reaches a certain minimum width. However, that doesn't hinder the right-floating image to keep moving as the browser window keeps getting smaller. I tried to change position: relative but that didn't work. I tried to use Javascript to fixate the images once the browser window reaches its min-width but that didn't seem to have an impact either. Using min-width on the DIV and making the images children of the DIV didn't work either.
My question is: how can I make sure that, starting at a certain window size, the right-floating image stays put instead of floating into the left-floating menu?
EDIT: Oh dear, I forgot to mention a rather important detail: the menu bar at the top needs to be sticky. That is why I used the position: fixed property for the DIV. The other page content is supposed to scroll under that menu and out of the window, see the modified fiddle here which is based on ntgCleaner's answer. This kind-of changes the whole thing, doesn't it! Sorry about that...
Thanks!
A couple things I changed:
I made your banner DIV a container instead of just a free floating div. Probably not necessary.
I gave that banner div a min-width:280px and made it overflow:hidden;
I made the images just float left and right, not positioned relatively or absolute (since it's in the div container now).
#banner {
left: 0px;
top: 0px;
width: 100%;
height: 60px;
background-color: lightblue;
z-index: 1;
opacity: 0.8;
overflow:hidden;
min-width:280px;
}
#left {
float:left;
margin:5px;
height:40px;
}
#right {
float:right;
margin:5px;
height:40px;
}
​
​
Here's the fiddle
EDITED FOR THE EDITED QUESTION:
You will just need to place all of your content under your header into a div, then give that div a top margin of the height of your fixed div. In this caes, it's 60px.
Add this to your HTML
<div id="content">
this <br>
is <br>
some <br>
test <br>
text <br>
</div>
then add this to your CSS
#content {
margin:60px 0px 0px 0px;
}​
Here's the new fiddle
Is this what you are after? http://jsfiddle.net/9wNEx/10/
You are not using the position: fixed correctly. Fixed means 'positioned relative to the viewport or browser window', and that is exactly what you are experiencing.
I removed the position: fixed from the images, and placed them inside the div. This should keep them always on top of the page, as they are inside the div that is still positioned fixed.
Also I tweaked some of the other styling to replicate your example. Note that i removed the fixed height of the head and replaced it by a padding bottom. This way the height will follow the content whenever the screen size becomes to small and the images are forced underneath each other.
The css looks like this now:
#banner {
left: 0px;
top: 0px;
width: 100%;
padding-bottom: 15px;
background-color: lightblue;
z-index: 1;
position: fixed;
opacity: 0.8;
}
#left {
float: left;
margin-left: 10px;
margin-top: 5px;
height: 40px;
}
#right {
float: right;
margin-right: 10px;
margin-top: 5px;
height: 40px;
}
I changed your HTML to put the <img> tags inside the banner, and added the min-width to the #banner since it has position: fixed. You'll still need to add min-width to the body or a container that wraps all other elements if you want there to be a min-width of the entire page.
http://jsfiddle.net/Wexcode/s8bQL/
<div id="banner">
<img id="left" src="http://www.google.com/images/srpr/logo3w.png" />
<img id="right" src="http://www.google.com/images/srpr/logo3w.png" />
</div>
#banner {
width: 100%;
min-width: 800px;
height: 60px;
background-color: lightblue;
z-index: 1;
position: fixed;
opacity: 0.8; }
#left {
float: left;
margin: 5px 0 0 10px;
height: 40px; }
#right {
float: right;
margin: 5px 10px 0 0;
height: 40px; }
​
When I look at your Fiddle I think your problem isn't the floats at all. position:fixed supersedes float. Those two elements aren't floating at all, they're in a fixed position (similar to an absolute position), which is why they overlap when they don't have enough room.
Take out float:left and float:right, the result will be the same. Also, top, left, bottom, and right don't work on non-positioned elements. So they are superfluous on your banner.
If you use floats, however, when there is not enough room the right image will wrap underneath the left. See http://codepen.io/morewry/pen/rjCGd. Assuming the heights on the images were set for jsfiddle testing only, all you need is:
.banner {
padding: 5px; /* don't repeat padding unnecessarily */
min-width: ??; /* to keep floats from wrapping, set one */
overflow: hidden; /* clearfix */
}
.right { float: right; } /* only need one float, don't over-complicate it with two */

How do I get a div to expand with its contents?

I have a div with these properties
#content {
background-image: url('img/cbg.png');
background-position: center top;
background-repeat: repeat-y;
width: 960px;
margin: auto;
padding-bottom:50px;
margin-bottom: 20px;
}
The background only shows up for 70px (I think) and then stops, then the rest of the stuff inside the div just goes on down the page like normal. If I set display:inline-block, it works correctly but uncenters my div.
If you have elements in the container which are floating, it's possible that the floats aren't properly being cleared. If this is your problem there are a bunch of work-arounds - they're called "clearfixs".
One of my favorite write-ups was here. The css they used in this example was here.
div.container {
border: 1px solid #000000;
overflow: hidden;
width: 100%;
}
div.left {
width: 45%;
float: left;
}
div.right {
width: 45%;
float: right;
}
Well, you're doing repeat-y which means it'll only repeat vertically. If the background image is 70px, that would support the issue. Either use repeat-x or just repeat.
It wouldn't expand any longer because you have set your #content width to 960px in your browser window.
In the case of your image expanding only up to 70px, it is probably because that's the actual height of the image you've used. but mistakenly used repeat-y (repeat vertically).
Here's a simple concept in background-repeat:
If you want to repeat the image vertically, create an image that is horizontally wide.
If you want to repeat the image horizontally, create an image that is vertically tall.

Image floating out of screen

I need to align a image to the center of the browser window, therefore i created the following css:
#charset "utf-8";
/* CSS Document */
html {
background-color:#CCCCCC;
}
body {
margin:0px 0px 0px 0px;
}
img {
position:absolute;
border:0px;
left:50%;
top:50%;
margin-left:-156px;
margin-top:-217px;
}
The problem is however that if you make the browser window very small, the image floats out to the top and the left. Instead it should be fixed in the top left corner, and then give the possibility to scroll to see the rest of the image.
View the problem here: ejlstrup.com
Try the following css:
img {
border: 0px;
margin: auto auto;
}
The problem will be with your negative margins, they are what is causing the image to be pushed to the left out of view. If you use margin: auto auto, it should center the image for you and you won't have to use absolute positioning with percentages.
Edit: Just tested my method and it didn't work as intended. What you can do then (if you don't mind using a div), is to wrap the image in a div. Make the div the size of the image, then the margin: auto auto; will work properly.
Edit2: Credits to Senthil for pointing out that if you set the image display property to block, you don't have to wrap the image in a div for it to center. However, auto isn't working for centering the div vertically, if it needs to be center you can use a percentage (although I'm not sure if this can cause problems with different resolutions).
img {
border: 0px;
margin: auto;
display: block;
}

how to show section of a CSS sprite within a set position on the whole html body

I use sprite sheets for my css, adn they work great, however i want to have a section of my sprite sheet on the footer
it is like a curved block and the left hand content boxes will come over the top of this a little.
however i cant seem to get a section of a sprite as a background positioned at the bottom.
now normally you would do something like this
background:url(sprite.png) -20px -144px no-repeat; display:block; width:800px; height:225px;
but when i try something like this
background-color: #ffffff;
font-size: .75em;
font-family: Verdana, Helvetica, Sans-Serif;
margin: 0;
padding: 0;
color: #000000;
height:100%;
width:800px;
background-image:url(images/sprite.jpg);
background-position:0 0 no-repeat bottom left;
i get the full sprite sheet as the background..... so my question is is it possible to only get a section of a sprite
and use that section as the bottom section of a div !!!!
bit of a mouthful, but i dont want to just bin this idea, if it can be done, someone has done it already.
Put it in a nested fixed size div within the footer section. If you want the footer div to grow, but don't want the size of the sprite to exceed its limits, that's pretty much the only way.
hiya thanks, could not get it going on the body so i added a container div:
min-height: 100%; height: auto !important; height: 100%; margin: 0 auto -4em; background:url(images/sprite.jpg) no-repeat; clip:rect(0,800px,270px,0); position:absolute;
however it restricts the div size to the size of the clipping being done, where as my plan is to always have this down at the bottom of all my content
please forgive it being on one line, the box wont let me add all the code in one block !!!!
So you're trying to show a section of an image inside a container that's larger than the section you want to show?
If so, check out the clip property. Here's an example of it:
#myDiv {
width:400px; height:300px;
background:url(sprite.png);
clip:rect(100px,250px,150px,100px);
position:absolute;
}
http://www.julienlecomte.net/blog/2007/07/4/