Make Bootstrap Columns Stop Breaking on Mobile [duplicate] - html

This question already has answers here:
Bootstrap columns stacking vertically on mobile device
(2 answers)
Closed 4 years ago.
I'm trying to get content within a Bootstrap row to scale down rather than break into single columns on mobile. How would I go about this?
Here is an example of what I have so far:
<div class="row justify-content-center">
<div class="col-xs-4" style="padding:0!important;">
<a class="btn btn-light" style="width: 200px; height: 200px;>
<h2> title </h2>
<img src="" style="width:100px; height:100px;">
</a>
</div>
<div class="col-xs-4" style="padding:0!important;">
<a class="btn btn-light" style="width: 200px; height: 200px;>
<h2> title </h2>
<img src="" style="width:100px; height:100px;">
</a>
</div>
<div class="col-xs-4" style="padding:0!important;">
<a class="btn btn-light" style="width: 200px; height: 200px;>
<h2> title </h2>
<img src="" style="width:100px; height:100px;">
</a>
</div>
</div>
When I open this up on my phone, each column is displayed as a single line on the page. I'd like all three to be on the same row on mobile.

Bootstrap-4 has removed all the variants of *-xs-* classes.
col-xs- have been dropped in Bootstrap 4 in favor of col-.
So in order to have three equal width columns on all kinds of devices, use col-4 or just col instead of col-xs-4.
https://getbootstrap.com/docs/4.1/layout/grid/#grid-options
Use p-0 class instead of the inline padding style for the a tags.
https://getbootstrap.com/docs/4.0/utilities/spacing/
Use img-fluid class instead of the inline css style for the img elements to make it responsive.
https://getbootstrap.com/docs/4.0/content/images/#responsive-images
As you may know, mobile devices have less than 414px width. But the sum of the a tags' width is more than 414px. Therefore, you should use a max-width to set their maximum width and use width: 100% or w-100 also.
The max-width CSS property sets the maximum width of an element. It prevents the used value of the width property from becoming larger than the value specified by max-width. https://developer.mozilla.org/en-US/docs/Web/CSS/max-width
In this case, since the row has exactly 12 columns, it is unnecessary to use justify-content-center. Therefore, you better remove it.
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/css/bootstrap.min.css">
<div class="container">
<div class="row">
<div class="col-4 p-0">
<a class="btn btn-light" style="max-width: 200px; width:100%; height: 200px;">
<h2> title </h2>
<img src="http://via.placeholder.com/100" class="img-fluid">
</a>
</div>
<div class="col-4 p-0">
<a class="btn btn-light" style="max-width: 200px; width:100%; height: 200px;">
<h2> title </h2>
<img src="http://via.placeholder.com/100" class="img-fluid">
</a>
</div>
<div class="col-4 p-0">
<a class="btn btn-light" style="max-width: 200px; width:100%; height: 200px;">
<h2> title </h2>
<img src="http://via.placeholder.com/100" class="img-fluid">
</a>
</div>
</div>
</div>
https://codepen.io/anon/pen/djWZJj

You need to make changes in your col structure. Bootstrap 4 has changed the breakpoints.
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/css/bootstrap.min.css" rel="stylesheet" />
<div class="row justify-content-center">
<div class="col-4" style="padding:0!important;">
<a class="btn btn-light" style="width: 200px; height: 200px;">
<h2> title </h2>
<img src="" style="width:100px; height:100px;">
</a>
</div>
<div class="col-4" style="padding:0!important;">
<a class="btn btn-light" style="width: 200px; height: 200px;">
<h2> title </h2>
<img src="" style="width:100px; height:100px;">
</a>
</div>
<div class="col-4" style="padding:0!important;">
<a class="btn btn-light" style="width: 200px; height: 200px;">
<h2> title </h2>
<img src="" style="width:100px; height:100px;">
</a>
</div>
</div>

More than likely this has to do with height and width of the images your using. I would suggest just using a max-height and max-width and allow the images to scale to the screen size.
<div class="row justify-content-center">
<div class="col-xs-4" style="padding:0!important;">
<a class="btn btn-light" style="width: 200px; height: 200px;>
<h2> title </h2>
<img src="" style="max-width:100px; max-height:100px;">
</a>
</div>

