Bootstrap 4 columns not stacking when screen is resized [duplicate] - css

This question already has answers here:
Bootstrap columns stacking vertically on mobile device
(2 answers)
Bootstrap 4.0 Grid System Layout not working
(1 answer)
Closed 4 years ago.
I can't seem to get my head around why the divs are not stacking on top of each other when I re size the screen.
I'm using col-xs-4 col-md-4 col-lg-4 but the content stays in one row and doesn't even resize.
<div class="container">
<div class="row">
<div class="info">
<div class="col-xs-4 col-md-4 col-lg-4">
<div class="logo-link"><img alt="Spartan Safety Logo" class="img-fluid" src="img/logo.png">
</div>
</div>
<div class="col-xs-4 col-md-4 col-lg-4">
<div class="info-center-1">
<div class="info-center-icon">
<i class="fa fa-phone-square fa-2x"></i>
</div>
<div class="info-center-title">
<h6>Customer Support and Sales</h6>
</div>
<div class="info-center-text">
<p>0208 5275888</p>
</div>
</div>
</div>
<div class="col-xs-4 col-md-4 col-lg-4">
<div class="info-center-1">
<div class="info-center-icon">
<i class="fa fa-clock-o fa-2x"></i>
</div>
<div class="info-center-title">
<h6>Opening Hours</h6>
</div>
<div class="info-center-text">
<p>Mon - Fri 08:30 - 4:30</p>
</div>
</div>
</div>
</div>
</div>
</div>
CSS
.info {
display: inline-flex;
margin: 20px 0px 10px 0px;
}
.logo-link img {
max-width: 50%;
height: auto;
margin-bottom: 10px;
}
.info-center-1 {
margin-top: 20px;
}
.info-center-icon i {
color: #cccccc;
display: inline-flex;
}
.info-center-title {
margin-bottom: px;
}
.info-center-title h6 {
font-family: 'Open Sans', Helvetica, Arial, sans-serif;
font-size: 16px;
font-weight: 400;
font-style: normal;
line-height: 22px;
text-transform: uppercase;
display: inline-flex;
}
.info-center-text p {
font-family: 'Open sans', sans-serif;
font-size: 24px;
font-weight: 400;
color: #FF9900;
line-height: 22px;
display: inline-flex;
}

You should not add more divs between .row and .col-. Instead, merge both info and row so you only have one wrapper for the col- divs:
<div class="container">
<div class="row info">
<div class="col-xs-4 col-md-4 col-lg-4">
<div class="logo-link"><img alt="Spartan Safety Logo" class="img-fluid" src="img/logo.png">
</div>
</div>
<div class="col-xs-4 col-md-4 col-lg-4">
<div class="info-center-1">
<div class="info-center-icon">
<i class="fa fa-phone-square fa-2x"></i>
</div>
<div class="info-center-title">
<h6>Customer Support and Sales</h6>
</div>
<div class="info-center-text">
<p>0208 5275888</p>
</div>
</div>
</div>
<div class="col-xs-4 col-md-4 col-lg-4">
<div class="info-center-1">
<div class="info-center-icon">
<i class="fa fa-clock-o fa-2x"></i>
</div>
<div class="info-center-title">
<h6>Opening Hours</h6>
</div>
<div class="info-center-text">
<p>Mon - Fri 08:30 - 4:30</p>
</div>
</div>
</div>
</div>
Working example: http://jsfiddle.net/aq9Laaew/34182/

If you want a column to take the whole width of the row for a particular screen size then you should specify col-ScreenSize-12. So you should be using col-xs-12 col-md-4 col-lg-4 instead.
And also display: inline-flex; styling on class .info is making the division to be in a single line always, so remove it.

Related

How to get div's centered next to each other in this Bootstrap 3 grid?

