Bootstrap Wordwrap issue on Mobile - css

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;
}

Related

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

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

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.

How does Bootstrap Pull and push work

I am trying to fix a page which wasn't bootstrapped like the illustration. But my col-2, col-3, col-4 don't align with the col 1 and 2. I cannot really understand how pull and push work. I have worked on my mobile layout and it seem fine, but as it goes to desktop, it messing the layout.
My layout becomes this, when I make it go desktop. Misaligned headings and columns under it.
You need to include yellow div-s into row so they won't jump over next line.
.left-box {
height: 290px;
width: 100%;
background: #e66;
margin: 3px;
}
.right-box {
height: 70px;
background: #ee6;
margin: 3px;
}
#media screen and (min-width: 992px) {
.left-box, .right-box {
height: 200px;
}
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="col-md-2 col-xs-5">
<div class="left-box"></div>
</div>
<div class="col-md-10 col-xs-7">
<div class="row">
<div class="col-md-3"><div class="right-box"></div></div>
<div class="col-md-3"><div class="right-box"></div></div>
<div class="col-md-3"><div class="right-box"></div></div>
<div class="col-md-3"><div class="right-box"></div></div>
</div>
</div>
</div>
</div>
Note: according to bootstrap rules, the statement class="col-md-2 col-sm-5" is the same that class="col-lg-2 col-md-2 col-sm-5 col-xs-12".
Actually you don't need push-pull classes I think. You could use a markup like this:
<div class="container">
<div class="row">
<div class="col-md-6">
<div class="left-box"></div>
</div>
<div class="col-md-6">
<div class="right-box"></div>
<div class="right-box"></div>
<div class="right-box">etc...</div>
</div>
</div>
</div>
Pen: http://codepen.io/anon/pen/yVKgwG

Why do browser prefixes for text-align have different behaviour and which is correct?