Related

overflow-x hides content (and it cannot be overwritten)

I have used the following style inside the element of my html to get rid of the extra white space on the right side of the screen:
<style>
html,body{
width: 100%;
height: 100%;
margin: 0px;
padding: 0px;
overflow-x: hidden;
}
</style>
And it worked perfectly fine. However, it sets the visibility of some of the content on of the pages to be "hidden" and I have tried using the !important attribute to overwrite but no matter what I do, they remain invisible.
<div class="col-lg-3 col-md-6 wow fadeInUp" data-wow-delay="0.2s">
<div class="box">
<div class="icon"><a href=""><i>
<img class="featurette-image img-fluid mx-auto" data-src="holder.js/500x500/auto" src="/img/yusufImg/slope%20design.png" alt="Generic placeholder image">
</i></a></div>
<h4 class="title">Slope Design</h4>
<a id="slopeButton" class="btn btn-lg btn-outline-success" style="font-weight: 900;color: white;">Read More</a>
</div>
</div>
<div style=" visibility:visible !important;" class="col-lg-3 col-md-6 wow fadeInUp" data-wow-delay="0.2s">
<div class="box">
<div class="icon"><a href=""><i>
<img class="featurette-image img-fluid mx-auto" data-src="holder.js/500x500/auto" src="/img/yusufImg/taş%20duvar.png" alt="Generic placeholder image">
</i></a></div>
<h4 class="title">Tas Duvar</h4>
<a id="tasduvarButton" class="btn btn-lg btn-outline-
success" style="font-weight: 900;color: white;">Read More</a>
</div>
Ones with the inline style for visibility have the same exact attributes and classes as the ones that don't. However, they are always rendered to be invisible when I load the page.
How can I fix this?

3 Box grid not equal width as they change depending on text

I have a small bit of HTML in a word press post body which I have (want) 3 equal width boxes, except the third box is smaller if i have less text (or more in another box) and i cant figure out how to keep the sizes static.
I have tried adding CSS containers, adding physical widths but nothing changes.
Current Code:
<div>
<div class="page-content">
<div class="grid grid--thirds">
<div class="grid__item" data-match-height="login-block-container" display:block width: 33%;>
<a class="login_link" href="https://www.google.com">
<div class="login-block">
<h5 class="login-block__title">B1HEADERTEXT</h5>
<p>B1BODYTEXT</p>
</div>
</a>
</div>
<div class="grid__item" data-match-height="login-block-container" display:block width: 33%;>
<a class="login_link" href="https://www.google.com">
<div class="login-block">
<h5 class="login-block__title">B2HEADERTEXT</h5>
<p>B2BODYTEXT</p>
</div>
</a>
</div>
<div class="grid__item" data-match-height="login-block-container" display:block width: 33%;>
<a class="login_link" href="https://www.google.com">
<div class="login-block">
<h5 class="login-block__title">B3HEADERTEXT</h5>
<p>B3BPDYTEXT</p>
</div>
</a>
</div>
</div>
</div>
</div>
How it looks:
With differing amounts of text:
<div>
<div class="page-content">
<div class="grid grid--thirds">
<div class="grid__item" data-match-height="login-block-container" display:block width: 33%;>
<a class="login_link" href="https://www.google.com">
<div class="login-block">
<h5 class="login-block__title">B1HEADERTEXT</h5>
<p>B1BODYTEXT</p>
</div>
</a>
</div>
<div class="grid__item" data-match-height="login-block-container" display:block width: 33%;>
<a class="login_link" href="https://www.google.com">
<div class="login-block">
<h5 class="login-block__title">B2HEADERTEXT</h5>
<p>B2BODYTEXT</p>
</div>
</a>
</div>
<div class="grid__item" data-match-height="login-block-container" display:block width: 33%;>
<a class="login_link" href="https://www.google.com">
<div class="login-block">
<h5 class="login-block__title">B3HEAD</h5>
<p>B3BPDYTEXT</p>
</div>
</a>
</div>
</div>
</div>
</div>
How that looks:
Judging by the image you've posted, it seems as if the parent or parent container is behaving like a flex or grid or something similar.
If you don't want the content of each box to effect the width of any box, you can do this by applying the following code to each box.
.box {
width: calc(100% / 3);
word-wrap: break-word;
}