I have 6 divs, each of which has a specific width in number of pixels. Using Bootstrap 3 I would like to have a maximum of 3 boxes on one row/line. As the screen gets smaller it should move to 2 divs on one line, and when it gets smaller even more just 1 div on a row. How can I do this?
I expected the code below to achieve this.
However, the divs displayed on one row unfortunately are not centered. How to center these divs?
.mainDiv {
margin: 0 auto;
}
.specificWidthInNumberOfPixels {
border: 14px solid #dd5;
width: 160px;
height: 160px;
padding: 15px;
text-align: center;
margin: 5px;
}
.float {
float: left;
display: table;
margin: auto;
}
<div class="mainDiv container-fluid">
<div class="col-xs-12 col-sm-12" style="">
<p style="text-align: center;">Header</p>
</div>
<div class="row" style="max-width: 700px; float: none; display: table; margin: auto; background-color: #000;">
<div class="col-xs-6 col-sm-4 float">
<div class="specificWidthInNumberOfPixels">
<p>Text</p>
</div>
</div>
<div class="col-xs-6 col-sm-4 float">
<div class="specificWidthInNumberOfPixels">
<p>Text</p>
</div>
</div>
<div class="col-xs-6 col-sm-4 float">
<div class="specificWidthInNumberOfPixels">
<p>Text</p>
</div>
</div>
<div class="col-xs-6 col-sm-4 float">
<div class="specificWidthInNumberOfPixels">
<p>Text</p>
</div>
</div>
<div class="col-xs-6 col-sm-4 float">
<div class="specificWidthInNumberOfPixels">
<p>Text</p>
</div>
</div>
<div class="col-xs-6 col-sm-4 float">
<div class="specificWidthInNumberOfPixels">
<p>Text</p>
</div>
</div>
</div>
</div>
Update: In response to this answer: so the answer now produces the visual at the top, but instead what I'm looking for is the visual at the bottom:
If you can use CSS Grid, you're in good shape. Look on codepen to preview it, the code snippet seems like it's acting up:
https://codepen.io/tobyinternet/pen/bGdoBEr
.mainDiv {
margin: 0 auto;
width: 100%;
text-align: center;
}
.row-grid:before, .row-grid:after {
display: none;
}
.row-grid {
margin: 0 auto;
width:100%;
max-width: 500px;
display: grid !important;
grid-template-columns: repeat(auto-fit,160px);
column-gap: 10px;
row-gap: 10px;
justify-content: center;
}
.specificWidthInNumberOfPixels {
border: 14px solid #dd5;
width: 160px;
height: 160px;
padding: 15px;
text-align: center;
}
p {
color: white;
}
<div class="mainDiv container-fluid">
<div class="col-xs-12 col-sm-12" style="">
<p style="text-align: center;">Header</p>
</div>
<div class="row row-grid" style="background-color: #000;">
<div class="col">
<div class="specificWidthInNumberOfPixels">
<p>Text</p>
</div>
</div>
<div class="col">
<div class="specificWidthInNumberOfPixels">
<p>Text</p>
</div>
</div>
<div class="col">
<div class="specificWidthInNumberOfPixels">
<p>Text</p>
</div>
</div>
<div class="col">
<div class="specificWidthInNumberOfPixels">
<p>Text</p>
</div>
</div>
<div class="col">
<div class="specificWidthInNumberOfPixels">
<p>Text</p>
</div>
</div>
<div class="col">
<div class="specificWidthInNumberOfPixels">
<p>Text</p>
</div>
</div>
</div>
</div>
You're supposed to wrap them in a container-fluid or container class with a row child element, like so:
<div class="container-fluid">
<div class="row">
<div class="col-xs-6 col-sm-4">
<div class="specificWidthInNumberOfPixels">
<p>Text</p>
</div>
</div>
<div class="col-xs-6 col-sm-4">
<div class="specificWidthInNumberOfPixels">
<p>Text</p>
</div>
</div>
<div class="col-xs-6 col-sm-4">
<div class="specificWidthInNumberOfPixels">
<p>Text</p>
</div>
</div>
</div>
</div>
This will display 1 row of 3 columns. Add a second row within the container div with the same 3 columns to display a second row of 3 columns

Bootstrap 4 Vertically align footer while respecting columns and rows

