bootstrap column to fit width - html

I hope this image can help me describe what I mean. I want to make the arrow and the boxes inline without the vacant space on the right. you can notice that the left most box is alligned on the white box on top, that is also what I want to achieve in the right. I will attach my code so you can see how did I do this.
Note: I updated the image above. There is a white box on top and under this 4 boxes. I need to align the eplay box to the white box above it and under it. also align the slide show demo box on the white box above and below it. Plus evenly space and size. And after eplay demo, theatre script demo, and audio speech demo box I need to put an arrow image in between. like this image below but need the right side box align to the top white box and under it.
<!--===================DEMOS ==================-->
<div class="row">
<div class="col-sm-12 col-md-12 col-lg-12 container-nopads" style="">
<div class="col-sm-2 col-md-2 col-lg-2 " >
<div class="demo-box col-sm-12 col-xs-12" id="demo-pdf">
<a href="/versebuster2/eplay/eplay-demo.php" style="text-decoration:none;">
<h4><strong>ePlay Demo</strong></h4><br><br><br>
<img src="images/hovers/pdf-512.png" >
</a>
</div>
</div>
<div class="col-xs-1 col-sm-1 col-lg-1 col-md-1 container-nopads" style="">
<img src="images/arrow-right.png" class="img-responsive" >
</div>
<div class="col-sm-2 col-md-2 col-lg-2 " >
<div class="demo-box col-sm-12 col-xs-12" id="demo-doc">
<h4><strong>Theatre Script Demo</strong></h4><br><br>
<img src="images/hovers/doc-512.png" class="">
</div>
</div>
<div class="col-xs-1 col-sm-1 col-lg-1 col-md-1 container-nopads" style="">
<img src="images/arrow-right.png" class="img-responsive" >
</div>
<div class="col-sm-2 col-md-2 col-lg-2 " >
<div class="demo-box col-sm-12 col-xs-12" id="demo-mp3">
<h4><strong>Audio Speech Demo</strong></h4><br><br>
<img src="images/hovers/mp3-512.png" class="">
</div>
</div>
<div class="col-xs-1 col-sm-1 col-lg-1 col-md-1 container-nopads" style="">
<img src="images/arrow-right.png" class="img-responsive" >
</div>
<div class="col-sm-2 col-md-2 col-lg-2 " >
<div class="demo-box col-sm-12 col-xs-12" id="demo-pdf">
<a href="data/pdf/ePlayPPPDemo.pdf" target="_blank" style="text-decoration:none; ">
<h4><strong>Slide Show Demo</strong></h4><br><br><br>
<img src="images/hovers/pdf-512.png" class="">
</a>
</div>
</div>
</div>
</div>
<!--===================END DEMOS ==================-->