I want to vertically centre <div> tags that have a horizontal margin between each other.
The problem is that this behavior appears to be inconsistent between text-align: center and text-align: -webkit-center or text-align: -moz-center:
.parent {
display: inline-block;
border: 1px dotted #fd0;
position: relative;
}
.parent.ta {
text-align: center;
}
.parent.browser-ta {
text-align: -webkit-center;
text-align: -moz-center;
}
.child {
display: inline-block;
vertical-align: top;
}
.child > .content {
display: block;
margin: 0 10px;
border: 1px solid #888;
width: 200px;
text-align: left;
}
.wrong {
background-color: #e00;
color: #fff;
}
.right {
background-color: #0a3;
color: #fff;
}
<div>
Using <tt>text-align: center</tt>;
<div class="parent ta">
<div class="child">
<div class="content wrong">child 1 LEFT</div>
<div class="parent ta">
<div class="child">
<div class="content">child a</div>
</div>
<div class="child">
<div class="content">child b</div>
</div>
<div class="child">
<div class="content">child c</div>
</div>
</div>
</div>
<div class="child">
<div class="content wrong">child 2 LEFT</div>
<div class="parent ta">
<div class="child">
<div class="content">child d</div>
</div>
<div class="child">
<div class="content">child e</div>
</div>
<div class="child">
<div class="content">child f</div>
</div>
</div>
</div>
<div class="child ">
<div class="content right">child 3 CENTRE</div>
</div>
</div>
</div>
<br>
<br>
<div>
Using <tt>text-align: -vendor-center</tt>
<div class="parent browser-ta">
<div class="child">
<div class="content right">child 1 CENTRE</div>
<div class="parent browser-ta">
<div class="child">
<div class="content">child a</div>
</div>
<div class="child">
<div class="content">child b</div>
</div>
<div class="child">
<div class="content">child c</div>
</div>
</div>
</div>
<div class="child">
<div class="content right">child 2 CENTRE</div>
<div class="parent browser-ta">
<div class="child">
<div class="content">child d</div>
</div>
<div class="child">
<div class="content">child e</div>
</div>
<div class="child">
<div class="content">child f</div>
</div>
</div>
</div>
<div class="child">
<div class="content right">child 3 CENTRE</div>
</div>
</div>
Run that snippet and the two similar HTML and CSS produce different layouts in Chrome (Webkit/Blink) and FireFox. The red panels are in the wrong location, the green ones are correct.
So text-align: -webkit-center and text-align: -moz-center appear to be correct (to me) but text-align: center appears to be bugged in both browsers.
Digging out the venerable old <centre> tag (that we're not supposed to use) and that works right too (though examining it reveals it uses the browser prefix too).
Is this correct? Is this a bug? Is there a reason for the difference? Which one should I use?
The prefixed values are described by MDN to be "block alignment values", which means block boxes themselves are aligned in addition to the inline content within them. This is the exact behavior of the <center> element, and the prefixed values are in fact intended for that element — if you look in the UA stylesheets for each engine you'll find a ruleset that says exactly center { display: block; text-align: -vendor-center; }.
The reason text-align: center is not implemented this way is because text-align is designed to affect inline-level boxes (as evidenced by the "text-" in its name), not block-level boxes. But that, I suspect, is not the answer you're really looking for.
What's happening is that the boxes that are actually being aligned in your snippet are the .content elements, which are block boxes, not inline-blocks. The reason that last element is being centred is because its parent, an inline-block, is being shrink-wrapped, and itself then centred by the text-align: center declaration in its ancestor.

bootstrap CSS: center any col- that overflows a line

As can be seen in this fiddle, I have series of columns that are nested in a single row and designed to overflow onto as many new lines as necessary.
Since each col-* has the property align: left; from Bootstrap, cols that overflow onto a new line stay left aligned.
Visually, I'd like to have "incomplete" lines have divs that are centered, like this fiddle. But, these col- divs are created dynamically, so I can't just use offsets or additional rows to fix.
Any ideas on how to accomplish this? Thanks in advance.
Very easy. First, you change your HTML and add some special class just to make sure you don't affect the columns in other places of your layout. Since you have app-style, let's use that for the row, and let's add the myCentre class name to the xs-4 columns. Like this:
<div class="row app-style">
<div class="col-xs-4 myCentre">
<div class="box-btn-reports">
<p>1</p>
</div>
</div>
<div class="col-xs-4 myCentre">
<div class="box-btn-reports">
<p>2</p>
</div>
</div>
<div class="col-xs-4 myCentre">
<div class="box-btn-reports">
<p>3</p>
</div>
</div>
<div class="col-xs-4 myCentre">
<div class="box-btn-reports">
<p>4</p>
</div>
</div>
</div>
<div class="row app-style">
<div class="col-xs-4 myCentre">
<div class="box-btn-reports">
<p>1</p>
</div>
</div>
<div class="col-xs-4 myCentre">
<div class="box-btn-reports">
<p>2</p>
</div>
</div>
<div class="col-xs-4 myCentre">
<div class="box-btn-reports">
<p>3</p>
</div>
</div>
<div class="col-xs-4 myCentre">
<div class="box-btn-reports">
<p>4</p>
</div>
</div>
<div class="col-xs-4 myCentre">
<div class="box-btn-reports">
<p>Another col just because I can</p>
</div>
</div>
</div>
Now, we can use some extremely simple CSS. Basically, we're removing Bootstrap styles to use old school responsive approach: text-align:center for container, text-align:left for item elements, nothing new:
.app-style{text-align:center;}
.myCentre{display:inline-block;
float:none;
text-align:left;
margin-right:-4px;
vertical-align:top;}
.box-btn-reports {
text-align: center;
width: 100%;
margin-top: .5em;
margin-bottom: .5em;
border: 1px solid #888888;
border-radius: 8px;}
p {
padding: .1em;
font-size: 1.25em;
line-height: 150%;
}
and now you can [see the fiddle here] and how those columns are happily centered1

Resources