How to fit a leaflet map under a bootsrap nav header? - css

I'm using bootstrap in combination with a leaflet map. Now to give the map full height of the window I used $("#map").height($(window).height()); But I have a nav header at the top of the page. This is the html of the bootstrap nav bar:
<nav class="navbar navbar-light bg-faded">
<a class="navbar-brand" href="#"><img id="logo" src="images/logo.png"></a>
</nav>
This is my map div:
<div class="col-md-9 col-sm-8 col-xs-8" id="map"></div>
Now when I load the page I get a scrollbar at the side because the map takes the full window height + the height of the nav bar. Is there a way to solve this? Can I add something to the css of the nav bar so the map will be behind it?
UPDATE:
After I implemented you'r suggestion #IvanSanchez, the map got real thin like this:
UPDATE
When I add the css with pixels like this it works and the thin map changes into a 600px height:
#map {
display : table-cell;
height : 800px;
/*height: calc ( 100vh - 5em );*/
}
But I want it to be responsive so I need it in % or like #IvanSanchez suggested it.

Now to give the map full height of the window I used $("#map").height($(window).height());
Don't.
If you want to fit stuff to the viewport size, use the vh, vw, vmin and vmax CSS units.
If you cannot use absolutely positioned block elements to control the size of the map container, then use calc like #map { height: calc ( 100vh - 5em ); }

Related

How to position an element at the bottom of the screen on load but not make it fixed?

I am trying to position a chevron down arrow at the bottom of my page that would allow the user to smooth scroll to the next section on click. I would like the position to always be close to the bottom no matter what device or size of the screen and I do not want it to stay in place. It should scroll along with the rest of the site. When the user clicks it it will scroll to the next section and there will be a new chevron down arrow also at the bottom of the screen linking to the next section.
HTML
<div class="row chevron-down">
<div class="col-md-12">
<img class="img-responsive visible-xs center-block" src="img/chevron-down.png" alt="Transformative Thinking" />
</div>
</div>
CSS
.chevron-down {
/* magic code here */
}
There are probably a few ways to go about it, but absolute positioning combined with a couple of CSS3 features was my first thought. Use top:100vh to send the chevron to the bottom of the screen, then translateY(-100%) to bring it just above the bottom (so it isn't below the viewport at the start):
.chevron-down {
position:absolute;
top:100vh;
transform:translateY(-100%);
width:100%;
}
Here's a Bootply to demonstrate. Hope this helps! Let me know if you have any questions.
you can use vh dimension ( viewport height ) in your css ,
you should give your div a height by vh , for example:
div { height : 10vh }
it means your div has a height as long as 10 percent of every viewport that is showed on . after that get it a relative position and 90vh top
div {
height : 10vh;
position : relative;
top : 90vh;
}
not that => height + top = 100
hope to be useful

PureCSS.io menu & Leaflet page height

I'm trying to create a fullscreen map with leaflet and a purecss horizontal menu on top of it.
Here is a solution for making the map height 100% (set parent elements also to 100% height).
So right now, I've got something like this:
<!-- Menu -->
<div class="pure-menu pure-menu-horizontal">
map
<ul class="pure-menu-list">
<li class="pure-menu-item">About</li>
<li class="pure-menu-item">Contact</li>
</ul>
</div>
<!-- Map -->
<div id="map"></div>
CSS
body {
padding: 0;
margin: 0;
}
html, body, #map {
height: 100%;
width: 100%;
}
The problem is: the page height ist 100% + the height of the menu. So parts of the map get cut off at the bottom.
I used Firefox' Inspector and changed various CSS settings to no avail. I also tested different browsers to exclude a problem with Firefox. What am I missing? Unfortunately I'm not a CSS guy..
I created a JSFiddle: http://jsfiddle.net/jygzLf3v/13/
The result window is scrollable for the height of the menu but should be "fullscreen" including the menu.
Thanks for some insight.
Sounds like you could use #map {height:calc(100% - $HEIGHT_OF_MENU);} on your map container to size things up properly, and not have any cutoff.Don't forget to add 'px' after your menu height.
You cand simply add overflow: hidden to your body element, in the stylesheet.
http://jsfiddle.net/jygzLf3v/14/

