Boostrap indenting columns in row - css

I am new to bootstrap. Why is the second row with 3 columns (col-sm-3, col-sm-6 and col-sm-3) being indented, the other two rows have a wider width? How can I make all rows the same width?
.header {background-color: #9933cc;}
.menu ul {
list-style-type: none;
margin: 0;
padding: 0;
}
.menu li {
background-color :#33b5e5;
margin-bottom: 7px;
}
.aside {background-color: #33b5e5;}
.footer {background-color: #0099cc;}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class='container'>
<div class='row'>
<div class='header'>
<h1>China</h1>
</div><!--end header-->
</div>
<div class='row'>
<div class='menu col-sm-3'>
<ul>
<li>The Flight</li>
<li>The City</li>
<li>The Island</li>
<li>The Food</li>
</ul>
</div><!--end menu-->
<div class='col-sm-6'>
<h1>The City</h1>
<p>Chania is the capital of the Chania region on the island of Crete. The city can be divided in two parts, the old town and the modern city.</p>
<p>Resize the browser window to see how the content respond to the resizing.</p>
</div>
<div class='col-sm-3'>
<div class='aside'>
<h2>What?</h2>
<p>Chania is a city on the island of Crete.</p>
<h2>Where?</h2>
<p>Crete is a Greek island in the Mediterranean Sea.</p>
<h2>How?</h2>
<p>You can reach Chania airport from all over Europe.</p>
</div>
</div>
</div>
<div class='row'>
<div class='footer'>
<p>Resize the browser window to see how the content respond to the resizing.</p>
</div><!--end footer-->
</div>
</div><!--end container-->

Because .col-sm-3 and .col-md-6 adds padding to the div elements.
Wrap the header and footer in col-sm-12
HTML
<div class="col-md-12">
<div class='header'>
<h1>China</h1>
</div><!--end header-->
</div>
<div class="col-sm-12">
<div class='footer'>
<p>Resize the browser window to see how the content respond to the resizing.</p>
</div><!--end footer-->
</div>
Working Fiddle
Adding .col-sm-12 class to .footer and .header div's don't change because, background-color property is applied on .header and .footer and color is applied including the padding.
Wrapping these elements (footer and header) divs in .col-sm-12 adds padding to parent elements.

Related

Difficulties in stacking elements with screen size changes

I am having difficulties with stacking my divs alongside one another when the screen size is smaller, then stack on top of one another once I hit phone size.
I am using Foldy Grids by Paravel, On full desktop size, there are 3 divs that are side by side, but I want this to shrink to 2 side by side and then on phone, just 1 on top of one another. However I feel as though I am applying the media queries to the incorrect <div>'s. Any guidance would be much appreciated. Within the CSS the reason I put 33% in is due to the divs being divided into 3 on full desktop mode.
CSS:
#media screen and (max-width: 900px) {
.dashboardIconsMod {
width: 50%;
}
}
#media screen and (max-width: 600px) {
.dashboardIconsMod {
width: 100%;
}
}
.dashboardIconsMod {
color: pink;
border-style: solid;
border-color: red;
}
HTML:
<section id="content">
<div class="container">
<section id="grid" class="clearfix">
<div class="cf show-grid">
<div class="row">
<div class="grid-2 dashboardIconsMod">
<!-- 1st Div -->
<p> 1st Grid </p>
</div>
<div class="grid-2 dashboardIconsMod">
<!-- 2nd Div -->
<p> 2nd Grid </p>
</div>
<div class="grid-2 dashboardIconsMod">
<!-- 3rd Div -->
<p> 3rd Grid </p>
</div>
</div>
<div class="row">
<div class="grid-2 dashboardIconsMod">
<!-- 4th Div -->
<p> 4th Grid </p>
</div>
<div class="grid-2 dashboardIconsMod">
<!-- 5th Div -->
<p> 5th Grid </p>
</div>
<div class="grid-2 dashboardIconsMod">
<!-- 6th Div -->
<p> 6th Grid </p>
</div>
</div>
</div>
</section>
</div>
</section>
I am not sure about Foldy Grids by Paravel as never worked with it and don't have much time to read documentation, but you can fix it by giving different size on media query, just make sure your media query need to be below to your desktop code.
For now, 3 items on the desktop, on smaller screens like iPad there are 2 items and on the smaller screen below 600px, there is a single item.
.dashboardIconsMod {
color: pink;
border-style: solid;
border-color: red;
width:33.33%;
}
* {box-sizing: border-box;}
.show-grid .row {display:flex; flex-wrap: wrap;}
#media screen and (max-width: 900px) {
.dashboardIconsMod {
width: 50%;
}
}
#media screen and (max-width: 600px) {
.dashboardIconsMod {
width: 100%;
}
}
<section id="content">
<div class="container">
<section id="grid" class="clearfix">
<div class="cf show-grid">
<div class="row">
<div class="grid-2 dashboardIconsMod">
<!-- 1st Div -->
<p> 1st Grid </p>
</div>
<div class="grid-2 dashboardIconsMod">
<!-- 2nd Div -->
<p> 2nd Grid </p>
</div>
<div class="grid-2 dashboardIconsMod">
<!-- 3rd Div -->
<p> 3rd Grid </p>
</div>
</div>
<div class="row">
<div class="grid-2 dashboardIconsMod">
<!-- 4th Div -->
<p> 4th Grid </p>
</div>
<div class="grid-2 dashboardIconsMod">
<!-- 5th Div -->
<p> 5th Grid </p>
</div>
<div class="grid-2 dashboardIconsMod">
<!-- 6th Div -->
<p> 6th Grid </p>
</div>
</div>
</div>
</section>
</div>
</section>