Use a .col-md-3 class for this case:
.col-md-3 .inner {margin: 5px; background: #99f; text-align: center;}
<script src="https://code.jquery.com/jquery-1.9.1.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<div class="row-fluid">
<div class="container-fluid">
<div class="col-md-3">
<div class="inner">One</div>
</div>
<div class="col-md-3">
<div class="inner">Two</div>
</div>
<div class="col-md-3">
<div class="inner">Three</div>
</div>
<div class="col-md-3">
<div class="inner">Four</div>
</div>
</div>
</div>
Preview:

Related

Does bootstrap let me to modify his own classes to make a page responsive

I'm creating project based in html and css. I have created this code in bootstrap inside a container and I want this to be responsive.
<div class=" container">
<div class="row">
<div class="col-md-12 col-sm-12 client "> <b>SEI GIÀ CLIENTE? ACCEDI </b>
</div>
</div>
<div class="row">
<div class="col-md-3 col-sm-3"></div>
<div class="col-md-3 col-sm-3 labelField">
<div class="row">
<div class="col-md-4 col-sm-4 labelField">
<strong><br>EMAIL</strong>
</div>
<div class="col-md-8 col-sm-8">
<input class="ut" type="mail">
</div>
</div>
</div>
<div class="col-md-6 col-sm-6"></div>
</div>
<div class="row">
<div class="col-md-3 col-sm-3"></div>
<div class="col-md-3 col-sm-3 labelField">
<div class="row">
<div class="col-md-4 col-sm-4 labelField">
<strong><br>PASSWORD</strong>
</div>
<div class="col-md-8 col-sm-8">
<input class="ut" type="mail">
</div>
</div>
</div>
<div class="col-md-6 col-sm-6"></div>
</div>
<div class="row">
<div class="col-md-3 col-sm-3 col-xs-3 "></div>
<div class="col-md-6 col-sm-6 col-xs-6 pass"> Hai dimenticato la password?
</div>
<div class="col-md-3 col-sm-3 col-xs-3"></div>
</div>
<div class="row">
<div class="col-md-12 col-sm-12 ">
<a href="#">
<img src="images/entra.png" class="img-responsive registrati ">
</a>
</div>
</div>
<div class="row">
<div class="col-md-12 col-sm-12 ">
<a href="#">
<img src="images/fb.png" class="img-responsive registrati ">
</a>
</div>
</div>
<div class="row">
<div class="col-md-12 col-sm-12 ">
<div class="divider"></div>
</div
Here is my css:
.registrati {
margin-top: 20px;
margin-left: 338px;
margin-bottom: 8px;
width: 33%px;
}
.pass {
font-style: Arial black;
color: black;
font-size: 0.8em;
margin-left: 339px;
margin-bottom: 20px;
margin-top: 20px;
text-decoration: underline;
}
Here is what my result should look like:
The result is not responsive. My question is have I done something wrong or bootstrap doesnt let me to modify the classes as I did? So what should I do to make this responsive?
All the scripts and links required for responsivity are in my page but not here for a shorter demo. Thanks!
I can't run your snippet on my Mac but just by looking at your code, I would remove width: 80%; height: 100%; If you really want it to be responsive the "bootstrap way", try letting it handle your div containers in terms of sizes first. Have you tried that?
Looks fine in terms of responsiveness without your stylesheet: https://jsfiddle.net/DTcHh/23755/
EDIT: those margins seem pretty large? Maybe it just looks like it's not responsive because of the huge margins. Can you maybe provide a sketch of what it should look like?
EDIT2: Here is my answer: https://jsfiddle.net/DTcHh/23757/ I cleaned it up a bit. Your problem was that you had way too many divs and columns; you should check out Bootstrap's grid documentation again and use col-md-offset if you want to offset things by design.
First of all I am assuming that you have included bootstrap css and js properly. Going further you don't need additional css for making your page responsive. Bootstrap does that. Always remember bootstrap has 12 columns in a row. So u need to use it properly for your page to show responsiveness.
<div class="container contain">
<div class="row">
<div class="col-lg-3 col-md-4 col-sm-2 col-xs-12 text-center">
<a href="#">
<img src="https://www.google.co.in/logos/doodles/2016/2016-doodle-fruit-games-day-12-5125886484414464.3-scta.png" class="registrati img-responsive">
</a>
</div>
<div class="col-lg-6 col-md-4 col-sm-8 col-xs-12 pass text-center">
<a href="https://www.google.co.in/logos/doodles/2016/2016-doodle-fruit-games-day-12-5125886484414464.3-scta.png">
Hai dimenticato la password?
</a>
</div>
<div class="col-lg-3 col-md-4 col-sm-2 col-xs-12 text-center">
<a href="#">
<img src="https://www.google.co.in/logos/doodles/2016/2016-doodle-fruit-games-day-12-5125886484414464.3-scta.png" class="registrati img-responsive">
</a>
</div>
</div>
</div>

Bootstrap is adding a white line when going from col-sm to col-xs

When my page re-sizes from SM to XS it is adding a white line (almost like a margin space) and I don't know why. If I add a style="margin-top: -1px" it goes away but then messes up the rest of the grid structure. Any ideas as to what is causing this? Below is the code, if you run the snippet and shrink the window you'll see the line appear.
<html>
<head>
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css"/>
<title>JPT Email Template Title</title>
</head>
<body>
<div class="container-fluid">
<div class="row" style="margin-top: 20px">
<div class ="col-xs-0 col-sm-1 col-md-2 col-lg-3"></div>
<div class="col-xs-12 col-sm-10 col-md-8 col-lg-6 bg-primary text-center">
<img class="img-responsive center-block" src="http://pages.jerusalemprayerteam.org/rs/591-HWU-361/images/foz-logo.png" style="margin-top: 5px; margin-bottom: 5px">
</div>
<div class="col-xs-0 col-sm-1 col-md-2 col-lg-3"></div>
</div>
<div class="row">
<div class="col-xs-0 col-sm-1 col-md-2 col-lg-3"></div>
<div class="col-xs-12 col-sm-10 col-md-8 col-lg-6 text-center bg-primary">
<a href="#">
<img class="img-responsive center-block" src="http://i.imgur.com/i131rzd.jpg" style="margin-bottom: 5px">
</a>
</div>
<div class"col-xs-0 col-sm-1 col-md-2 col-lg-3"></div>
</div>
This happens cause you do not use bootstrap properly, you have chosen an option of adding extra divs for offset and it's wrong. Bootstrap has offset for this cases:
<div class="col-sm-10 col-sm-offset-1 col-md-8 col-md-offset-2 col-lg-6 col-lg-offset-3">
Your content
</div>
Do not use those extra divs for offset, one of those is giving you this 1px
Columns have a min-height of 1px. So the below creates the white line. Try using .hidden-xs instead.
<div class="col-xs-0 col-sm-1 col-md-2 col-lg-3"></div>
in addition to previous answers, Bootstrap has not class "col-xs-0".

Border wrapping other elements when resizing window bootstrap

I am trying to wrap the last content using border, but when I resize the window border wraps above content too?
<div class="row">
<div class=" col-xs-6 col-sm-3 ">
<img src="image/1.png" class="img-responsive center-block" >
</div>
<div class=" col-xs-6 col-sm-3 ">
<img src="image/2.png" class="img-responsive center-block" >
</div>
<div class=" col-sm-6 clearfix" id="t">
<div class="col-xs-7 ">
<h3>hello</h3>
Add
</div>
<div class="col-xs-5 ">
<img src="image/t.png" class="img-responsive pull-right">
</div>
</div>
</div>
I am using following css
#t{
border: 5px solid rgb(232,226,226);
}
I presume you mean at small screen sizes, it's not behaving as you'd like. The problem is you're not telling bootstrap how to treat that div when the screen is below 768 pixels. Try this:
<div class=" col-xs-12 col-sm-6 clearfix" id="t">
Note I've just added the .col-xs-12 class. Works for me in a quick test.

