Third element ends up in new line in Safari - css

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>

Related

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>

Fixed size but responsive cards boostrap3

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.

Css column-count should respect only first child

I'm trying to use the column-count to make a kind of week calendar to user tasks.
The main div of the week has the property of column-count to 7 and ALWAYS there will 7 childs. The seven days of this week.
Inside this days there are the tasks, but the number of tasks is variable and it break the column-count logic.
Why column-count not consider just the first childs inside it?
Here's an example of what I'm saying: https://jsfiddle.net/nby5ctb2/
On the second list, I wanted the tasks 1, 1.1 and 1.2 on top of each other, and when there are no childs just skip these day.
The css I used was just this:
.week {
-moz-column-count: 7;
-webkit-column-count: 7;
column-count: 7;
}
Thanks advanced
You seem to have misunderstood the purpose of column-count and are therefore misusing it.
It's purpose is to take some content and divide it into the given number of columns with as close to equal amounts of content as possible. The only tool you have is break-inside:avoid to keep "block-like" content together.
But if you do use it to make one column taller than the rest, your are making all columns the same height, because that's what CSS columns does. So, for example, using break-inside:avoid on .day. will cause other shorter .days to pile up in the same column. It would only work if days in your week had equal amounts of content, which is clearly not the case.
First question that comes in mind is: why not use flex? Since you probably want your day's widths equal, you need to add width to the children. By default display:flex children have flex: 0 1 auto, which makes them flexible, depending on contents.
.week {
display: flex;
}
.week > * {
width: calc(100% / 7)
}
Fiddle.
CSS Column is not the best solution to accomplish that. It strives to flow the content column wise, from left to right, and what you ask is to fight against it.
I recommend you use i.e. Flexbox, which does that very simple, and with better browser support.
.week {
display: flex;
flex-wrap: wrap;
}
.week .day {
flex-basis: calc(100% / 7);
word-break: break-all;
overflow: hidden;
}
This works
<div class='week'>
<div class="day">
<div class="task" >Task 1</div>
</div>
<div class="day">
<div class="task" >Task 2</div>
</div>
<div class="day">
<div class="task" >Task 3</div>
</div>
<div class="day">
<div class="task" >Task 4</div>
</div>
<div class="day">
<div class="task" >Task 5</div>
</div>
<div class="day">
<div class="task" >Task 6</div>
</div>
<div class="day">
<div class="task" >Task 7</div>
</div>
</div>
<br />
<br />
This <strike>doesn't</strike> work too, now
<div class='week'>
<div class="day">
<div class="task" >Task 1</div>
<div class="task" >Task 1.1</div>
<div class="task" >Task 1.2</div>
</div>
<div class="day">
<div class="task" >Task 2</div>
</div>
<div class="day">
</div>
<div class="day">
</div>
<div class="day">
<div class="task" >Task 5</div>
<div class="task" >Task 5.1</div>
</div>
<div class="day">
</div>
<div class="day">
</div>
</div>

Order and stack 3 columns with bootstrap 4

I have this structure in bootstrap columns:
And I want you to change to a lower resolution, be ordered as follows:
I found how to do it with flexbox here:
Flexbox: reorder and stack columns
But I can not change the entire structure of my project to flexbox, so I want to know if with bootstrap 4, it is possible to do so.
Thank you very much.
My poor test.
#import url( 'https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css' );
div {
text-align: center;
height: 60px;
}
#left {
background: yellow;
}
#middle {
background: blue;
}
#right {
background: coral;
}
<div class="container">
<div class="row">
<div class="col-sm-3 col-md-3">
<div id="left">COLUMN 1</div>
</div>
<div class="col-sm-6 col-md-6">
<div id="middle">COLUMN 2</div>
</div>
<div class="col-sm-3 col-md-3">
<div id="right">COLUMN 3</div>
</div>
</div>
</div>
You can use the Bootstrap 4 (alpha 6) utility classes to avoid the extra CSS. 1-2-3 becomes 3-2-1 on mobile.
<div class="container">
<div class="row">
<div class="col-sm-8 col-md-6 push-md-3">
<div id="middle">COLUMN 2</div>
</div>
<div class="col-sm-4 col-md-6">
<div class="row">
<div class="col-md-6 pull-md-12 flex-last flex-md-unordered">
<div id="left">COLUMN 1</div>
</div>
<div class="col-md-6">
<div id="right">COLUMN 3</div>
</div>
</div>
</div>
</div>
</div>
http://codeply.com/go/GIcPuzURbs
I assume by "resolution" you mean smaller screen size?
Here's a possible solution that uses some bootstrap push/pull grid utilities to reorder the columns in a medium size viewport, and then rearrange the layout in small size viewport the way you've shown in your diagram. In the small screen view, within a media query I use the css property order to reorder the 1 and 3 columns vertically Hope it gets you on the right track
<div class="container">
<div class="row">
<div class="col-sm-8 col-md-6 push-md-3">
<div id="middle">COLUMN 2</div>
</div>
<div class="col-sm-4 col-md-6">
<div class='row'>
<div id='leftcont' class="col-md-6 pull-md-12">
<div id="left">COLUMN 1</div>
</div>
<div id='rightcont' class="col-md-6">
<div id="right">COLUMN 3</div>
</div>
</div>
</div>
</div>
</div>
CSS:
div {
text-align:center;
height:60px;
}
#left{background:yellow;}
#middle {background:blue;}
#right {background:coral;}
#media (max-width: 768px) {
#leftcont { order: 2; }
#rightcont {
order: 1;
margin-bottom: 1em; }
}
New fiddle
The height of the divs might have to be adjusted for grid breakpoints but since the colored divs were only for a test, i didn't match those to your example
have you tried to pull column 2 for lower resolution?

