Safari and bootstrap 4 flexbox error - html

Bootstrap 4 - Safari Version 10.1.2 display:table; and display:table-cell; vertical-align:center; not working on a 100% height div.
<div class="test-slider">
<div class="slide">
<div class="row no-gutters">
<div class="col-12 col-xs-12 col-sm-12 col-md-7 col-lg-7">
<img src=""/>
</div>
<div class="col-12 col-xs-12 col-sm-12 col-md-5 col-lg-5">
<div style="display:table; height:100%;">
<div style="display:table-cell; vertical-align: middle;">
<h2>Test center</h2>
<p>Should be centered</p>
</div>
</div>
</div>
</div>
</div>
</div>
If I render in chrome the height is inherited from the .test-slider class that has a fixed height whilst in safari it takes the contents height rather than filling the height of the div. Any ideas? I am using slick slider.

Well, currently I have Safari 11.0.1, but if I set the below stlye, it does center the text vertically to me.
.test-slider .row {
height: 500px;
}
Setting the height only to .test-slider is not enough, since the children do not know that they should fill in that height. The 100% height set on the "table" is calculated from the height of it's parent, the .col-md-5 div. Which, in your case does not know about the height of the .test-slider.
Other than that, please note that col-12 col-xs-12 col-sm-12 col-md-7 col-lg-7 is totally equivalent to simply writing col-md-7. The same stands for col-md-5 of course.
Also, instead of using tables, I would recommend to use the flexbox utility classes already available in Bootstrap. That makes the markup lighter. This is an example:
.test-slider .row {
height: 300px;
}
.test {
background-color: lightgray;
}
<div class="test-slider">
<div class="slide">
<div class="row no-gutters">
<div class="col-md-7">
<img src=""/>
</div>
<div class="test col-md-5 d-flex align-items-center">
<div>
<h2 class="mb-0">Test center</h2>
<p class="mb-0">Should be centered</p>
</div>
</div>
</div>
</div>
</div>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css">

Related

Bootstrap images in columns overlapping