Center elements vertically in Bulma

I just started setting up my blog prototype with Bulma. There is a footer section with two equally divided columns.
I'd like the three items (Twitter, Email, etc.) to be vertically centered in the yellow area. Is there any special class for that available in Bulma?
(Please see the full example on codepen.io.)
<footer class="footer" style="background-color: lightpink;">
<div class="columns">
<div class="column has-text-centered-touch" style="background-color: cyan;">
<p>Some copyright stuff...</p>
<p>Templated with Bulma. Published with Hugo.</p>
</div>
<div class="column has-text-right" style="background-color: yellow;">
<div class="level">
<div class="level-left"></div>
<div class="level-right">
<a class="level-item" href="#">Twitter Icon</a>
<a class="level-item" href="#">Email Icon</a>
<a class="level-item" href="#">LinkedIn Icon</a>
</div>
</div>
</div>
</div>
</footer>
You could add the following CSS so the right side column so it is vertically centered.
https://codepen.io/anon/pen/XzmEgr
.footer .has-text-right {
display: flex;
justify-content: center;
}
Make the height of the .level on the right side 100%
.right-side > .level {
height: 100%;
}
JSFiddle

How do I align images to the bottom of a div (in bootstrap)?

I would like to be able to align different sized images to the bottom of a div.
I have the following markup:
<div class="container">
<div class="container">
<div class="footer-images">
<img src="img1">
<img src="img2">
<img src="img3">
</div>
</div>
<div class="container">
<div class="copyright">
<p>© Some Company YYYY</p>
</div>
</div>
</div>
I can't figure out how to have all the images aligned to the bottom of the footer-images div. Any help would be greatly appreciated.
try this
.footer-images img{
vertical-align:bottom;
border:0;
}
In Bootstrap v4 you can use the class align-items-end to achieve bottom alignment in a div. You can use this class on the row or on the column.
Example with all column content aligned to the bottom.
<div class="container">
<div class="row align-items-end">
<div class="col">
One of three columns
</div>
<div class="col">
One of three columns
</div>
<div class="col">
One of three columns
</div>
</div>
</div>
Example with first column top, second colum middle and third colunm bottom alignment.
<div class="container">
<div class="row">
<div class="col align-self-start">
One of three columns
</div>
<div class="col align-self-center">
One of three columns
</div>
<div class="col align-self-end">
One of three columns
</div>
</div>
</div>
Source: Bootstrap documentation.
Does this help?
<style type="text/css">
.footer-images {
margin: auto;
display: block;
position: absolute;
bottom: 0;
}
.footer-images .copyright {
text-align: center;
}
</style>
Using this HTML
<div class="container">
<div class="container">
<div class="footer-images">
<img src="http://placehold.it/350x150">
<img src="http://placehold.it/640x480">
<img src="http://placehold.it/120x120">
<div class="container">
<div class="copyright">
<p>© Some Company YYYY</p>
</div>
</div>
</div>
</div>
</div>
used to this css and apply
.footer-images img{
width:xxpx;
height:xxpx; // add here your style as like with height border etc.
vertical-align:top;
border:0;
}
More about bootstrap
It would be enough:
margin-top: auto;
See https://jsfiddle.net/d3jau1gx/

Responsive Design, how to change order from div containers?

