Fixed size but responsive cards boostrap3 - css

I want to make my cards have fixed size, but they fit all types of screens.
Currently they are fixed size, but on smaller screens they are getting one over the other, I want them to fit on the screens.
1920x1080px:
Here is correct, but on screens larger than this, there could be more cards per line.
1366x768px:
Here it is wrong, it can be only 3 per line.
<div class="row">
<section class="catalogos">
<div class="catalogo">
<div class="col-lg 3 col-md-3 col-sm-12 col-xs-12" ng-repeat="sistema in $ctrl.sistemasFavoritos | filter:search">
<div class="panel catalogo-item">
<div class="media-left media-middle">
<div class="catalogo-item-icone-conteudo">
{{ sistema.nome.substring(0, 1) | uppercase}}
</div>
</div>
<div class="media-body">
<h4 class="media-heading">
{{sistema.nome | uppercase}}
</h4>
<p>{{sistema.descricao}}</p>
</div>
<div class="media-right">
<a ng-click="$ctrl.removeFavorito(sistema)" class="fa fa-star yellow"></a>
</div>
</div>
</div>
</div>
</section>
</div>
css:
.catalogo-item {
height: 100%;
width:100%;
max-width: 380px;
max-height: 125px;
min-width: 380px;
min-height: 125px;
padding: 10px;
}

<div class="catalogo">
<div class="row">
<div class="col-lg-2 col-md-3 col-sm-6 col-xs-12" ng-repeat="sistema in $ctrl.sistemasFavoritos | filter:search">
<div class="panel catalogo-item">
<!-- card contents -->
</div>
</div>
[...]
<div class="col-lg-2 col-md-3 col-sm-6 col-xs-12" ng-repeat="sistema in $ctrl.sistemasFavoritos | filter:search">
<div class="panel catalogo-item">
<!-- card contents -->
</div>
</div>
[...]
</div>
</div>
You don't need the CSS you added. The width:100% and max-width and min-width would conflict. Bootstraps .panels are 100% wide by default.
You had .col-lg 3 which has to be .col-lg-3. I changed it to .col-lg-2 so it will fit 6 'cards' in a row on very large screens.
Next you'll have to put the columns directly inside a .row for them to work properly. If the heights of the cards are not the same you might want to divide them in different .rows so float will not cause chaos. (but this will be tricky since you'll need to render different html depending on screensize).
TIP: Bootstrap 4 now supports flex box which would make it less difficult to get what you want.

Related

Third element ends up in new line in Safari

I have a simple Bootstrap layout:
<div class="row">
<div class="footer_column col-md-4">
<div class="footer_item">
ABOUT
</div>
<div class="footer_item">
Contact Us
</div>
<div class="footer_item">
Terms & Conditions
</div>
<div class="footer_item">
Privacy Policy
</div>
</div>
<div class="footer_column col-md-4">
<div class="footer_item">
SITE RESOURCES
</div>
<div class="footer_item">
General Rules
</div>
<div class="footer_item">
Scoring
</div>
<div class="footer_item">
Game Coins
</div>
<div class="footer_item">
<a class="store-show">Store</a>
</div>
<div class="footer_item">
Account Types
</div>
</div>
<div class="footer_column col-md-4">
<div class="footer_item">
MORE FANTASY FOOTBALL
</div>
<div class="footer_item">
<div class="footer_item">
Fantasy Game
</div>
</div>
</div>
</div>
In Chrome and Firefox it looks like it's supposed to (a 3 column layout):
But in Safari the 3rd column ends up in a new line below the other. When I inspect it, it has the correct width (exactly 1/3 of the total row width) in both Chrome and Safari.
I am seeing this when I inspect the element:
.col-md-4 {
flex: 0 0 33.3333333333%;
max-width: 33.3333333333%;
}
When I remove the max-width attribute, each column spreads out to 100%. This is expected I suppose. But when I add width: 20% for example, the width of each column remains the same as it was!
How can I make Safari behave?
If you're using a container around the row then add a helper class to remove the before content.
<div class="container before-fix"><!-- content --></div>
.before-fix::before {
content: none;
}
I fixed this here. The problem was the flex was overriding the default width.
This is what the CSS is now:
.col-md-4 {
flex: none;
max-width: 33.3333333333%;
width: 20%;
}
It successfully sets the width of the columns to 20% instead of 33.3%.
Here's a really clean way using grid instead of bootstrap...
.three-columns {
display: grid;
grid-template: 1fr 1fr 1fr;
}
<div class="three-columns">
<div>column 1</div>
<div>column 2</div>
<div>column 3</div>
</div>