I'm trying to find a solution how to vertically align the 2 rows in the footer which are placed with a Bootstrap grid.
I've already tried to make a wrapper for the content and apply the regular flexbox solution:
display: flex; align-items: center. But this moves both rows to be on the same row.
Fiddle here https://codepen.io/pen/WNNPdxv
HTML
<footer class="footer">
<div class="footer-wrapper">
<div class="container">
<div class="row row">
<div class="col-sm-8 footer-credit">
<h6>GetMove</h6>
<p>Copyright &copy 2019 GetMove All Rights Reserved</p>
</div>
<div class="col-sm-2 footer-contact">
<h6>Contact</h6>
hola#getmove.net
</div>
<div class="col-sm-2 footer-social-icons">
<h6>Follow us</h6>
<a class="social-icon" target="_blank" href="https://www.facebook.com/pg/GetMove.Official/"
><i class="fab fa-facebook-square"></i
></a>
<a class="social-icon" target="_blank" href="https://www.instagram.com/getmovemx/"
><i class="fab fa-instagram"></i
></a>
<a class="social-icon" target="_blank" href="https://soundcloud.com/getmove"
><i class="fab fa-soundcloud"></i
></a>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-sm-8 text-center"></div>
<div class="col-sm-4 footer-newsletter">
<h6>Subscribe</h6>
<div class="input-group input-group-sm mb-3">
<input
type="text"
class="form-control shadow-none"
id="subscribe"
placeholder="# Enter your email adress"
aria-label="Sizing example input"
aria-describedby="inputGroup-sizing-sm"
/>
<div class="input-group-append">
<button class="btn btn-outline-secondary" type="button" id="button-addon1">
Submit
</button>
</div>
</div>
</div>
</div>
</div>
<div class="container footer-credit">
<div class="row">
<div class="col-sm-8"></div>
<div class="col-sm-4 footer-credit"></div>
</div>
</div>
</div>
</footer>
CSS
.footer {
width: 100%;
height: 24em; /* Set the fixed height of the footer here */
background-color: #f4f2f0;
margin-top: 4em;
}
.footer-social-icons {
list-style-type: none;
}
.footer h6 {
text-transform: uppercase;
font-size: 16px;
}
.footer-credit {
font-size: 11px;
}
.social-icon {
/* display: block; */
margin: 0;
font-size: 16px;
}
.form-control:focus {
border-color: black;
}
The idea of a wrapper to vertically center content is correct, however you already have a wrapper in place => container.
No need to have multiple containers inside a single section (footer). You use rows for this.
So to clean-up your structure a bit, as suggested in the comments, is key to understand what's going on.
container is your wrapper
row row is redundant
empty columns as placeholder are not required with flexbox (bootstrap 4), not sure if that's what's going on... => m-auto, ml-auto, mr-auto
place custom classes inside columns (these blocks might change places someday, especially when designing for a CMS)
keep the structure clean and decorate with utility classes if needed (padding, margin, ...)
HTML Structure
<footer role="contentinfo">
<div class="container">
<div class="row">
<div class="col-sm-7"></div>
<div class="col-sm-3"></div>
<div class="col-sm-2"></div>
</div>
<div class="row">
<div class="col-sm-5 ml-auto"></div>
</div>
<div class="row">
<div class="col-sm-5 ml-auto"></div>
</div>
</div>
</footer>
Solution
Now your height is set on the footer, your container is simply taking the required height inside the space. This means you should now be able to move it vertically with flexbox.
footer[role="contentinfo"] {
display: flex;
flex-flow: column wrap;
justify-content: center; /* content of the footer is the container */
}
DEMO

CSS text side by side same height

I am trying to make this text
but how can I make it same height and make inline each other
<div class="row">
<div class="col-xs-12 text-center">
<p style="display:inline">初期費用 <br> 月額費用 <br>手続き料</p>
<h3 style="display:inline">0<span>円</span></h3>
</div>
</div>
Try this:
p, h3{
display: inline-block;
}
h3 {
color: skyblue;
font-size: 70px;
}
<div class="row">
<div class="col-xs-12 text-center">
<p>初期費用 <br> 月額費用 <br>手続き料</p>
<h3>0<span>円</span></h3>
</div>
</div>
Using display flex
.col-xs-12 {
display: flex;
align-items: center;
padding: 0;
}
p {
font-size: 16px;
line-height: 1.5;
margin-right: 8px;
}
h3 {
font-size: 102px;
margin: 0;
}
h3 span {
font-size: 32px
}
<div class="row">
<div class="col-xs-12 text-center container">
<p>初期費用 <br> 月額費用 <br>手続き料</p>
<h3>0<span>円</span></h3>
</div>
</div>
Here you go with a solution
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.css" rel="stylesheet"/>
<div class="row">
<div class="col-xs-12 text-center">
<div style="display: flex;">
<p style="display: inline-flex">初期費用 <br> 月額費用 <br>手続き料</p>
<h3 style="display: inline-flex">0<span>円</span></h3>
</div>
</div>
</div>
Solution using flex & inline-flex

CSS - My bootstrap columns aren't breaking correctly

