Im using bootstrap grid but Im with some doubts.
I want to have a header where i have a logo at left some links at right. And below this header I want to have a menu that occupies the same with of the content above.
I have this in this example: https://jsfiddle.net/v529b4mz/1/, and it is working. But there are 2 issues:
For example if the size of the screen is 1920px I have some white margins around content and if the screen is resized the space around decreases and there is some point that the media querie changes and when the media querie change there are again more white space around, but i Would like to not have too much space. So, I would like to have less space around when the media queries change so the content can occupy more space.
Do you know how to do this?
For example if I want to have this menu with background-color green in this example: https://jsfiddle.net/v529b4mz/1/ in all media queries except for the extra small media query where I want to hide this menu and show a mobile one. How to do that in a way that its not necessary decrease too much the font size or the padding of the list items, or both but instead utilize the white space around so the list items appear legible up to the small media query?
And, there are some margins between the list elements, do you know why?
Note: The header and section elements are just to give a full width background color to the bootstrap containers.
HTML:
<header style=background:yellow;>
<div class="container">
<div class="row">
<div class="col-2" style="background-color: orange">
Logo
</div>
<div class="col-10 d-flex justify-content-end" style="background-color: pink; ">
Links
</div>
</div>
</div>
</header>
<section style="background:pink;">
<div class="container">
<div class="row" style="background-color: green">
<div class="col-12">
<ul>
<li>Item1</li>
<li>Item2</li>
<li>Item3</li>
<li>Item4</li>
<li>Item5</li>
<li>Item6</li>
<li>Item7</li>
</ul>
</div>
</div>
</div>
</section>
CSS:
*{
box-sizing:border-box;
}
ul{
display: flex;
align-items: center;
list-style:none;
justify-content:space-between;
}
ul li{
padding:20px;
border:1px solid gray;
}
You're using .container which creates a fixed width grid between 2 given breakpoints.
You can replace it by .container-fluid which is... well fluid :)
Note that you'll have to set manually some padding on the section parent: can be a fixed padding in rem, em or px or proportional to the width of the viewport with vw unit (100vw = the width of the viewport) or a mix of them depending of the resolution.
Relevant documentation (Bootstrap 4.0 as seen in your fiddle)
Containers provide a means to center your site’s contents. Use .container for fixed width or .container-fluid for full width.
Updated Fiddle
<section style="background:pink;">
<div class="container-fuild">
<div class="row" style="background-color: green">
<div class="col-12">
<ul>
<li>Item1</li>
<li>Item2</li>
<li>Item3</li>
<li>Item4</li>
<li>Item5</li>
<li>Item6</li>
<li>Item7</li>
</ul>
</div>
</div>
</div>
</section>
Related
I am currently designing a website and need to know if I can use container tag inside a container-fluid tag? Is it a good design approach to use that.
You can do this if you want, though it is generally not necessary, as their primary purpose is to be an external wrapper. The main thing to be aware of is the 15px padding on either side of a Bootstrap container, as well as their varying max-width media queries.
When nested, a child .container will not fill the width of the screen at any point.
Bootstrap Containers overview.
Bootstrap.css Source Code. Open this, ctrl + f and search .container, .container-fluid, and the sm, md, lg, and xl container sizes to see how they are styled.
Open the following code snippet example in Full Page mode and re-size to see their effects within .container-fluid, without .container-fluid, and with several .container divs nested within eachother.
.container-fluid {
background:pink
}
.container, .container-sm, .container-md, .container-lg, .container-xl {
border: 1px solid black;
background: lightblue;
}
.not-a-bootstrap-container {
background: orange;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<div class="container-fluid">
<h2>
Within container-fluid
</h2>
<div class="container">
.container
</div>
<div class="container-sm">
.container-sm
</div>
<div class="container-md">
.container-md
</div>
<div class="container-lg">
.container-lg
</div>
<div class="container-xl">
.container-xl
</div>
</div>
<div class="not-a-bootstrap-container">
<h2>
Without container-fluid
</h2>
<div class="container">
.container
</div>
<div class="container-sm">
.container-sm
</div>
<div class="container-md">
.container-md
</div>
<div class="container-lg">
.container-lg
</div>
<div class="container-xl">
.container-xl
</div>
</div>
<div class="container-fluid">
<h2>
Multiple nested containers (within Container-Fluid)
</h2>
<div class="container">
<div class="container">
<div class="container">
Three .container divs nested within eachother in a .container-fluid
</div>
</div>
</div>
</div>
Yes, you can use the container tag inside of a container-fluid tag. It all depends on the needs. Let say you have a scenario where you want to make the navbar of full screen width and page content to be in a single centered container.
There is nothing like bad approach in this.
Basically, I need to put a back-to-top button at the right side of the footer.
Something like this:
What I get is this:
You can see that there is a blank space between footer and the end of viewport, that space is the height the back-to-top button, if I remove the button the blank space is removed too.
I'm using bootstrap so my html code is similar to:
<footer class="container-fluid">
<div class="container">
<div class="content1>CONTENT 1</div>
<div class="content2>CONTENT 2</div>
</div>
<div class="back-to-top>TOP</div>
</footer>
You can see an example in Bootply. You can see that the footer has to be 20px height (min-height: 20px) but instead it is 40px.
I think that my problem will be solved if I can put the .back-to-top div beside the .container div.
How can I get this?
You can use helper class pull-right and move TOP link before container:
<footer class="container-fluid">
<div class="back-to-top pull-right">TOP</div>
<div class="container">
<div class="content1>CONTENT 1</div>
<div class="content2>CONTENT 2</div>
</div>
</footer>
You need to remove your CSS bloc:
.back-to-top {
float: right;
position: relative;
top: -20px;
}
Doc: http://getbootstrap.com/css/#helper-classes-floats
Having a min-height proxy doesn't mean you footer is going to be 20px. That just mean its height won't be smaller than that. If you want your height to be 20px, use height property. If for some reason you want it to be variable, you can look to the max-height property.
For your "back-to-top" button, here is my suggestion :
http://jsfiddle.net/Bladepianist/38ne021p/
HTML
<footer class="container-fluid navbar-inverse">
<div class="row">
<div class="col-xs-6">CONTENT 1</div>
<div class="col-xs-5">CONTENT 2</div>
<div class="col-xs-1 text-right" id="back-to-top">TOP</div>
</div>
</footer>
CSS
.container-fluid {
color: white;
}
Basically, I change your "back-tot-top" class to an ID in my model but you're free to adapt it to your liking.
Using the col-system and the text-positions classes, you can achieve the same rendering as you show in your question. That way, the back-to-top button is part of the footer.
Hope that's helping ;).
Building a portfolio site with TB v3.0.0 and encountered a horizontal scrolling issue that I can't seem to figure out.
Trying to achieve a full bleed for the images on mobile devices so I striped the left/right padding, but horizontal scrolling occurs. Here's the css I added that's causing the problem:
#media (max-width: 767px) {
.container {
padding-right: 0;
padding-left: 0;
margin-right: auto;
margin-left: auto;
}
}
Here's the staging site I'm working off of: http://www.kesernio.com/playground/
I wonder if changing the padding helps to set the images 100% in the first place.
The code below will be 100% viewport (green). Also mention your content has a padding. This padding is set on your col-xs-12 (to remove it: set the padding of .col-xs-12 to zero )
In your case remove the padding of your col-- with images.
<div class="container" style="background-color:green;">
<div class="row">
<div class="col-xs-12 contact">
content
</div>
</div>
</div>
</div>
About your scrollbar, in fact you do this:
<div class="container" style="background-color:green;padding:0">
<div class="row">
<div class="col-xs-12 contact">
content
</div>
</div>
</div>
add padding:0 this will give you a horizotal scrollbar cause your .row classes have a negative margin of 15px on both sides.
To remove the scrollbar set the margin of the .row to zero to:
<div class="container" style="background-color:green;padding:0">
<div class="row" style="margin:0">
<div class="col-xs-12 contact">
content
</div>
</div>
</div>
See also: https://stackoverflow.com/a/19044326/1596547 about the construction of the gutter of the grids
I am using Twitter Bootstrap. And i have used span8 and span 4 in a row. Is there anyway to remove the leading margin-left:20px from the first span of the row without needing to over ride it manually ?
That 20px margin you see on your #mainContent area is due to the setup of the bootstrap grid, which uses a container of 940px, it is supposed to be removed by the .row container with a margin-left:-20px property. In your setup, your content area is working just the way it was designed too, but your top pageHeader and mainNav sections are not appropriately inserted into the grid, you just have divs inside the .row top sections that are not being contained within the proper containers of the grid.
To fix this you can just insert all of your pageHeader and mainNav elements inside a .span12 container and everything should stack accordingly.
Fixed markup
<header class="row" id="pageHeader">
<div class="span12">
<div id="logo">Logo</div>
<div id="userDetails">userDetails</div>
</div>
</header>
<nav id="mainNav" class="row">
<div class="span12">
<ul>
<li>Home</li>
<li>Dashboard</li>
<li>Blog</li>
<li>Idea Exchange</li>
</ul>
</div>
</nav>
Also, quick tip, you can switch your mainNav background color to the proper grid container of .span12 simply by targeting it like so:
nav#mainNav .span12 {
background: url("../images/nav_bar_bg.png") repeat-x scroll 0 0 transparent;
height: 45px;
overflow: hidden;
}
you can add a class in your css with an !important:
example:
.no_margin{
margin:0px !important;
}
and add that class to your html when required.
(sorry for my bad english xD)
there is also small less utility at
http://getkickstrap.com/extras/#single-view
called flushspan
By using "row" or "row-fluid" class as parent of your span class
<div class="row">
<div class="span3">
<ul>
<li>Home</li>
<li>Dashboard</li>
<li>Blog</li>
<li>Idea Exchange</li>
</ul>
</div>
</div>
Let's say I have a this markup:
<div id="container">
<div id="header">content</div>
<div id="left-column">content</div>
<div id="right-column">content</div>
<div id="footer">content</div>
</div>
The #container is centered and fixed at 1000px, #header and #footer are 1000px, and #content-left and #content-right are floated left, at 500px each.
How do I extend the header and footer background colors the full length of the browser window if the container is fixed?
First, change a little your html structure. While you're there, why not using html5 for header and footer elements.
Html
<header>
<div class="container">
content
</div>
</header>
<div class="container">
<div id="left-column">content</div>
<div id="right-column">content</div>
</div>
<footer>
<div class="container">
content
</div>
</footer>
Css
Than, in the Css, set the header and footer width to 100% and make them de color you want. In this example red. Than use a class .container that will make the content wherever you put it (header, main section, footer) display in the middle of the screen, but without any background color.
header, footer{display:block; width:100%; background:#ff000; margin:0; padding:0;}
.container{width:1000px; margin:0 auto;}
Hope this help :)
The header and footer divs need to be outside the container div.
Apply the background colour to a wrapper around the header/footer.
html
<div id="header-wrapper">
<div id="header">content</div>
</div>
<div id="container">
<div id="left-column">content</div>
<div id="right-column">content</div>
</div>
<div id="footer-wrapper">
<div id="footer">content</div>
</div>
css
#header-wrapper{width:100%;height:xxx;background:#3399ff}
#header,#footer{width:1000px;margin:0 auto}
The accepted answer is really a bad way to accomplish this. HTML is used for semantic meaning of the content. Removing your header from your container is not semantic! Here's a much better way of doing this that still preserves the semantic content: http://css-tricks.com/full-browser-width-bars/.