Bootstrap : Add a junction between div

I'm trying to add a junction (a line) between 2 divs in the middle.
<div class="row">
<div class="col-xs-6 col-md-6">
<div style="background-color:#f39a6f;width:100%;height:100px;">
....1
</div>
</div>
<div class="col-xs-6 col-md-6">
<div style="background-color:#ffff00;width:100%;height:100px;">
....2
</div>
</div>
Thanks for help.
Hope this code will solve your problem.
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<div class="row no-gutters">
<div class="col-md-3">
<div class="card bg-success">
<div class="card-body"></div>
</div>
</div>
<div class="col-md-2">
<hr>
</div>
<div class="col-md-3">
<div class="card bg-danger">
<div class="card-body"></div>
</div>
</div>
</div>
My idea is to have the junction (a line) always be the center of a row via absolute/relative positioning, with lower z-index than what those color blocks have so that the line is hidden behind the blocks but shown between the blocks.
The tricky part is accurately calculate the position of the junction line, due to the fact that bootstrap rows have their own paddings. That's why it's better to use SCSS so that you can read bootstrap default values for row and column settings, and calculate the junction line based on those.
But for demo purpose, I will stick with CSS and "hardcode" the pre-configured values from bootstrap.
HTML Structure
<div class="row junction-row">
<div class="col-6 col-sm-3">
<div class="block bg-primary"></div>
</div>
</div class="col-6 col-sm-4 offset-sm-5">
<div class="block bg-danger"></div>
</div>
</div>
CSS
.junction-row {
height: 6rem;
position: relative;
}
.junction-row::after {
content: '';
position: absolute;
background-color: var(--danger);
height: 5%;
// Default bootstrap row's padding is 1rem.
// Width = 100% - left padding of the row - right padding of the row
width: calc(100% - 2rem);
// Top = total height 100% - the height of the line, and then divide by 2
// to have the line stay in the center of the row.
top: calc((100% - 5%) / 2);
// Left = starting after the row's left padding
left: 1rem;
// Any value here, but it needs to be lower than what .block has
z-index: 1;
}
.block {
position: relative;
height: 6rem;
z-index: 2;
}
Result
demo: https://jsfiddle.net/davidliang2008/vknor3cz/32/
I don't believe you can have this and have your column sizes at 6 each. I can think of 2 ways. Make them 5 and use this. This comes from their documentation on the grid system.
https://getbootstrap.com/docs/4.0/layout/grid/
<div class="row justify-content-between">
<div class="col-5">
One of two columns
</div>
<div class="col-5">
One of two columns
</div>
</div>
Or if you don't mind that junction being static width then you could do this. Effectively making the junction width static and each side equal in the remaining width.
<div class="row">
<div class="col">
1 of 2
</div>
<div class="col-auto" style="width:30px"></div>
<div class="col">
2 of 2
</div>
</div>

Get divs next to each other, with same height, in md, lg and xl devices and get divs in block in smaller devices