Issue aligning div's using width and float

So what I am trying to do is align these divs within a bootstrap card. My issue is, I am able to get the left half of it right, but I can't figure out how to align the far right elements. I am currently using width percentages to allow this to stay responsive, though I have one thing set as fixed due to pictures always being the same size.
<div class="card" style="width:65%;float:left;">
<h5 class="card-header">Window Latch Black (Small)</h5>
<div class="card-body clearfix text-center" style="width:100%;display:inline-block;background-color: aqua;">
<div class="cartimage" style="background-color:red;float:left">
<img class="rounded-circle" src="data:image/gif;base64,R0lGODlhAQABAIAAAHd3dwAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" alt="Generic placeholder image" width="140" height="140">
</div>
<div class="carttext" style="height:50%;width:75%;background-color:green;">
khjg
</div>
<div class="cartamt" style="height:50%;width:75%;background-color:yellow;">
amt
</div>
<div class="cartprice" style="height:50%;width:15%;background-color:purple;float:right">
price
</div>
<div class="cartbutton" style="height:50%;width:15%;background-color:pink;float:right">
button
</div>
</div>
</div>
You need to adjust the order and replace 15% with 25% to have a total of 100% per row. You need to also set a height to parent container to use % height with child element:
.rounded-circle {
border-radius:50%;
vertical-align:top;
}
<div class="card" style="width:65%;float:left;">
<h5 class="card-header">Window Latch Black (Small)</h5>
<div class="card-body clearfix text-center" style="width:100%;display:inline-block;background-color: aqua;height:140px">
<div class="cartimage" style="background-color:red;float:left">
<img class="rounded-circle" src="data:image/gif;base64,R0lGODlhAQABAIAAAHd3dwAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" alt="Generic placeholder image" width="140" height="140">
</div>
<div class="cartprice" style="height:50%;width:25%;background-color:purple;float:right">
price
</div>
<div class="carttext" style="height:50%;width:75%;background-color:green;">
khjg
</div>
<div class="cartbutton" style="height:50%;width:25%;background-color:pink;float:right">
button
</div>
<div class="cartamt" style="height:50%;width:75%;background-color:yellow;">
amt
</div>
</div>
</div>
By the way, since you are using Bootstrap V4 you can rely on flex to create your layout:
.rounded-circle {
border-radius: 50%;
vertical-align: top;
}
.cartprice {
background: red;
flex-basis: 75%;
}
.carttext {
background: green;
flex-basis: 25%;
}
.cartbutton {
background: blue;
flex-basis: 75%;
}
.cartamt {
background: yellow;
flex-basis: 25%;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="card">
<h5 class="card-header">Window Latch Black (Small)</h5>
<div class="card-body text-center d-flex">
<div class="cartimage">
<img class="rounded-circle" src="data:image/gif;base64,R0lGODlhAQABAIAAAHd3dwAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" alt="Generic placeholder image" width="140" height="140">
</div>
<div class="d-flex flex-wrap w-100" >
<div class="cartprice">
price
</div>
<div class="carttext">
khjg
</div>
<div class="cartbutton">
button
</div>
<div class="cartamt">
amt
</div>
</div>
</div>
</div>
If you are using bootstrap4, I don't understand why using float...Use boostartp4 [Flex Utilities] classes instead to make these type of grid layout...Also for good practice try to wrap your divs into a wrapper divs
Stack Snippet
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="card">
<h5 class="card-header">Window Latch Black (Small)</h5>
<div class="card-body text-center p-0 d-flex no-gutters" style="background-color: aqua;">
<div class="cartimage" style="background-color:red;">
<img class="rounded-circle" src="data:image/gif;base64,R0lGODlhAQABAIAAAHd3dwAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" alt="Generic placeholder image" width="140" height="140">
</div>
<div class="d-flex flex-column" style="flex: 2;">
<div class="carttext col" style="background-color:green;">
khjg
</div>
<div class="cartamt col" style="background-color:yellow;">
amt
</div>
</div>
<div class="d-flex flex-column col">
<div class="cartprice col" style="background-color:purple">
price
</div>
<div class="cartbutton col" style="background-color:pink">
button
</div>
</div>
</div>
</div>

Bootstrap css Aligns the text to the center by the text length of the other div

I want to use css, bootstrap to align the first line align left, and the second line will center on the text length of the first line.
I tried many ways but not.
code follow
<div class="col-md-6">
<a href="/" style="text-decoration:none">
<div class="col-md-12 row-eq-height" style="padding:0;">
<div class="col-md-2" style="padding:0">
<img src="/Content/images/logo.png" class="img-responsive" alt="">
</div>
<div class="col-md-10 tex-center" style="padding-right:0;">
<div style="padding:0">
<div class="line1-bold">THIS IS THE FIRST LONG HEADLINE</div>
<div class="line2">THIS IS THE SECOND HEADLINE</div>
</div>
</div>
</div>
</a>
</div>
Please check this..
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<div class="col-md-6">
<a href="/" style="text-decoration:none">
<div class="col-md-12 row-eq-height" style="padding:0;">
<div class="col-xs-2" style="padding:0">
<img src="https://www.tenforums.com/attachments/browsers-email/18558d1485951187t-microsoft-edge-logo-microsoft-edge-100582336-large.png" class="img-responsive" style="width:100px" alt="">
</div>
<div class="" style="float:left;">
<div class="line1-bold" style="color:#b63957; font-size:18px;">THIS IS THE FIRST LONG HEADLINE</div>
<div class="line2" style="color:#b63957; font-size:16px; text-align:center;">THIS IS THE SECOND HEADLINE</div>
</div>
</div>
</a>
</div>
Try adding the class text-center to your divs.
Here is a working pen.
Something like this?
I don't know about your task, but I deleted some tags.
CSS
.img-responsive {
width: 100px;
float: left;
}
span {
display: block;
}
HTML
<div class="col-md-6">
<a href="/" style="text-decoration:none">
<div class="col-md-12 row-eq-height" style="padding:0;">
<img src="https://www.tenforums.com/attachments/browsers-email/18558d1485951187t-microsoft-edge-logo-microsoft-edge-100582336-large.png" class="img-responsive" alt="">
<span class="text-left">THIS IS THE FIRST LONG HEADLINE</span>
<span class="text-center">THIS IS THE SECOND HEADLINE</span>
</div>
</a>
</div>
Reference Link

How to make same height of all responsive images in a row

The first image of the row doesn't have the same height as the other ones. I am using Bootstrap .img-responsive.
HTML
<div class="row">
<div class="down-content">
<div class="haber">
<!--HABER 1-->
<div class="col-sm-3">
<div id="haber1">
<div id="haberimg1">
<img class="img-responsive" src="http://www.avukatwebsite.net/public/_uploads/photos/temalar/avukat-web-site-tema-1.jpg" >
</div>
<div id="haberyazi1">
<h3>Kanser Affetmedi...</h3>
<p>Sanssiz genc Kanser yüzünden öldü...</p>
<button type="button" class="btn">Devamini Oku...</button>
</div>
</div>
</div>
<!--HABER 2-->
<div class="col-sm-3">
<div id="haber2">
<div id="haberimg2">
<img class="img-responsive" src="http://medicare.bold-themes.com/clinic/wp-content/uploads/sites/2/2015/12/shutterstock_288977717-1200x800.jpg" >
</div>
<div id="haberyazi2">
<h3>Sizofreni Salgini</h3>
<p>Türkiyede ki Sizofren sayisinda artis görüldü...</p>
<button type="button" class="btn">Devamini Oku...</button>
</div>
</div>
</div>
/* we deleted the other parts because of mostly code problem */
</div>
<!--HABER BÖLÜMÜ BITIS-->
</div>
</div>
Bootstrap CSS
.img-responsive,
.thumbnail > img,
.thumbnail a > img,
.carousel-inner > .item > img,
.carousel-inner > .item > a > img {
display: block;
max-width: 100%;
height: auto;
}
This is the issue:
There are a number of solutions. Here is a couple of similar solutions. First you would need to create a div that scales responsively. This can be achieved with:
.img-wrap {
height:0;
// adjust the padding to change the aspect ratio of the div
padding-bottom:60%;
}
you can then either add a background image to the .image-wrap element with background-size:cover. Or you could place an image inside .image-wrap and then position:absolute; it inside .image-wrap and add object-fit: cover; width: 100%; height: 100%;.
Answer 1:
You have to set a fixed height to the img parent div and then set height:100% to the img Check below Snippet:
.haberImg {
height: 75px;
}
.haberImg img {
height: 100%;
width: 100%;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<div class="row">
<div class="down-content">
<div class="haber">
<!--HABER 1-->
<div class="col-xs-3">
<div id="haber1">
<div id="haberimg1" class="haberImg">
<img class="img-responsive" src="http://www.avukatwebsite.net/public/_uploads/photos/temalar/avukat-web-site-tema-1.jpg"></div>
<div id="haberyazi1">
<h3>Kanser Affetmedi...</h3>
<p>Sanssiz genc Kanser yüzünden öldü...</p>
<button type="button" class="btn">Devamini Oku...</button>
</div>
</div>
</div>
<!--HABER 2-->
<div class="col-xs-3">
<div id="haber2">
<div id="haberimg2" class="haberImg">
<img class="img-responsive" src="http://medicare.bold-themes.com/clinic/wp-content/uploads/sites/2/2015/12/shutterstock_288977717-1200x800.jpg"></div>
<div id="haberyazi2">
<h3>Sizofreni Salgini</h3>
<p>Türkiyede ki Sizofren sayisinda artis görüldü...</p>
<button type="button" class="btn">Devamini Oku...</button>
</div>
</div>
</div>
</div>
</div>
Answer 2:
You have to set a fixed height to the img parent div as the smallest img height and then add overflow:hidden. Check below Snippet:
.haberImg {
height: 80px;
overflow:hidden;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<div class="row">
<div class="down-content">
<div class="haber">
<!--HABER 1-->
<div class="col-xs-3">
<div id="haber1">
<div id="haberimg1" class="haberImg">
<img class="img-responsive" src="http://www.avukatwebsite.net/public/_uploads/photos/temalar/avukat-web-site-tema-1.jpg"></div>
<div id="haberyazi1">
<h3>Kanser Affetmedi...</h3>
<p>Sanssiz genc Kanser yüzünden öldü...</p>
<button type="button" class="btn">Devamini Oku...</button>
</div>
</div>
</div>
<!--HABER 2-->
<div class="col-xs-3">
<div id="haber2">
<div id="haberimg2" class="haberImg">
<img class="img-responsive" src="http://medicare.bold-themes.com/clinic/wp-content/uploads/sites/2/2015/12/shutterstock_288977717-1200x800.jpg"></div>
<div id="haberyazi2">
<h3>Sizofreni Salgini</h3>
<p>Türkiyede ki Sizofren sayisinda artis görüldü...</p>
<button type="button" class="btn">Devamini Oku...</button>
</div>
</div>
</div>
</div>
</div>
A simple way is to use images that have the same width and the same height! (You avoid a lot of problems and there is no need to fix something with CSS)
HTML
<div class="row">
<div class="col-sm-3">
<img src="http://placehold.it/400x300" alt="" class="img-responsive">
<h3>Heading</h3>
<p>Text</p>
<button class="btn">More</button>
</div>
<div class="col-sm-3">
<img src="http://placehold.it/400x300" alt="" class="img-responsive">
<h3>Heading</h3>
<p>Text</p>
<button class="btn">More</button>
</div>
<div class="col-sm-3">
<img src="http://placehold.it/400x300" alt="" class="img-responsive">
<h3>Heading</h3>
<p>Text</p>
<button class="btn">More</button>
</div>
<div class="col-sm-3">
<img src="http://placehold.it/400x300" alt="" class="img-responsive">
<h3>Heading</h3>
<p>Text</p>
<button class="btn">More</button>
</div>
</div>
Just give your images same class and add height.
Trick: avoid of giving height with pixels because getting issue in small screen instead give height with rem or
percentage
It's very easy actually, use display grid and grid-auto-columns: 1fr.