CSS: Making an element fill the browser width while keeping other elements centered with a defined width

I'm trying to create the following layout in CSS:
It is a typical web layout where all the content is in a wrapper DIV that has a defined width and is centered on the page.
However, the purple background is a CSS gradient and needs to fill the entire width of the browser (and not just the width of the content wrapper). Furthermore, different pages will have different lines of headline/intro text (e.g. some pages might have 3 lines, others just 1) and so the purple background needs to match the height of this content.
I am also using a CMS which places all the content in a wrapper that has a width and is centered with margin:auto.
How can I achieve the layout?
At first I though I could use position:absolute on the headline/intro div. This works great. Except the rest of the content gets hidden behind the headline/intro div.
See an example here: http://jsfiddle.net/5BkX6/1/
I then tried using position:relative on the headline/intro div and then using negative left values together with padding to stretch the background of the DIV while keeping the content centered.
See an example here: http://jsfiddle.net/4DZYr/1/
This method works great, except it creates a horizontal scroll bar. I know I can apply overflow-x:hidden to the main wrapper DIV to hide the scroll bar, but I would prefer not to have it in the first place.
How can I achieve my goal. I do not want to use jquery to get the height of the headline/intro DIV.
This should give you the layout you want ^^
Here is the Html
<body>
<div class="header">
<div class="contentheader">This is the header</div>
</div>
<div class="container">
<div class="content">
<div class="left"></div>
<div class="right"></div>
</div>
</div>
</body>
And here is the style
.header{
width : 100%;
background : #0033aa;
height : 100px;
}
.contentheader{
width : 1000px;
margin : 0 auto;
}
.container{width : 100%;
}
.content{
width : 1000px;
margin : 0 auto;
}
.left {
width : 300px;
display : inline-block;
height : 200px;
background : #3300aa;}
.right{
width : 700px;
display : inline-block;
height : 200px;
background : #aa0033;}

Set a minimum width for the sidebar-nav in Twitter Bootstrap

I have a sidebar-nav as shown in the typical Twitter Bootstrap example.
Some of my sidebar menu items are long. Depending on the size of the window, the text wraps to the next line as shown in this jsfiddle as you change the width of the window. For presentation's sake, I'd like to set a minimum width for the sidebar-nav. I know there are media tags in Bootstrap's CSS, but I'm not sure that that's what I need to be doing. Basically, I want the content section to still be responsive, but have the sidebar menu to have a minimum width (or actually a locked width might be even better).
Is there a way to fix the width of the sidebarnav but make sure it still plays nicely with the content section of the page?
Get the nav out of the fluid-container, set its position to absolute and add a margin-left to the container. It's not Twitter Bootstrap's native positioning method, but it should work.
Markup:
<div class="navbar navbar-fixed-top">...</div>
<div class="the-sidebar">...</div>
<div class="container-fluid the-container>...</div>
CSS:
.the-sidebar {
position: absolute;
width: 220px;
}
.the-container {
margin-left: 240px;
}
This is the script on jsfiddle (i've used latest version of Twitter Bootstrap)
TIP:
If you want an always-visible sidebar, just change positioning to fixed

Side fill when width is higher then 1280px

I want to make a website that fills the pagewidth to 100% for all widths (available space) lower or equal to 1280px and for all widths greater than 1280 two filling side bars should appear (like this: |fill|website|fill|).
(How) can i do this without scripts? (by using css settings?)
You could use something like this:
#content {
max-width: 1280px;
width: 100%;
margin: 0 auto;
}
That refers to the style applied to a div that has all the page's contents.
Your "sidebars" would be whatever the background body is.
Do you want content in the "fill" bits, or just a border type thing? If just a border, you can use a background image/colour to make the fill effect, and use max-width on the main content bit. Be aware that it won't work in IE6, if that's important to you.
<div style="max-width: (bar width * 2) + 1280">
<div style="max-width: 1280px">
<!-- content -->
</div>
</div>

Resources