I have a list which looks like this:
https://codepen.io/Insane415/pen/QgbQvv
but somehow the columns aren't breaking correctly when resizing the window. I want to keep it readable when someone access my page with a smartphone or other small devices.
Any help would be appreciate
(reduced code)
HTML
<ol class="product-list">
<div class="row">
<div class="col-md-3">
<li>
<div class="row vertical-center">
<div class="col-lg-4 col-md-12 col-xs-12 text-right">
<strong>Productname</strong>
<span class="product-description">
Some text, which describes the product lorem ipsum.
</span>
</div>
<div class="image-holder col-lg-4 col-xs-12 col-md-12">
<img src="http://via.placeholder.com/100x100"/>
</div>
<div class="circle col-lg-4 col-xs-12 col-md-12">
<span class="circle-number"></span>
</div>
</div>
</li>
<li>
<div class="row vertical-center">
<div class="col-lg-4 col-md-12 col-xs-12 text-right">
<strong>Productname</strong>
<span class="product-description">
Some text, which describes the product lorem ipsum.
</span>
</div>
<div class="image-holder col-lg-4 col-xs-12 col-md-12">
<img src="http://via.placeholder.com/100x100"/>
</div>
<div class="circle col-lg-4 col-xs-12 col-md-12">
<span class="circle-number"></span>
</div>
</div>
</li>
</div>
<div class="col-md-6 large-image-holder">
<img class="image-large" src="http://via.placeholder.com/500x400"/>
</div>
<div class="col-md-3">
<li>
<div class="row vertical-center">
<div class="circle col-lg-4 col-xs-12 col-md-12">
<span class="circle-number"></span>
</div>
<div class="image-holder col-lg-4 col-xs-12 col-md-12">
<img src="http://via.placeholder.com/100x100"/>
</div>
<div class="col-lg-4 col-md-12 col-xs-12 text-left">
<strong>Productname</strong>
<span class="product-description">
Some text, which describes the product lorem ipsum.
</span>
</div>
</div>
</li>
<li>
<div class="row vertical-center">
<div class="circle col-lg-4 col-xs-12 col-md-12">
<span class="circle-number"></span>
</div>
<div class="image-holder col-lg-4 col-xs-12 col-md-12">
<img src="http://via.placeholder.com/100x100"/>
</div>
<div class="col-lg-4 col-md-12 col-xs-12 text-left">
<strong>Productname</strong>
<span class="product-description">
Some text, which describes the product lorem ipsum.
</span>
</div>
</div>
</li>
</div>
CSS
body {
counter-reset: counter;
}
.circle-number {
counter-increment: counter;
}
.circle-number:after {
content: counter(counter);
}
.product-list{
padding-left: 50px;
padding-right: 50px;
}
.product-description{
display: block;
}
img{
margin-top: 15px;
}
li{
/*display: inline-block;*/
list-style-type: none;
border-bottom: 2px solid #47c9e5;
padding-bottom: 20px;
margin-top: 10px;
}
.large-image-holder{
text-align: center;
object-fit: cover;
}
.image-large{
object-fit: cover;
width: 100%;
}
.circle{
display: flex;
align-items: center;
justify-content: center;
border-radius: 100%;
background-color: #47c9e5;
max-width: 70px;
max-height: 70px;
}
.circle-number{
font-size: 45px;
color: white;
}
.vertical-center{
display: flex;
align-items: center;
justify-content: center;
}
.image-holder{
text-align: center;
}
li:last-child{
border-bottom: none;
}

Bootstrap Wordwrap issue on Mobile

I have a label (#linkDiv) which turns into a button once 'unlocked.' While as a label, the text is longer than the button, so it needs to wrap. I already did white-space:normal; word-wrap: break-word; word-break: normal;
That works for wide and medium screens, but when testing on mobile screen sizes, the line awkwardly wraps the whole label to the next line.
(not enough rep to embed image:) http://i.imgur.com/DfCp6lw.jpg
Help!
html:
<div class="container">
<div class="row">
<div id="pickCoins" class="col-sm-4">
...(other code for coins, etc)...
<div id="buttonRow" class="row">
<div id="rulesDiv" class="col-sm-4 btn btn-primary">Rules</div>
<div id="exampleDiv" class="col-sm-4 btn btn-info">Examples</div>
<div id="linkDiv" class="col-sm-4 label label-warning">
Unlock theory link in <span class="badge" id="unlockLink">5</span>
</div>
</div>
</div>
</div>
</div>
css:
#buttonRow div.col-sm-4 {
width:30%;
margin:0 1%;
white-space:normal;
word-wrap: break-word;
word-break: normal;
}
try this instead
HTML
<div class="container">
<div class="row">
<div id="pickCoins" class="col-sm-4">
...(other code for coins, etc)...
<div id="buttonRow" class="row">
<div id="rulesDiv" class="col-xs-4 btn btn-primary">Rules</div>
<div id="exampleDiv" class="col-xs-4 btn btn-info">Examples</div>
<div id="linkDiv" class="col-xs-4 label label-warning">
Unlock theory link in <span class="badge" id="unlockLink">5</span>
</div>
</div>
</div>
</div>
</div>
CSS
#buttonRow div.col-xs-4 {
width: 30%;
margin: 1.5%;
white-space: normal;
word-wrap: break-word;
word-break: normal;
}

Resources