how to implement responsive three columns boxed layout using bootstrap?

I am using the following to create a 3 columns layout feel to my website:
<div>
<div class="foo col-md-4">
</div>
<div class="foo col-md-4">
</div>
<div class="foo col-md-4">
</div>
<div class="foo col-md-4">
</div>
</div>
The above works great, and no matter how many foo items I added, it will format it to three columns layout automatically. However, I wanted to add a boxed feeling to each of the foo item, so that it does not look like that they're attached to each other. To achieve this, I added margin to the foo class:
.foo
{
margin: 3px 3px 3px 3px;
}
Adding the above, changes the layout become a two column layout.
My goal is to replicate responsive boxed layout, just like one we find in google plus.
Since the Bootstrap cols already having padding, you could make the content of your columns boxed.. For example, the panel creates a boxed effect.. No additional CSS required:
<div class="col-md-4">
<div class="panel panel-default">
<div class="panel-heading">Title</div>
<div class="panel-body">Content here..</div>
</div>
</div>
Demo on Bootply: http://bootply.com/96277
Also, you may be interest in this Bootstrap Google+ project:
http://iatek.github.io/bootstrap-google-plus/
http://jsbin.com/akaQufU/3
Put a div inside the col-* this can be done.
CSS
body {background:#eee}
/* demo */
.container {padding:3%;}
/* put a div inside .foo style for demo */
.foo > div {
background:#fff;
margin-bottom:4px;
padding:2%
}
/* adjust row margins */
.row.foo-row {
margin-left: -2px;
margin-right: -2px;
}
/* adjust padding */
.row.foo-row .col-sm-4,
.row.foo-row .col-md-4,
.row.foo-row .col-lg-4 {
padding-left: 2px;
padding-right: 2px;
}
HTML
<div class="container">
<div class="row foo-row">
<div class="foo col-md-4">
<div>
something
</div>
</div>
<div class="foo col-md-4">
<div>
something
</div>
</div>
<div class="foo col-md-4">
<div>
something
</div>
</div>
<div class="foo col-md-4">
<div>
something
</div>
</div>
<div class="foo col-md-4">
<div>
something
</div>
</div>
<div class="foo col-md-4">
<div>
something
</div>
</div>
<div class="foo col-md-4">
<div>
something
</div>
</div>
<div class="foo col-md-4">
<div>
something
</div>
</div>
<div class="foo col-md-4">
<div>
something
</div>
</div>
</div>
</div>
how about adding inset border instead
.foo
{
border-color:transparent;
border:inset 3px;
}
because margin will be calculated as a column extra width
anyway if you want to seperate them without using borders , then just use padding
.foo
{
padding:3px 3px 3px 3px;
}
Your columns should already spaced properly by your code and bootstrap's grid system, you just need need to added a margin to the bottom to stop them touching.
margin-bottom: 3px;
The problem you had with it converting to a 2 column was because you were adding side margin of 3px as well, which throws bootstraps grid system out.
You can't use padding (well) because bootstrap uses it for spacing and that will be more pain than gain.

Resources