Basic centering elements in adaptive row class in bootstrap

On my page I have lots of elements, which I need to show by several in a row in straight columns. Each element is an image of equal size. When you click on it, on it's place appears icon menu with three items in a row. All elements should be centred horizontally and vertically.
There could be a different number of big images (6, 7, 8 or more) so I want to add them in one row-class.
Now, I think I'm doing everything by bootstrap documentation, but elements logic on the page steel appears to be broken.
What am I doing wrong?
Codepen example
<body>
<div class="container-fluid wrapper">
<div class="row center-block text-center">
<div class="center-block col-xs-6 col-sm-4 col-md-3 col-lg-2">
<div class="row center-block">
<div class="col-md-12 center-block">
<img src="http://img.leprosorium.com/2474872">
</div>
</div>
</div>
<div class="center-block col-xs-6 col-sm-4 col-md-3 col-lg-2">
<div class="row center-block">
<div class="col-md-12 center-block">
<img src="http://img.leprosorium.com/2474872">
</div>
</div>
</div>
<div class="center-block col-xs-6 col-sm-4 col-md-3 col-lg-2">
<div class="row center-block">
<div class="col-md-12 center-block">
<img src="http://img.leprosorium.com/2474872">
</div>
</div>
</div>
<div class="center-block col-xs-6 col-sm-4 col-md-3 col-lg-2">
<div class="row-fluid center-block text-center pagination-centered">
<div class="col-md-4 center-block text-center pagination-centered link">
<a target="_blank" href="#"><img src="http://img.leprosorium.com/2474848"></a>
</div>
<div class="col-md-4 center-block text-center pagination-centered link">
<a target="_blank" href="#"><img src="http://img.leprosorium.com/2474848"></a>
</div>
<div class="col-md-4 center-block text-center pagination-centered link">
<a target="_blank" href="#"><img src="http://img.leprosorium.com/2474848"></a>
</div>
<div class="col-md-4 center-block text-center pagination-centered link">
<a target="_blank" href="#"><img src="http://img.leprosorium.com/2474848"></a>
</div>
<div class="col-md-4 center-block text-center pagination-centered link">
<a target="_blank" href="#"><img src="http://img.leprosorium.com/2474848"></a>
</div>
<div class="col-md-4 center-block text-center pagination-centered link">
<a target="_blank" href="#"><img src="http://img.leprosorium.com/2474848"></a>
</div>
<div class="col-md-4 center-block text-center pagination-centered link">
<a target="_blank" href="#"><img src="http://img.leprosorium.com/2474848"></a>
</div>
<div class="col-md-4 center-block text-center pagination-centered link">
<a target="_blank" href="#"><img src="http://img.leprosorium.com/2474848"></a>
</div>
<div class="col-md-4 center-block text-center pagination-centered link">
<a target="_blank" href="#"><img src="http://img.leprosorium.com/2474848"></a>
</div>
</div>
</div>
<div class="center-block col-xs-6 col-sm-4 col-md-3 col-lg-2">
<div class="row center-block">
<div class="col-md-12 center-block">
<img src="http://img.leprosorium.com/2474872">
</div>
</div>
</div>
<div class="center-block col-xs-6 col-sm-4 col-md-3 col-lg-2">
<div class="row center-block">
<div class="col-md-12 center-block">
<img src="http://img.leprosorium.com/2474872">
</div>
</div>
</div>
<div class="center-block col-xs-6 col-sm-4 col-md-3 col-lg-2">
<div class="row center-block">
<div class="col-md-12 center-block">
<img src="http://img.leprosorium.com/2474872">
</div>
</div>
</div>
<div class="center-block col-xs-6 col-sm-4 col-md-3 col-lg-2">
<div class="row center-block">
<div class="col-md-12 center-block">
<img src="http://img.leprosorium.com/2474872">
</div>
</div>
</div>
<div class="center-block col-xs-6 col-sm-4 col-md-3 col-lg-2">
<div class="row center-block">
<div class="col-md-12 center-block">
<img src="http://img.leprosorium.com/2474872">
</div>
</div>
</div>
</div>
</div>
</body>
Screenshot of what I get:
Screenshot of what I need:
Please point me in the right direction. Thank you in advance. I was able to done it without bootstrap, b I hope it could be done only by the right usage of bootstrap and elements, because I want to save the adaptive layout.
UPD #LegendaryAks fixed the problem with gap by using <div class="clearfix"></div> after icons element, but problem of centering all elements for the adaptive layout and unknown number of total elements is still open.
UPD2 Centering just one element in the end is not enough, because we need to know how to center from one to max number of elements on the last row, sow that we could load all the elements on a page with no worry for the last row centering.
There you go i think this did the trick . You can check the demo at http://codepen.io/anon/pen/QybXQJ?editors=100
What i did is I added a div with class clearfix after the fourth div. I hope this is what you are looking for
<div class="clearfix"></div>
there the solution using only css:
.center-block-big:nth-child(4n+1) {
clear: left;
}
.center-block-big:last-child {
margin: 0 auto;
float: none;
}
the only thing is that in this example i have removed the col-lg-2 to apply it to all resolution, and edited the class name to only apply to the container of the big images and not the twitter ones.
updated codepen
If you want mantain the space on lg resolution you need to play with the col width a bit in this way:
updated codepen
If you have dynamic elements you can use this to make that only if one element is on a row it will be centered:
.center-block-big:nth-child(4n+1) {
clear: left;
}
.center-block-big:last-child:not(:nth-child(5n)) {
margin: 0 auto;
float: none;
}
.center-block-big:nth-child(4n+2),
.center-block-big:nth-child(4n+3),
.center-block-big:nth-child(4n) {
float: left!important;
}
updated codepen, add .center-block-big elements to see the effect
use col-md-12 instead of col-md-6 at the last element of your design.
Try this:
<div class="col-md-12 center-block text-center pagination-centered link">
<a target="_blank" href="#">VK</a>
</div>
AND
<div class="col-md-12 center-block text-center pagination-centered link">
<a target="_blank" href="#">FB</a>
</div>
for vertical align use make a new class
.verticalcenter {
display: inline-block;
vertical-align: middle;
float: none;
}
and use it.
make your HTML structure like below:
First Row..
<div class="row center-block text-center">
<div class="center-block col-md-4">
</div>
<div class="center-block col-md-4">
</div>
<div class="center-block col-md-4">
</div>
</div>
Second Row..
<div class="row center-block text-center">
<div class="center-block col-md-4">
</div>
<div class="center-block col-md-4">
</div>
<div class="center-block col-md-4">
</div>
</div>

