CSS 2 columns layout with 2 fixed height images - html

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>

Related

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.

How to split a column containing two divs on top of each other to the div's being side by side on smaller screen size

I'm fairly inexperienced in CSS, HTML and bootstrap.
Basically I would like to know how to split a single column on a large screen, into two columns on smaller screen so that the columns two div's sit side by side instead of on top of each other when the window is resized.
<div class= "container-fluid">
<div class ="row">
<div class="col-xl-9 col-lg-9 col-md-12 col-sm-12 col-12">
<canvas width="800" height="450">
</canvas>
</div>
<div class="col-xl-3 col-lg-3 col-md-12 col-sm-12 col-12">
<div id="Pseudo">
</div>
<div id="Element">
</div>
</div>
</div>
</div>
I want the Pseudo and element divs to sit next to each other on smaller devices and on top of each other on larger. Its working fine on a large screen.
I'm not sure if I can do that using bootstrap, I have been trying for a long time but having no luck.
You need to define single columns for your element, because defining the external column for both of them is not going to give you the result you are looking for. So, I think that something like this could do the trick:
#Pseudo {
background-color: red;
}
#Element {
background-color: green;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.bundle.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class= "container-fluid">
<div class ="row">
<div class="col-xl-9 col-lg-9 col-md-12 col-sm-12 col-9 ">
<canvas width="800" height="450">
</canvas>
</div>
<div class="col-xl-9 col-lg-3 col-md-12 col-sm-12 col-3">
<div class="row">
<div class="col-6 col-sm-6 col-md-6 col-lg-12 col-xl-12" id="Pseudo">
x
</div>
<div class="col-6 col-sm-6 col-md-6 col-lg-12 col-xl-12" id="Element">
y
</div>
</div>
</div>
</div>
</div>
From your code you are not doing anything to make the Pseudo and element divs dynamic.
It's funny because what you are trying to achieve is correct from the perspective of:
<canvas width="800" height="450">
</canvas>
and
<div id="Pseudo">
</div>
<div id="Element">
</div>
These two parts are dynamic. So the same way you implemented this for them you should implement for these divs.
Something like this:
<div class ="row">
<div class="col-xl-3 col-lg-3 col-md-12 col-sm-12 col-12">
<div id="Pseudo">
</div>
</div>
<div class="col-xl-3 col-lg-3 col-md-12 col-sm-12 col-12">
<div id="Element">
</div>
</div>
</div>
And you don't have to worry about the others. Bootstrap accepts nested rows.

div alignment on different screens

How can I achive this behaviour on different screens. (Grey rectangles are divs with some content). Assuming, picture 1 (left) is normal, wide screen; picture 2 (middle) is small (netbook or tablet) screen; picture 3 (right) is mobile screen. I use bootstrap 3.
You could use the offset column and column ordering classes. Making sure to apply each at the appropriate screen/grid size.
#import url('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css');
div[class^="col-"] > div {
margin: 1rem 0;
min-height: 100px;
background-color: yellow;
}
<div class="container-fluid">
<div class="row">
<div class="col-sm-6 col-sm-offset-3 col-md-4 col-md-offset-0 col-md-push-4">
<div>2</div>
</div>
<div class="col-sm-6 col-md-4 col-md-pull-4">
<div>1</div>
</div>
<div class="col-sm-6 col-md-4">
<div>3</div>
</div>
</div>
</div>
Note: The extra DIV in the column DIVs is for illustrative purposes. Do whatever you need to do.
You just need to use pull push classes of bootstrap.also learn about col-*-offset-* classes.
To learn more check this site:
Twitter bootstrap official docs
This is an example how you can do it
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<div class="row">
<div class="col-xs-12 col-md-12 col-lg-4 col-lg-push-4" style="height: 100px; background-color: red;">
2
</div>
<div class="col-xs-12 col-md-6 col-lg-4 col-lg-pull-4" style="height: 100px; background-color: blue;">
1
</div>
<div class="col-xs-12 col-md-6 col-lg-4" style="height: 100px; background-color: green;">
3
</div>
</div>
<div class="row">
<div class="col-xs-12 col-sm-6 col-sm-offset-3 col-md-4 col-md-offset-0 col-md-push-4">2</div>
<div class="col-xs-12 col-sm-6 col-md-4 col-md-pull-4">1</div>
<div class="col-xs-12 col-sm-6 col-md-4">3</div>
</div>

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>

How to keep collapsed Bootstrap columns centered

I am trying to keep some Bootstrap columns centered when the columns wrap around when the screen is shrunk.
My code looks like this:
<div class="container">
<div class="row">
<div class="col-md-2">
</div>
<div class="col-md-8 text-center">
<div style="font-size:36px;">Page Title</div>
</div>
<div class="col-md-2">
</div>
</div>
<div class="row text-center">
<div class="col-md-2">
</div>
<div class="col-md-2">
<div class="text-left" style="float:left;width:25%;">WWW</div>
</div>
<div class="col-md-2">
<div class="text-left" style="float:left;width:25%;">XXX</div>
</div>
<div class="col-md-2">
<div class="text-left" style="float:left;width:25%;">YYY</div>
</div>
<div class="col-md-2">
<div class="text-left" style="float:left;width:25%;">ZZZ</div>
</div>
<div class="col-md-2">
</div>
</div>
</div>
In the code above the 'Page Title' text stays centered horizontally on the screen as the screen width is reduced which is exactly what I want. I also want the four columns to stay centered horizontally when collapsed down to two columns and then when collapsed down to one column but the code above results in the columns being left aligned in the col-md-8 when wrapped. Is it possible to ensure that however the col-md-2 columns are wrapped they stay centered horizontally?
Your content is being left-aligned within their container divs by the class text-left. If you use the Bootstrap class text-center it will be centered.
Also regarding your column layout, I think you're working against the Bootstrap styles with those inline widths. I'd remove them and try using Bootstrap's own classes, like this:
<div class="container">
<div class="row">
<div class="col-md-2">
</div>
<div class="col-md-8 text-center">
<div style="font-size:36px;">Page Title</div>
</div>
<div class="col-md-2">
</div>
</div>
<div class="row text-center">
<div class="col-xs-12 col-sm-6 col-md-2 text-center">???
</div>
<div class="col-xs-12 col-sm-6 col-md-2">
<div class="text-center">WWW</div>
</div>
<div class="col-xs-12 col-sm-6 col-md-2">
<div class="text-center">XXX</div>
</div>
<div class="col-xs-12 col-sm-6 col-md-2">
<div class="text-center">YYY</div>
</div>
<div class="col-xs-12 col-sm-6 col-md-2">
<div class="text-center">ZZZ</div>
</div>
<div class="col-xs-12 col-sm-6 col-md-2 text-center">???
</div>
</div>
</div>
This will give you full-width columns on each div at the "xs" size (extra small, or mobile), then at the "sm" size (small) they'll grow to be 50%, then at md (medium) they'll shrink to be 1/6th.
Here's a bootply for your reference: http://www.bootply.com/t9XqPsBOpB