I have the following problem.
I am using a twitter bootstrap to make my new website but I have difficulties with the background. The following is what I have :
<body>
<div class="wrapper">
<div class="navbar navbar-inverse navbar-fixed-top">
...
</div>
<div id="header">
...
</div>
<div id="content">
...
</div>
<div class="push>
</div>
</div>
<div class="footer">
....
</div>
</body>
The navbar is fixed at top. (fixed height)
The header (title stuff) is scrolling with the page and is fixed height.
the footer is at the bottom of the page but scrolls if there is more content (not fixed at bottom but fixed height)
What I want is that the content has a background that takes all the avaiable space (from right after the header till the footer)
Image to clarify
Full HTML & CSS(without bootstrap css) code
So you want the content area to be at least 100% less header and footer so to speak?
This is how i would do it:
demo:
http://jsbin.com/ofijap/1/edit
.head {
height:100px;
background-color:green;
}
.wrap {
min-height:100%;
background-color:red;
}
.footer {
height:100px;
background-color:grey;
margin-top:-100px;
}
.content {
padding-bottom:100px;
}
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
<div class="wrap">
<div class="head">Head</div>
<div class="content">content</div>
</div>
<div class="footer">footer</div>
</body>
</html>
EDIT:
as a rule of thumb, if you want something to fill up all the vertical space it probably needs min-height:100%; But, its parent should have 100% height too, and so on up to the body element.
To the people who want to see my final result: thanks to #user1721135 ;)
http://jsbin.com/udoxet/2/edit
Now I'm gonna try and port it to my own website see if that works :)
Related
I need a way to put 3 divs side by side. The Left side one will have text, the middle one will have image and the right side will have text. I also want it responsive to it could be mobile friendly. Is there a way to do that? Whenever I try using flexbox or css-grid, it keeps becoming 2 divs or I can't put any images. I also got a flexbox is not defined error message. Can you help me?
Here is the code I tried
<!DOCTYPE html>
<html>
<head>
<!-- CSS property to place div
side by side -->
<style>
#leftbox {
float:left;
background:Red;
width:25%;
height:280px;
}
#middlebox{
float:left;
background:Green;
width:50%;
height:280px;
}
#rightbox{
float:right;
background:blue;
width:25%;
height:280px;
}
h1{
color:green;
text-align:center;
}
</style>
</head>
<body>
<div id = "boxes">
<div id = "leftbox">
Text
</div>
<div id = "middlebox">
I can't put an image here.
</div>
<div id = "rightbox">
Box 3
</div>
</div>
</body>
</html>
You have to define col-count that one div will take (see code below).
<div class="container-fluid">
<div class="row">
<div class="col-4">first</div>
<div class="col-4">second</div>
<div class="col-4">third</div>
</div>
</div>
Try this :
<div class="container-fluid">
<div class="col">This div takes up 1/3 of the available width on a desktop</div>
<div class="col">This div takes up 1/3 of the available width on a desktop</div>
<div class="col">This div takes up 1/3 of the available width on a desktop</div>
</div>
I would like to re-create this revealing sticky-footer effect found at http://www.akc.org/dog-breeds/
I know the footer has to be fixed.
I know the content needs to have a higher z-index
I'm guessing (sort of) that the body needs to have a margin-bottom which is equal to the height of the footer???
Please would someone help me out.
I'm using Twitter Bootstrap 4. The general markup looks like this:
<body>
<div class="container"> <!-- This part should scroll up to reveal the footer below -->
<!-- Content goes in here -->
</div>
<footer class="footer"> <!-- This should be hidden initially -->
<div class="container">
<div class="row">
<!-- Footer stuff goes in here -->
</div>
</div>
</footer>
</body>
You will want to add a main content div and then give this div a background color of whatever you want your page to be otherwise you will just end up having text overlapping but yes you are right you will want to give your main content div a z-index of 1 or something and then fix your footer behind that and give it a z-index smaller than that in my example I gave it a z-index of -1. Then your main content div will scroll over the top of your footer. You will probably want to give your footer a height and your body a padding-bottom of the same height.
Here is an example of how I did it Fiddle Demo:
Html:
<div class="main-content">
<div class="container">
<div class="row">
Your main Content Scroll down
</div>
</div>
</div>
<footer>
<div Class="container">
<div CLass="row">
Footer Content
</div>
</div>
</footer>
Css:
body{
padding-bottom:200px;
}
.main-content{
min-height:200vh;
background:#fff;
z-index:1;
}
footer{
position:fixed;
bottom:0;
left:0;
width:100%;
height:200px;
background:#000;
color:#fff;
z-index:-1;
}
Sorry, I couldn't post images without a higher reputation, so I linked them below:
PSD:
HTML:
Okay, the PSD screenshot is of what I want the alignment to do.
And the HTML screenshot is it's current form.
As you can tell, the sidebar is currently below the orange bar (nav) and the grey bar (banner). I know there is a way to make its position absolute and overlay it on top, but seeing that this is built on a responsive grid, I think that would ruin it.
Does anyone know of anyway to overlap the sidebar like it is shown in the psd without ruining the responsiveness?
I'm open to any and all suggestions.
Thanks!
Code:
<div class="container">
<div class="row">
<header> content </header>
</div>
</div>
<nav> content </nav>
<div class="container">
<div class="row">
<div class="col-sm-9">
<section>
<!-- Services Section Content -->
</section>
<services>
<!-- Clients Section Content -->
</section>
<section>
</div>
<div class="col-sm-3">
<!-- Sidebar -->
</div>
Using position:absolute would not ruin your responsive layout if you edit your media queries to compensate.
Alternately, try a negative margin on the sidebar element and set the z-index to be higher than the top bar element. Example:
header {
width:100%;
height:100px;
background:#ccc;
z-index:100;
}
.col-sm-9 {
width:200px;
height:500px;
margin:-50px 0 0 0;
background:#000;
z-index:200;
}
Have a fiddle: http://jsfiddle.net/68ANR/
It will perfectly works.Try it because position:absolute give the position to the main div or the parent div.
.col-sm-9 {
position:absolute;
left:/*give here from left*/px;
top:/*give here from top*/px;
width:200px;
height:500px;
background:#000;
z-index:200;
}
Hope the answer !
I'm using bootstrap to do a simple version of something like this: http://techlist.in/
Basically, I want to have a map and a right side bar with a fixed size and fixed position.
I've started with something like:
HTML:
...
<div class="container">
<div class="span10">
<div id="map_canvas">
</div>
</div>
<div class="span2" style="position:fixed; right:0">
Some stuff
</div>
</div>
...
CSS:
#map_canvas {
display:block;
position:absolute;
height:auto;
bottom:0;
top:0;
left:0;
right:0;
margin-top:40px; /* used for the top navigation bar */
}
But this is not working as expected, as the map remains 100% width and the "some stuff" label appears on top of the map. Any hints?
UPDATE
In fact, I already have the nav-bar, but I did not detailed it in the code, my bad. So basically the whole structure of the html page is (with the missing row div added):
<body>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
...
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="span10">
<div id="map_canvas">
</div>
</div>
<div class="span2" style="position:fixed; right:0">
Some stuff
</div>
</div>
</div>
<!-- include javascript stuff -->
...
</body>
The css file is:
#map_canvas {
display:block;
position:absolute;
height:auto;
bottom:0;
top:0;
height: 90%
width: 80%;
left:0;
right:0;
margin-top:40px;
margin-right:200px;/* used for the top navigation bar */
background: #ccc;
}
If a leave 200px of right margin for the map, how can I fill the margin with the sidebar ?
Basically, I need a side bar of 200px width and the map adapting accordingly on screen resizing.
UPDATE 3
I'm wondering if I really need to use container / row to achieve this layout in fact (I still do not manage to have this working as expected). As I only need to have a map and a sidebar (that should always remain on the right of the map even if the window is resized), would it make some sense to use basic div / css and not bootstrap classes ?
This is basically what I needed: http://jsfiddle.net/kuXYq/4/
have a look at this fiddle I made it might help.
http://jsfiddle.net/eKQGD/
I used percentages to keep things the same
#map_canvas {
display:block;
position:absolute;
height:auto;
bottom:0;
top:0;
height: 90%
width: 80%;
left:0;
right:0;
margin-top:40px;
margin-right:150px;/* used for the top navigation bar */
background: #ccc;
}
There are a few parts to the answer to this question.
The first thing to point out is that it's a little hazy as to why there is the requirement of a "fixed size and position", and by that I mean that the terminology being used may be throwing off your thinking a bit. Typically, you only need to use the "fixed" css position property if you plan on the page having scroll bars and you want the element to stay in the same position on the page no matter what. In this case, it doesn't seem like you want page scrolling at all since the map will appear to be the same size as the entire page. It seems like what you really want on the sidebar is for it to be a fixed height (aka the height of the browser window) with overflow set to scroll.
Secondly, it appears that you're missing a <div class="row"></div> tag around your elements - a tag with a "row" class is necessary to make the bootstrap "span" classes work.
Lastly, here is something that I would go with if I was trying to duplicate the link you posted, using a bit of JS love as well: http://jsfiddle.net/kzBkA/5/ (background colors added just to show what it looks like )
HTML:
<div class="container">
<div class="row">
<div class="span10">
<div id="nav_bar">
Nav bar goes here
</div>
<div id="map_canvas">
test
</div>
</div>
<div class="span2">
<div id="sidebar">
Some stuff
</div>
</div>
</div>
</div>
css:
#nav_bar {
height:40px;
background-color:blue;
}
#map_canvas {
background-color:green;
}
#sidebar{
background-color:red;
overflow-y:auto;
}
js:
$(function(){
$("#map_canvas").height($(window).height() - 40);
$("#sidebar").height($(window).height());
});
UPDATE:
So - again, first off, I encourage you to reconsider your use of fixed elements. You seem to be trying to build a page that won't scroll, but then using a "positioning" feature that's specifically for scrolling (position:fixed), which basically tells all your nice bootstrap code to be ignored and just put it where you tell it. A much nicer way to do this would be to use Bootstrap to your advantage. I changed the row class to row-fluid, I moved your nav bar into the span10 with the map (since that's how wide you actually want the nav, or at least that's how it was in the example), I removed the "navbar-fixed-top" class since you don't actually need things to be fixed, and removed the fixed positioning from the sidebar (since again that's basically making it ignore what you're trying to do). Check out the updated jsfiddle: http://jsfiddle.net/kzBkA/7/ - you may have to tinker with the JS to get the map_canvas div set with the correct height, but otherwise this should take care of making your page fluid when the browser is resized without having to add a ton of unnecessary CSS rules. In general, if you use a scaffolding framework, you should use it to your advantage to avoid creating cluttered, messy css with lots of "width:80%; height:20%; margin: ..." - the whole point of using the framework and scaffolding was to avoid that kind of code :)
HTML:
<div class="container">
<div class="row-fluid">
<div class="span10">
<div class="navbar navbar-inverse">
<div class="navbar-inner">
navbar
</div>
</div>
<div id="map_canvas">
map goes here
</div>
</div>
<div class="span2" id="sidebar">
Some stuff
</div>
</div>
</div>
CSS:
.container{
max-width:100%;
}
#map_canvas {
background-color:green;
}
#sidebar{
background-color:red;
overflow-y:auto;
}
JS:
$(function(){
$("#map_canvas").height($(window).height() - 40);
$("#sidebar").height($(window).height());
});
UPDATE 2
Just realized I missed the part about the sidebar always being 200px but the map width being fluid. I've updated the fiddle to reflect that as well as updating so that sizes get reset when window is resized - http://jsfiddle.net/kzBkA/9/
HTML:
<div class="container">
<div class="row-fluid">
<div class="span10 left-col">
<div class="navbar navbar-inverse">
<div class="navbar-inner">
navbar
</div>
</div>
<div id="map_canvas">
map goes here
</div>
</div>
<div class="span2 right-col" id="sidebar">
Some stuff
</div>
</div>
</div>
CSS:
.container{
max-width:100%;
}
#map_canvas {
background-color:green;
}
#sidebar{
background-color:red;
overflow-y:auto;
}
.right-col{
width:200px;
}
JS:
$(function(){
resizeElements();
window.onresize = function(event) {
resizeElements();
}
});
function resizeElements(){
//set height
$("#map_canvas").height($(document).height() - $(".navbar").outerHeight() - 20 /*not sure where this is coming from, possibly the scrollbar?*/);
$("#sidebar").height($(document).height());
//set width of left col
$(".left-col").width($(document).width() - $(".right-col").outerWidth() - 20 /*not sure where this is coming from, possibly the scrollbar?*/)
}
I have a div (with a fixed width) that has 2 image elements as children.
Each image is the same width as the div so the images are placed not on the same row (see screenshot) .
This is great, but I want the images to displayed the same way (one on top of the other) but at the bottom of the div.
I'm able to achieve such behavior in some browsers using:
-webkit-transform: rotate(180deg); -moz-transform: rotate(180deg);
on the div css.
Is there a nicer way to achieve that?
Here is the code I used for the example:
<html>
<head>
<style type="text/css">
.container {background:url(http://img01.imagefra.me/img/img01/1/11/10/f_dwr8biwm_3ed594d.png) no-repeat;height:116px;
width:33px}
</style>
</head>
<body>
<div class="container">
<img src="http://img01.imagefra.me/img/img01/1/11/10/f_ei8p1qf6om_0e5c35c.png" width="33px">
<img src="http://img01.imagefra.me/img/img01/1/11/10/f_ei8p1qf6om_0e5c35c.png" width="33px">
</div>
</body>
</html>
Make the container position:relative; and set the images to position:absolute; bottom:0;
However, this will not stack the images. They will overlay each other. If you need them stacked, the easiest (dynamic) way is to wrap the images with another container (like a div), and then set the styles on it. For example...
Markup:
<div class="container">
<div class="innerContainer">
<img src="http://img01.imagefra.me/img/img01/1/11/10/f_ei8p1qf6om_0e5c35c.png" width="33px" />
<img src="http://img01.imagefra.me/img/img01/1/11/10/f_ei8p1qf6om_0e5c35c.png" width="33px" />
</div>
</div>
CSS:
.container {
background:url(http://img01.imagefra.me/img/img01/1/11/10/f_dwr8biwm_3ed594d.png) no-repeat;
height:116px;
width:33px;
position:relative;
}
.container .innerContainer {
position:absolute;
bottom:0;
}
The solution: Add an innner div and set its position to bottom:
<html>
<head>
<style type="text/css">
.container {background:url(http://img01.imagefra.me/img/img01/1/11/10/f_dwr8biwm_3ed594d.png) no-repeat;height:116px;position:relative;
width:33px;}
.inner {position:absolute;bottom:0px;}
</style>
</head>
<body>
<div class="container"><div class="inner">
<img src="http://img01.imagefra.me/img/img01/1/11/10/f_ei8p1qf6om_0e5c35c.png" width="33px">
<img src="http://img01.imagefra.me/img/img01/1/11/10/f_ei8p1qf6om_0e5c35c.png" width="33px">
</div></div>
</body>
Thanks to Josh for suggesting this.