bootstrap 3 responsive grid break with images

Probably I'm missing something or have misinterpreted BS documentation, the html below works as expected if I use text instead of images, as I place the images it breaks on xs and sm.
By expected I mean: 1 row 8 columns on >= md, 2 rows 4 columns on sm, 4 rows 2 columns on xs.
On my browsers (Chrome/Firefox) the behavior seems to be:
first row always correct
second row align the first image to the right and break the line (go to the next line)
Any suggestion?
<div class="container">
<div class="row">
<div class="col-xs-6 col-sm-3 col-md-1 text-center">
<img src="http://placehold.it/50x50" />
</div>
<div class="col-xs-6 col-sm-3 col-md-2 text-center">
<span class="stat-title">999</span><br />text
</div>
<div class="col-xs-6 col-sm-3 col-md-1 text-center">
<img src="http://placehold.it/50x50" />
</div>
<div class="col-xs-6 col-sm-3 col-md-2 text-center">
<span class="stat-title">999</span><br />text
</div>
<div class="col-xs-6 col-sm-3 col-md-1 text-center">
<img src="http://placehold.it/50x50" />
</div>
<div class="col-xs-6 col-sm-3 col-md-2 text-center">
<span class="stat-title">999</span><br />text
</div>
<div class="col-xs-6 col-sm-3 col-md-1 text-center">
<img src="http://placehold.it/50x50" />
</div>
<div class="col-xs-6 col-sm-3 col-md-2 text-center">
<span class="stat-title">999</span><br />text
</div>
</div>
</div>
i believe its because the height of your divs is different. the image is 50px while the text is slightly less, so when bootstrap puts them in their columns, it sees that the right column is shorter than the left, so it'll put the next image (2nd) under the 1st text block.
if you do something like this it should work.
*in essence, all you have to do is make sure that the heights of the divs are equal
div.text-center{
min-height: 50px;
}
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="col-xs-6 col-sm-3 col-md-1 text-center">
<img src="http://placehold.it/50x50" />
</div>
<div class="col-xs-6 col-sm-3 col-md-2 text-center">
<span class="stat-title">999</span><br />text
</div>
<div class="col-xs-6 col-sm-3 col-md-1 text-center">
<img src="http://placehold.it/50x50" />
</div>
<div class="col-xs-6 col-sm-3 col-md-2 text-center">
<span class="stat-title">999</span><br />text
</div>
<div class="col-xs-6 col-sm-3 col-md-1 text-center">
<img src="http://placehold.it/50x50" />
</div>
<div class="col-xs-6 col-sm-3 col-md-2 text-center">
<span class="stat-title">999</span><br />text
</div>
<div class="col-xs-6 col-sm-3 col-md-1 text-center">
<img src="http://placehold.it/50x50" />
</div>
<div class="col-xs-6 col-sm-3 col-md-2 text-center">
<span class="stat-title">999</span><br />text
</div>
</div>
</div>
I think I see what you're experiencing. This is a common issue with BS, actually. What's happening is the fifth column has room under the fourth column to squeeze itself in there. You could add a custom class to the columns to set a min-height and force the fifth column down. In other words, since a new row isn't explicitly defined, any columns greater than 12 will squeeze themselves wherever they can go. You can get around this by defining the min-height on a custom class to equal the height of your tallest element in the row.
I think this is what you're seeing: https://jsfiddle.net/ejutc5bf/
Here's my fix:
HTML:
<divhttps://jsfiddle.net/DTcHh/#update class="container">
<div class="row">
<div class="col-xs-6 col-sm-3 col-md-1 text-center custom">
<img src="http://placehold.it/50x50" />
</div>
<div class="col-xs-6 col-sm-3 col-md-2 text-center custom">
<span class="stat-title">999</span><br />text
</div>
<div class="col-xs-6 col-sm-3 col-md-1 text-center custom">
<img src="http://placehold.it/50x50" />
</div>
<div class="col-xs-6 col-sm-3 col-md-2 text-center custom">
<span class="stat-title">999</span><br />text
</div>
<div class="col-xs-6 col-sm-3 col-md-1 text-center custom">
<img src="http://placehold.it/50x50" />
</div>
<div class="col-xs-6 col-sm-3 col-md-2 text-center custom">
<span class="stat-title">999</span><br />text
</div>
<div class="col-xs-6 col-sm-3 col-md-1 text-center custom">
<img src="http://placehold.it/50x50" />
</div>
<div class="col-xs-6 col-sm-3 col-md-2 text-center custom">
<span class="stat-title">999</span><br />text
</div>
</div>
</div>
CSS:
.custom{
min-height: 100px;
}
Fiddle
*You'll likely want to make your own custom class and apply it to that. If you apply it to a pre-existing class (text-center, for example) it will apply to ALL of those classes if and when they're used in the future.
The images are likely larger than their container div columns. Try this:
img { max-width: 100% }
In order to make your images responsive, you need to use img-responsive class.
<img class="img-responsive" src="http://placehold.it/50x50" />
See http://getbootstrap.com/css/#images