I have been trying to get 3 images to be responsive using bootstrap columns. They seem to be responsive, but the problem is that the images overlap except for the last column which remains being normal.
<div class="row">
<div class="col-sm-2 offset-sm-3">
<img class="img-responsive" src="../assets/images/roy-creates-categories-02.png">
</div>
<div class="col-sm-2">
<img class="img-responsive" src="../assets/images/roy-creates-categories-02.png">
</div>
<div class="col-sm-2">
<img class="img-responsive" src="../assets/images/roy-creates-categories-02.png">
</div>
</div>
I would like all 3 columns to like the one all the way on the right.
I've tried adding class "img-responsive" & "img-fluid" and neither have worked.
I'm using bootstrap 4.0.
The images are overflowing their container. The image on the right is full height but it is overflowing its container. Using the bootstrap '.col-2' means that you are limiting the column widths based on the window width. You could use background css rules instead of img elements to ensure containment or coverage of images or you could just use .col-auto instead of .col-2 with .justify-content-center provided you have appropriately sized images.
All three examples are in the snippet.
.row {
min-height: 150px;
}
.col-auto {
background-color: green;
}
.col-sm-2 {
background-color: red;
}
.bg-image {
width: 100%;
height: 100%;
background-image: url("https://picsum.photos/100");
background-position: center;
background-size: contain;
background-repeat: no-repeat;
}
.bg-image.bg-image--cover {
background-size: cover;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<div class="row justify-content-center">
<div class="col-auto">
<img class="img-fluid" src="https://picsum.photos/100">
</div>
<div class="col-auto">
<img class="img-fluid" src="https://picsum.photos/100">
</div>
<div class="col-auto">
<img class="img-fluid" src="https://picsum.photos/100">
</div>
</div>
<div class="row">
<div class="col-sm-2 offset-sm-3">
<div class="bg-image"></div>
</div>
<div class="col-sm-2">
<div class="bg-image"></div>
</div>
<div class="col-sm-2">
<div class="bg-image"></div>
</div>
</div>
<div class="row">
<div class="col-sm-2 offset-sm-3">
<div class="bg-image bg-image--cover"></div>
</div>
<div class="col-sm-2">
<div class="bg-image bg-image--cover"></div>
</div>
<div class="col-sm-2">
<div class="bg-image bg-image--cover"></div>
</div>
</div>

CSS 2 columns layout with 2 fixed height images

I'm trying to achieve the result detailed in the images attached in the best way possible but for some reason I can't find any solution that ticks all the boxes.
Desktop version - The images' height is fixed to 600px, but the width must always keep the same aspect ratio on resize. Also, the left column with the heading, paragraphs and buttons is the one to be fluid first, but when it reaches its min-width, then the images column must start to resize.
On mobile, the order needs to change so that the buttons go underneath the images, but they still keep their aspect ratio between their width and height to fill the container.
I've tried using flex, grid, but the closest results I'd found was by using good-old display:inline-block, but that presents an issue when switching the order of blocks which can easily be fixed by using flex or grid. The images part is particularly tricky.
I think it can be achieved via bootstrap classes.
I have created a demo in the code snippet below using inbuilt bootstrap classes.
Hope it helps
.heading,.paragraph,.buttons{
border: 1px solid #000;
padding: 15px;
background: #ccc;
}
.img-div img{
height: 600px;
width: 100%;
}
#media (max-width:767px){
.img-div img{
height: 300px;
width: 100%;
}
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row">
<div class="col-lg-5 col-md-5 col-sm-12 col-12">
<div class="heading">
<h1>Heading</h1>
</div>
<div class="paragraph">
<h1>Paragraphs</h1>
<p>Paragraph Content</p>
</div>
<div class="buttons d-none d-sm-block">
<h1>Buttons</h1>
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-6 col-6">
<button class = "btn btn-primary">Button 1</button>
</div>
<div class="col-lg-6 col-md-6 col-sm-6 col-6">
<button class = "btn btn-primary">Button 2</button>
</div>
</div>
</div>
</div>
<div class="col-lg-7 col-md-7 col-sm-12 col-12">
<div class="row">
<div class="col-lg-8 col-md-8 col-sm-8 col-8">
<div class="img-div">
<img src="https://picsum.photos/500/600" height = "600" class = "img-responsive">
</div>
</div>
<div class="col-lg-4 col-md-4 col-sm-4 col-4">
<div class="img-div">
<img src="https://picsum.photos/500/600" height = "600" class = "img-responsive">
</div>
</div>
</div>
</div>
<div class="col-lg-12 col-md-12 col-sm-12 col-12 d-sm-none">
<div class="buttons ">
<h1>Buttons</h1>
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-6 col-6">
<button class = "btn btn-primary">Button 1</button>
</div>
<div class="col-lg-6 col-md-6 col-sm-6 col-6">
<button class = "btn btn-primary">Button 2</button>
</div>
</div>
</div>
</div>
</div>

Why is there a space between row's in bootstrap grid on mobile size?

Im wondering why do i have space between second text which is from first row and first text which is on second row? I find it annoying, why does it happen? Is there any way to fix it?
[IMG]http://i67.tinypic.com/2zhe0xg.jpg[/IMG]
This is how it looks on desktop:
[IMG]http://i65.tinypic.com/2eby5bs.png[/IMG]
HTML:
<div class="container-fluid">
<div class="row mt-5 mb-5 ml-3 mr-3">
<div class="col-lg-6 col-md-6 col-sm-6">
<div class="row">
<div class="col-lg-8 col-md-8 col-sm-8">
<img class="img-fluid img-thumbnail" src="https://static-assets-prod.epicgames.com/fortnite/static/webpack/8704d4d5ffd1c315ac8e2c805a585764.jpg">
</div>
<div class="col-lg-4 col-md-4 col-sm-4text">
<div class="b">
<p>Somethin ggoes here maybe</p>
</div>
</div>
</div>
</div>
<div class="col-lg-6 col-md-6 col-sm-6">
<div class="row">
<div class="col-lg-8 col-md-8 col-sm-8">
<img class="img-fluid img-thumbnail" src="https://static-assets-prod.epicgames.com/fortnite/static/webpack/8704d4d5ffd1c315ac8e2c805a585764.jpg">
</div>
<div class="col-lg-4 col-md-4 col-sm-4 text">
<div class="b">
<p>Something goes here maybe</p>
</div>
</div>
</div>
</div>
</div>
<div class="row mt-5 mb-5 ml-3 mr-3">
<div class="col-lg-6 col-md-6 col-sm-6">
<div class="row">
<div class="col-lg-8 col-md-8 col-sm-8">
<img class="img-fluid img-thumbnail" src="https://static-assets-prod.epicgames.com/fortnite/static/webpack/8704d4d5ffd1c315ac8e2c805a585764.jpg">
</div>
<div class="col-lg-4 col-md-4 col-sm-4 text">
<div class="b">
<p>Somethin ggoes here maybe</p>
</div>
</div>
</div>
</div>
<div class="col-lg-6 col-md-6 col-sm-6">
<div class="row">
<div class="col-lg-8 col-md-8 col-sm-8">
<img class="img-fluid img-thumbnail" src="https://static-assets-prod.epicgames.com/fortnite/static/webpack/8704d4d5ffd1c315ac8e2c805a585764.jpg">
</div>
<div class="col-lg-4 col-md-4 col-sm-4 text">
<div class="b">
<p>Something goes here maybe</p>
</div>
</div>
</div>
</div>
</div>
</div>
CSS:
.row > .text > .b {
display: -webkit-box;
height: 70%;
line-height: 1.3;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
overflow: hidden;
text-overflow: ellipsis;
}
I tried multiple solutions but couldnt get it to work
There are some styles you should definitely include in future questions so we can diagnose conflicts. For future reference, include any styles for classes you have assigned.
As far as what I can tell just from your code and screenshots, though, I'd say setting margin: 0; on your 2 divs in a media query for the affected breakpoint would work, but I'd also like to add a suggestion that will be a bit less messy for you using flexbox.
/* Make your container a flexbox */
.container {
display: flex;
}
/* Give flex grow value of 1 to keep all inner containers equal size */
.article {
flex: 1;
margin: 5px;
}
/* Sizing the image */
.article>img {
max-width: 400px;
}
.article>h1 {
font-size: 12px;
}
/* You could also just set the flex-direction to column, but displaying as block at the breakpoint will achieve the layout you're looking for on mobile. 500px is a trivial guess, use inspector to find the sweet spot */
#media (max-width:500px) {
.container {
display: block;
}
}
<div class="container">
<div class="article">
<img src="https://3bonlp1aiidtbao4s10xacvn-wpengine.netdna-ssl.com/wp-content/uploads/2018/05/epic-fortnite.jpg" />
<h1>
Something here maybe.
</h1>
</div>
<div class="article">
<img src="https://3bonlp1aiidtbao4s10xacvn-wpengine.netdna-ssl.com/wp-content/uploads/2018/05/epic-fortnite.jpg" />
<h1>
Something here maybe.
</h1>
</div>
</div>
<div class="container">
<div class="article">
<img src="https://3bonlp1aiidtbao4s10xacvn-wpengine.netdna-ssl.com/wp-content/uploads/2018/05/epic-fortnite.jpg" />
<h1>
Something here maybe.
</h1>
</div>
<div class="article">
<img src="https://3bonlp1aiidtbao4s10xacvn-wpengine.netdna-ssl.com/wp-content/uploads/2018/05/epic-fortnite.jpg" />
<h1>
Something here maybe.
</h1>
</div>
</div>
You can read up a bit more on flexbox in this CSS-Tricks article as well. If you're confused on anything here, feel free to comment and I'll try and answer the best I can. I've composed a fiddle here too so you can see how it responds when resizing.