Im using bootstrap and I want that in medium, large and extra large devices get the first layout of the image below, where there is a image at the left and then some information at right. And these 2 areas (the image and the informations div) occupy the full .container div width and have always the same height.
Then in smaller devices I want to get the layout in the image below, where the image is above and the informations below.
Image to demonstrate the layout that Im trying to get:
Image:
enter image description here
But Im getting this: https://jsfiddle.net/ce228caL/
Do you know how to properly get the layouts of the image?
html:
<div class="container py-md-5">
<div class="row justify-content-md-center">
<div class="col-12 col-md-auto">
<img style="width: 100%; height: auto" src="http://via.placeholder.com/1000x400"/>
</div>
<div class="col col-lg-2 d-md-flex">
<div class="d-none d-md-block details-title d-flex flex-column align-items-start">
<span class="font-size-sm font-weight-semi-bold">Title</span>
<h1 class="h5 mb-0 title">Subtitle</h1>
Link
</div>
</div>
</div>
</div>
css
.title{
display: flex;
flex-direction: column;
justify-content: space-between;
border: 1px solid $light-gray;
padding: 1rem;
margin-top: 1rem;
}
.subtitle{
margin-top: 1rem;
}
.link{
margin-top: 1rem;
}
You specified your first div to have all 12 columns on every screen size
<div class="col-12 col-md-auto">
Reduce it to 10 on medium and up, so the 2nd 2-column div will fit in the row. also set the 2nd div to col-md-2, so it occupies 2 columns on medium. Also, I am not sure why you would want to solve this using flexbox instead of the classic grid
<div class="container py-md-5">
<div class="row">
<div class="col-md-10 col-12">
<img style="width: 100%; height: auto" src="http://via.placeholder.com/1000x400"/>
</div>
<div class="col col-md-2 col-12">
<div class="d-none d-md-block details-title d-flex flex-column align-items-start">
<span class="font-size-sm font-weight-semi-bold">Title</span>
<h1 class="h5 mb-0 title">Subtitle</h1>
<span class="subtitle font-size-sm font-weight-semi-bold">Subtitle 2</span>
Link
</div>
</div>
</div>
</div>

Bootstrap Single Page Full Screen Layout Responsive Height

I am trying to make a single page full screen layout using Bootstrap 3 where the height of the main body is responsive.
The page is going to be displayed in Kiosk mode displaying 3 panels which display different messages, but as the site is going to be displayed on multiple screens of different sizes I am wanting to get the main to be responsive in height.
https://jsfiddle.net/gokcLvtv/7/
<div class="container">
<div class="row header">
<div class="col-xs-6">
Title
</div>
<div class="col-xs-6 text-right">
LOGO
</div>
</div><!-- Header-->
<div class="row main">
<div class="col-xs-8">
<div class="well">Panel One</div>
</div>
<div class="col-xs-4">
<div class="well">Panel Two</div>
<div class="well">Panel Three</div>
</div>
</div><!--main-->
<div class="row footer">
<div class="col-xs-12">© Copyright 2016</div>
</div><!--footer-->
</div><!--container-->
As you can see I have had to specify a height of the main content to get the cols to be 100% and then the .wells inside the column. But I am wanting this to be 100%.
You can use the vw value for horizontal and vertical resizing.
For example
HTML
<div class="main">
<div class="well">
Panel one
</div>
</div>
CSS
.main {
border: 1px solid red;
height: 75vw;
}
.well {
width: 30vw;
height: 30vw;
margin: 1vw;
}
It's easy to translate from px to vw. Every 1 vw is 10 pixels.
Thanks for your help with the vw ... I have managed to achieve this using vh for the height..
I have created an example for anyone who would like to use this in the future - here
Using the same layout
<div class="container-fluid">
<div class="row">
<div class="col-sm-12">
<div class="well">Header</div>
</div>
</div>
<!-- main -->
<div class="row">
<div class="col-xs-8 main">
<div class="well">
Main Panel
</div>
</div>
<div class="col-xs-4 side-bar">
<div class="well">
Side Panel One
</div>
<div class="well">
Side Panel One
</div>
</div>
</div>
<!-- Footer-->
<div class="row">
<div class="col-sm-12">
<div class="well">Hello</div>
</div>
</div>
</div>
You will just have to play around with the heights to get it to the screensize that works for you.