I am just starting with responsive webdesign. I have a 2 column layout (sidebar and content).
<div class="main-container">
<div class="main wrapper clearfix">
<div class="con1">
<header>
<h1>container 1 h1</h1>
<p>text1</p>
</header>
<section>
<h2>overview section h2</h2>
<p> test</p>
</section>
</div>
<div class="con2">
<header>
<h1>container 2 article header h1</h1>
<p></p>
</header>
<section>
<h2>article section h2</h2>
<p>text</p>
</section>
</div>
<aside>
<h3>aside</h3>
<p>text</p>
</aside>
</div> <!-- #main -->
</div> <!-- #main-container -->
The content got 2 div container. On a small screen I want
Div1
Div2
On a large screen I want them swapped,
Div2
Div1
In my CSS I now got the following Media Query:
#media only screen and (min-width: 768px) {
.main div.con1 {
float: right;
width: 57%;
}
.main div.con2 {
float: right;
width: 57%;
}
Is it possible to swap the order around and if so, how can I do it? Anyone got maybe a link to a good tutorial?
Thanks a lot in advance !
The method used in the StackOverflow question "CSS positioning div above another div when not in that order in the HTML" seems to be your best bet.
with js:
//on load
responsive_change_box_order();
//on resize
window.addEventListener('resize', responsive_change_box_order );
function responsive_change_box_order() {
if (window.matchMedia("(max-width: 1118px)").matches) {
jQuery("#block-menu-block-1").remove().insertBefore(jQuery("#content"));
}
else{
jQuery("#block-menu-block-1").remove().prependTo(jQuery(".region-sidebar-second .region-inner"));
}
}
This snippet uses flexbox and related properties to meet your end requirement.Also kindly note that you use use appropriate vendor prefixes for flexbox when you implement or use something like autoprefixer or prefixfree.
.main{
display:flex;
flex-direction:column
}
.con1{
order:2;
background-color: green;
}
.con2{
order:1;
background-color: red;
}
/*For Large screen only*/
#media(min-width:1200px){
.con1{
order:1;
}
.con2{
order:2;
}
}
<div class="main-container">
<div class="main wrapper clearfix">
<div class="con1">
<header>
<h1>container 1 h1</h1>
<p>text1</p>
</header>
<section>
<h2>overview section h2</h2>
<p> test</p>
</section>
</div>
<div class="con2">
<header>
<h1>container 2 article header h1</h1>
<p></p>
</header>
<section>
<h2>article section h2</h2>
<p>text</p>
</section>
</div>
<aside>
<h3>aside</h3>
<p>text</p>
</aside>
</div>
<!-- #main -->
</div>
<!-- #main-container -->

vertical-align: middle with Bootstrap 2

I use the twitter bootstrap and I wanted to align verticaly a div block with a picture and the text at the right.
Here is the code:
<ol class="row" id="possibilities">
<li class="span6">
<div class="row">
<div class="span3">
<p>some text here</p>
<p>Text Here too</p>
</div>
<figure class="span3"><img src="img/screenshots/options.png" alt="Some text" /></figure>
</div>
</li>
<li class="span6">
<div class="row">
<figure class="span3"><img src="img/qrcode.png" alt="Some text" /></figure>
<div class="span3">
<p>Some text</p>
<p>Some text here too.</p>
</div>
</div>
</li>
</ol>
I tried this but not wortks:
.span6 .row{display: table;}
.span6 .row .span3, .span6 .row figure{display:table-cell; vertical-align: middle;}
I tried this too:
.span6 .row .span3{display: inline-block; vertical-align: middle;}
None is working. Does somebody have an idea?
Thanks in advance.
Try this:
.row > .span3 {
display: inline-block !important;
vertical-align: middle !important;
}
Edit:
Fiddle: http://jsfiddle.net/EexYE/
You may need to add Diego's float: none !important; also if span3 is floating and it interferes.
Edit:
Fiddle: http://jsfiddle.net/D8McR/
In response to Alberto: if you fix the height of the row div, then to continue the vertical center alignment you'll need to set the line-height of the row to be the same as the pixel height of the row (ie. both to 300px in your case). If you'll do that you will notice that the child elements inherit the line-height, which is a problem in this case, so you will then need to set your line height for the span3s to whatever it should actually be (1.5 is the example value in the fiddle, or 1.5 x the font-size, which we did not change when we changed the line-height).
Try removing the float attribute from span6:
{ float:none !important; }
If I remember correctly from my own use of bootstrap, the .spanN classes are floated, which automatically makes them behave as display: block. To make display: table-cell work, you need to remove the float.
As well as the previous answers are you could always use the Pull attrib as well:
<ol class="row" id="possibilities">
<li class="span6">
<div class="row">
<div class="span3">
<p>some text here</p>
<p>Text Here too</p>
</div>
<figure class="span3 pull-right"><img src="img/screenshots/options.png" alt="Some text" /></figure>
</div>
</li>
<li class="span6">
<div class="row">
<figure class="span3"><img src="img/qrcode.png" alt="Some text" /></figure>
<div class="span3">
<p>Some text</p>
<p>Some text here too.</p>
</div>
</div>
</li>
i use this
<style>
html, body{height:100%;margin:0;padding:0 0}
.container-fluid{height:100%;display:table;width:100%;padding-right:0;padding-left: 0}
.row-fluid{height:100%;display:table-cell;vertical-align:middle;width:100%}
.centering{float:none;margin:0 auto}
</style>
<body>
<div class="container-fluid">
<div class="row-fluid">
<div class="offset3 span6 centering">
content here
</div>
</div>
</div>
</body>

Resources