Bootstrap 4 big margin in parent container

Okay, this is my 3rd question and hopefully the last one. I get some problems with my page layout that looked like this before:
[navbar]
[1][2][3]
I wanted to achieve this effect when resizing:
[navbar]
[2][3]
[1]
(1st div under the 3rd one)
However, when I use (in the main container that holds all the 3 divs) class container mt-3 I get this layout:
[navbar]
[1][2]
[3]
Now, when I change the margin-left of the 3rd div it doesn't go up to the top row but just moves to the left - something happens like it would be in another row class.
When I use parent-container container mt-3
[navbar]
[1][2] [3]
And they are really small and I can't change the width no matter what I do. I even tried changing the bootstrap's "container" class with both px and %.
container-fluid does the job a bit because all the divs are bigger (and on 100% width of the page) but I would want to have it just like 90%, but still, the [3] div is on the right side mile from the [2]. When I resize the window, the [2] div goes in this white space between [1] and [3] under the [3]. So it looks similar to this:
[navbar]
[2] [3]
[1]
CSS CODE:
.main{
background-color: red;
box-shadow: 3px 3px 20px #000000;
border-radius: 20px;
}
.left{
background-color: green;
max-width: 200px;
border-radius: 20px;
}
.right{
background-color: blue;
max-width: 200px;
border-radius: 20px;
}
.parent-container {
display: flex;
}
.right-content{
width: 100%;
text-align: center;
float: center;
margin-top: 10px;
}
HTML
<div class="parent-container container mt-3">
<div class="row">
<div class="left col-4 col-lg-3 order-last order-lg-first offset-8 offset-lg-0">
<div class="col-12 text-center" style="margin-bottom: 15px">
<h3>TITLE LEFT</h3>
</div>
</div>
<div class=" col-8 col-lg-6">
<div class="container card">
<div class="card-body">
<div class="row">
<div class="col-12 text-center">
<h2>TITLE CENTER</h2>
</div>
</div>
<div class="row">
<div class="col-12 text-center">
<h3>heading 3</h3>
<h6>heading 6</h6>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-12 mx-auto">
<a href="#" class="article-link">
<h3>Heading 3</h3>
<p>Text</p>
</a>
</div>
</div>
<hr>
</div>
</div>
<div class="right col-4 col-lg-3">
<div class="right-content">
<h2>TITLE RIGHT</h2>
</div>
</div>
</div>
You had improper nesting for the columns. Here's the right way to do it (all main columns must sit within the main row):
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<style>
.left{
background-color: green;
max-width: 200px;
border-radius: 20px;
}
.right{
background-color: blue;
max-width: 200px;
border-radius: 20px;
}
</style>
<div class="parent-container container mt-3">
<div class="row">
<div class="left col-4 col-lg-3 order-last order-lg-first offset-8 offset-lg-0">
<h3>TITLE LEFT</h3>
</div>
<div class=" col-8 col-lg-6">
<div class="container2 card">
<div class="card-body">
<div class="row">
<div class="col-12 text-center">
<h2>TITLE CENTER</h2>
</div>
</div>
<div class="row">
<div class="col-12 text-center">
<h3>heading 3</h3>
<h6>heading 6</h6>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-12 mx-auto">
<a href="#" class="article-link">
<h3>Heading 3</h3>
<p>Text</p>
</a>
</div>
</div>
<hr>
</div>
<div class="right col-4 col-lg-3">
<div class="right-content">
<h2>TITLE RIGHT</h2>
</div>
</div>
</div>
</div>
Note: Right now the columns aren't stacking on the smallest screens. That's because they aren't specified to do so. To make them stack, the responsive column classes for the smallest screens (col-*) all need to be changed to col-12.
You'd also need to adjust the offset classes because right now the offset-8 class kicks in for all screens that are smaller than lg. The offset-8 class is what causes the offset of 8 units (on the left) on all screens that are smaller than lg.