Bootstrap Grid arrangement on responsive view

Is it possible to do this?
I have 3 columns in a row. The first column has 2 nested row - top and bottom.
Is it possible to have the bottom row of the first column to be at the fourth position is the mobile view?
Here is my code:
http://www.bootply.com/yhhFaWRjC6
Edit:
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<div class="row" style="height:100%;">
<div class="col-md-4 col-lg-4 col-sm-12" style="background-color:#ccc;height:100%; padding:0px;">
<div class="row">
<div class="col-md-12 " style="height:180px;background-color:#d33;">one</div>
</div>
<div class="row">
<div class="col-md-12 " style="height:180px;background-color:#edd;">four</div>
</div>
</div>
<div class="col-md-4 col-lg-4 col-sm-12" style="height:360px;background-color:#e42;">two</div>
<div class="col-md-4 col-lg-4 col-sm-12" style="height:360px;background-color:#444;color:#fff;">three</div>
</div>
</div>
I want to make it the sequence to be:
- one
- two
- three
- four
In mobile
Assuming the first column to be less in height than both the second and third column I'm afraid you can only achieve this by:
Duplicating the content of the fourth column and showing/hiding it based on the grid size (e.g. xs). I'll show an example of this below.
Using JavaScript to move the content of the fourth column when the grid size changes. I have a small prototype of a jQuery plugin to facilitate this at https://github.com/ckuijjer/jquery-breakpointspy
Create your own grid system using flexbox. This might be an option if you don't have to support IE9 or lower.
I've implemented the first option below, and made some additional changes:
I've moved the inline styling into classes named .one, .two, .three and .four to make the code a little bit more clean.
I've started with the mobile layout and gave all classes col-xs-12. This makes a column take up 12 columns from the size xs onwards.
<div class="container">
<div class="row">
<div class="col-xs-12 one">one</div>
...
<div class="col-xs-12 four">four</div>
</div>
</div>
As we want to have each column take up a fourth of the container, I've added col-md-4 to each of the columns. Each column now looks like e.g. <div class="col-xs-12 col-md-4 one">. There is no need to add col-lg-4 nor col-sm-12.
Showing a column only on a specific grid size can be done by e.g. visible-xs-block. As we want the fourth column to only be visible on xs and sm I've changed the html into <div class="col-xs-12 visible-xs-block visible-sm-block four">four</div>. Notice that I've dropped the col-md-4 as there is no need for that anymore.
To put the fourth column below the first column when the screen is md or lg the first column is changed into a nested grid. I've opted not to use a second .row as having more than 12 columns will make the next column drop anyway and used .col-xs-12 as I always want a column to have a bootstrap grid class on it, regardless of the screen size. I could've used visible-md-block and visible-lg-block to make it show on md and lg only, but for fun I've used its opposite, hidden-xs and hidden-sm.
<div class="col-xs-12 col-md-4">
<div class="row">
<div class="col-xs-12 one">one</div>
<div class="col-xs-12 hidden-xs hidden-sm four">four</div>
</div>
</div>
See the entire code below:
.one {
height: 180px;
background-color: #d33;
}
.two {
height: 360px;
background-color: #e42;
}
.three {
height: 360px;
background-color: #444;
color: #fff;
}
.four {
height: 180px;
background-color: #edd;
}
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<div class="row">
<div class="col-xs-12 col-md-4">
<div class="row">
<div class="col-xs-12 one">one</div>
<div class="col-xs-12 hidden-xs hidden-sm four">four</div>
</div>
</div>
<div class="col-xs-12 col-md-4 two">two</div>
<div class="col-xs-12 col-md-4 three">three</div>
<div class="col-xs-12 visible-xs-block visible-sm-block four">four</div>
</div>
</div>

Resources