Twitter Bootstrap : vertically align child div with height

I am using Bootstrap v3.1.1 to design web app. I hav three divs in the middle div i have a small div and i need to place it vertically aligned.
Here is what i got so far.
<body>
<div class="row fill">
<div class="col-md-4 col-sm-3 col-xs-1 fill" style="background-color:red;">
</div>
<div class="col-md-4 col-sm-6 col-xs-10 parent" style="background-color:blue;">
<div class="child"></div>
</div>
<div class="col-md-4 col-sm-3 col-xs-1 fill" style="background-color:green;">
</div>
</div>
</body>
I couldn't place the child div vertically aligned. I tried following css.
.parent {
display:table;
height:100%;
display:table;table-layout:fixed;
}
.child {
vertical-align:middle;
text-align:center;
border:2px solid gray;
height:40%;
}
Someone please help,
Thanks.
So your problem was you wanted to vertically center-align a child div whose height was 40% but since you had given it as display:table-cell, it behaves like a <td> element and ignores the height.
The solution is to place that child div in another container and apply the display:table-cell and vertical-align:middle to that container:
<div class="row fill">
<div class="col-md-4 col-sm-3 col-xs-1 fill" style="background-color:red;">
</div>
<div class="col-md-4 col-sm-6 col-xs-10 parent" style="background-color:blue;">
<!-- another container to vertical align the child div -->
<div class="center-child">
<div class="child">test</div>
</div>
</div>
<div class="col-md-4 col-sm-3 col-xs-1 fill" style="background-color:green;">
</div>
</div>
DEMO