I made an example in codepen:
Link: https://codepen.io/ScottFSchmidt/pen/gGVPrm
How do I get section B to float left on XS/mobile phone (sections A, C, D will hide). Getting all sections to "stack float left" would also work.
The problem seems to be that section A, C, & D are still "there" but hidden causing section B to "float right".
<div class="container-fluid wrapper">
<div class="box a hidden-sm hidden-xs"> <b><u>Definitions <br></b></u>
Grid-gap: provides an easy way for spacing our content <br>
Grid: generates a block-level grid <br>
Inline-grid: generates an inline-level grid<br>
Subgrid: Indicate that you want the sizes of its rows/columns to be taken from its parent rather than specifying its own.
</div>
<div class="box b">
<b><u>Conclusion <br></b></u>
Flexbox and Gridbox can be used together (with bootrap). <br>
Flexbox is best for single rows while Grixbox is best for "2 dimensions" <br>
Non-flexible measurements such as px can make boxes not appear on screen if the screen width is less than the px size. <br>
<br><b>Sources</b><br>https://css-tricks.com/snippets/css/complete-guide-grid/<br>
https://gridbyexample.com/examples/<br>
https://css-tricks.com/things-ive-learned-css-grid-layout/<br>
https://css-tricks.com/snippets/css/complete-guide-grid/<br>
https://www.w3schools.com/css/css_rwd_grid.asp<br>
</div>
<div class="box c hidden-sm hidden-xs"><b><u>What is flexbox? </b></u><br>
Flexbox is for one dimensional layout (row or column).
<br>"Flexbox is a single dimension – in a row OR a column." -Rachel Andrews <br>
Warning: Flexbox is NOT compatible with some IE verisions.
</div>
<div class="box d hidden-sm hidden-xs">
<b><u>What is gridbox? <br></b></u>
Grid is designed to be used with flexbox, not instead of it. CSS grid is for two dimensional layout. <br>"Grid is for layout of items in two dimensions – rows AND columns" - Rachel Andrews.
</div>
</div>
If you -1 please explain why for better posting in future as I am new to forms.
Thanks!
You can do that using flex. Check the code below.
.container {
display: flex;
flex-direction: column;
}
.left{
order: 2;
}
.right {
order: 1;
}
.container > div {
flex: 1;
}
.container img {
width: 100%;
display: block
}
.innerBottom {
display: flex;
flex-direction: column
}
#media(min-width: 768px){
.container {
flex-direction: row;
}
.innerBottom {
flex-direction: row
}
.left{
order: 1;
}
.right {
order: 2;
}
}
<div class="container">
<div class="right">
<img src="http://www.placehold.it/600x200/cccccc?text=Right">
</div>
<div class="left">
<div>
<img src="http://www.placehold.it/1200x200/cc0000?text=Left">
</div>
<div class="innerBottom">
<div>
<img src="http://www.placehold.it/600x200/azazaz?text=LeftBottomLeft">
</div>
<div>
<img src="http://www.placehold.it/600x200/ddd?text=LeftBottomRight">
</div>
</div>
</div>
</div>
Related
I'm using Bulma have a column of cards which need to have the same height regardless of the content.
To achieve so I have created the following class
.equal-height
display: flex
flex-direction: column
height: 100%
My HTML looks like
<div class='columns is-multiline'>
<div class='column is-one-fifth'>
<div class='card equal-height'>
<div class='card-content'>
# CONTENT GOES HERE
</div>
<div class='card-footer'>
# FOOTER GOES HERE
</div>
</div>
</div>
<div class='column is-one-fifth'>
<div class='card equal-height'>
<div class='card-content'>
# CONTENT GOES HERE
</div>
<div class='card-footer'>
# FOOTER GOES HERE
</div>
</div>
</div>
</div>
Which produces something like
Now I'm trying to make the card-footer to stick at the bottom of the card like below.
I have tried a few things with flex but they don't really make sense.
Any ideas on how I may do it?
Add "flex: auto;" to '.card-contents' to make the card-footer to stick at the bottom of the card. Here is the working jsfiddle link.
.equal-height {
display: flex;
flex-direction: column;
height: 100%;
}
.equal-height .card-content {
flex: auto;
}
Add this CSS
.card-footer {
margin-top: auto;
}
working demo : https://jsfiddle.net/baLg7940/
UPDATE:
I made a fiddle for testing.
An illustration of what I'd like to achieve: (Rows and columns are Bootstrap 4 rows and columns.)
The page should only have scrollbars if the second row is already
"fully compressed" (0 height) and still the header + first row +
footer can't fit in the viewport.
The second row doesn't have to fill
in all remaining pale green place. It's height can be flexible.
Flexbox? Max-width? Overflow... How should I start? What could be a good solution?
HTML:
<div class="page">
<div class="header">
...<br>...
</div>
<div class="main">
<div class="container-fluid">
<div class="row">
<div class="col-6">
<div class="card">
<div class="card-header"> .... </div>
<div class="card-body"> .... </div>
</div>
</div>
<div class="col-6">
<div class="card">
<div class="card-header"> .... </div>
<div class="card-body"> .... </div>
</div>
</div>
</div>
<div class="row">
<div class="col-6">
<div class="card">
<div class="card-header"> .... </div>
<div class="card-body scrollable"> THIS <br> SHOULD <br> BE <br> THE <br> SCROLLABLE <br> CONTENT </div>
</div>
</div>
</div>
</div>
</div>
<div class="footer">
...
</div>
</div>
CSS:
div.page {
background-color: palegreen;
display: flex;
flex-direction: column;
min-height: 100vh;
max-height: 100vh;
}
div.header,
div.footer {
background-color: grey;
padding: 0.5em;
}
div.main {
display: flex;
flex-grow: 1;
}
div.row {
margin-top: 1em;
}
div.scrollable {
/* ??? */
}
The key is how you calculate the height for the <main> and usage of flex, esp. flex-grow, flex-shrink.
<header>, <main> and <footer>
The second row doesn't have to fill in all remaining pale green place. It's height can be flexible.
So I assume you want the <header> and <footer> always stay on top and bottom. Instead of regular absolute positioning approach, I want to explicitly set the heights for them, as well as for <main>.
HTML
<header>header</header>
<main class="container-fluid"></main>
<footer>footer</footer>
SCSS
$custom-header-height: 3rem;
$custom-footer-height: 2rem;
header, footer {
background-color: var(--gray);
// In order to position the text to the center, like your picture
display: flex;
flex-flow: row nowrap;
justify-content: center;
align-items: center;
}
header {
height: $custom-header-height;
}
footer {
height: $custom-footer-height;
}
main {
// Calculate the height for main, which is 100% viewport height -
// height of header - height of footer
height: calc(100vh - #{$custom-header-height} - #{$custom-footer-height});
background-color: var(--teal);
}
Result
This gives you the playground you can build stuff on.
First Row
The first row is free to expand as high as its contents, but you don't want it to take up any free space. That's why you set flex-grow: 0;. Also when you resize the window and the space for first row is shrinking, you don't want the cards go over the row. That's why you set flex-shrink: 0;. We might as well use the shortcut flex: 0 0 auto; for those 2.
But in order to set that, the first row (as well as the second row) needs to be flexbox children. So we set display:flex; on its parent - <main>.
HTML
<header>header</header>
<main class="container-fluid">
<div class="row first-row">
<div class="col-6">
<div class="card">...</div>
</div>
<div class="col-6">
<div class="card">...</div>
</div>
</div>
</main>
<footer>footer</footer>
SCSS (In addition)
main {
display: flex;
flex-flow: column nowrap;
}
.first-row {
// I purposely make first row's background yellow so that you can see it
background-color: var(--yellow);
flex: 0 0 auto;
}
Result
Second Row
The key here is to make the <card> not to grow when there is space, but shrink on limited space, which is the default of flexbox children: flex: 0 1 auto;
But again, in order to use that, its parent needs to display: flex;. Here the parent is col-6 since we want to use bootstrap grid system.
HTML
<header>header</header>
<main class="container-fluid">
<div class="row first-row">
<div class="col-6">
<div class="card">...</div>
</div>
<div class="col-6">
<div class="card">...</div>
</div>
</div>
<div class="row second-row">
<div class="col-6">
<div class="card">
...
...
...
</div>
</div>
</div>
</main>
<footer>footer</footer>
SCSS (In addition)
.second-row {
// I purposely make second row's background to be blue so that you can see it
background-color: var(--blue);
// Any column, class name starts as "col-"
[class*="col-"] {
display: flex;
flex-flow: column nowrap;
// So that when the second row is compressed to 0, it doesn't show
// the row completely.
min-height: 0;
.card {
// flex-grow: 0;
// flex-shrink: 1;
// Might as well just set it
// flex: 0 1 auto;
// But this is the default of flexbox children so we don't need to set
// it here.
.card-body {
overflow-y: auto;
}
}
}
}
Result
The second row doesn't have to fill in all remaining pale green place. It's height can be flexible.
An illustration of what I'd like to achieve
The page should only have scrollbars if the second row is already "fully compressed" (0 height) and still the header + first row + footer can't fit in the viewport
Notes
There is still a funkiness when the second row is fully compressed. The scrollbar is still hanging there and I don't know how to get rid of it.
The code can be simplified a little bit without usage of bootstrap grid system.
Demo
https://codepen.io/anon/pen/XBqyxZ
Sorry for this lengthy post. If you want to know more about flexbox, here is a great guide: https://css-tricks.com/snippets/css/a-guide-to-flexbox/
I would but a set the height (or max-height if you prefer) on the card and then set overflow to scroll.
<html>
<div class="box">
<div class="content">
Dispassionate extraterrestrial observer citizens of distant epochs
permanence of the stars billions upon billions vastness is bearable only
through love brain is the seed of intelligence.
</div>
</div>
</html>
<style>
.box {
width: 500px;
overflow: scroll;
}
</style>
I am trying to split my webpage into two vertical columns which can be clicked on to take you to the right pages. I've gotten this far.
HTML
<!-- Choices -->
<div class="container-fluid">
<div class="row">
<div class="col-md-6 col-xs-12 vertical-center webd">
<h1 class="text-muted text-center">Web Design</h1>
</div>
<div class="col-md-6 col-xs-12 vertical-center circ">
<h1 class="text-muted text-center">Circus</h1>
</div>
</div>
</div>
CSS
.vertical-center {
min-height: 100%;
min-height: 100vh;
display: flex;
align-items: center;
}
.webd {
background-image: url('webd.jpg');
}
.circ {
background-image: url(circ.JPG);
}
My issue is, no matter where I put the text-center class. My <h1>s stay left aligned on the page. Can anybody help?
It is because you have added display flex to the parent container. This means the children are not full width anymore.
If you add the following style, it will fix your error:
.vertical-center > .text-center
{
flex-grow: 1;
}
Example bootply
If you don't want to grow the children, you can just add the following to your vertical center: justify-content: center;
Example bootply 2
Hi, I was wondering how can I achieve a grid as shown above. Perhaps you guys have some tricks? :) I've tried Masonry, but I don't think it's fit for this.
I'm also using Bootstrap, but it doesn't have to be Bootstrap. Maybe if i'd had some keywords I could Google it, but I have nooo idea what exactly to search for.
This can be done easily using nested flexboxes- created a demo for you.
Adjust height and width of wrapper to suit your needs.
Enjoy!
* {
box-sizing: border-box;
}
.wrapper {
display: flex;
height: 250px;
}
div {
background: rgb(0, 140, 88);
}
.wrapper > div:first-child {
width: 50%;
}
.wrapper > div:last-child {
display: flex;
flex-direction: column;
width: 50%;
height: 100%;
}
.wrapper > div:last-child > div:first-child {
width: 100%;
height: 50%;
background: #2ba982;
}
.wrapper > div:last-child > div:last-child {
height: 50%;
display: flex;
}
.wrapper > div:last-child > div:last-child > div {
width: 50%;
height: 100%;
}
.wrapper > div:last-child > div:last-child > div:first-child {
background: #76c6ac;
}
.wrapper > div:last-child > div:last-child > div:last-child {
background: #bbe2d5;
}
<div class="wrapper">
<div></div>
<div>
<div></div>
<div>
<div></div>
<div></div>
</div>
</div>
</div>
Yes, you can do this with Bootstrap.
The major element will be one row with 2 div's (50% each, soo col-md-6 for example). The div on the right will have 2 row on his own, each with 50% of the height of his parent element. The second row of this will have 2 columns himself, with col-md-6 again. Don't forget each time you have a row or a container, you should always consider the 12 columns system again!
<div class="row">
<div class="col-md-6">
</div>
<div class="col-md-6">
<div class="row half-height">
<div class="col-md-12">
</div>
</div>
<div class="row half-height>
<div class="col-md-6">
</div>
<div class="col-md-6">
</div>
</div>
</div>
</div>
Not much time to do a jsfiddle, but I think it was clear
You would be looking at something similar to this (Note: This is just one of the many solutions available
Fiddle
What you do is you use the bootstraps grid system to create your shapes accordingly and you set the height of the left box (big box) to double the height of the smaller box
<div class="container">
<div class="row">
<div class="col-md-6" style="background-color:green;height:600px;">
</div>
<div class="col-md-6">
<div class="row">
<div class="col-md-12" style="background-color:blue;height:300px">
</div>
</div>
<div class="row">
<div class="col-md-6"style="background-color:yellow;height:300px"></div>
<div class="col-md-6"style="background-color:red;height:300px"></div>
</div>
</div>
</div>
</div>
As you can see in this code I have given the smaller voxes a height equal to half of the big box's height, the colors are just for visual representation and serve no function whatsoever, by using col-md-6 you can fit two columns in one row, which is what we need in your case, *Note, bootstrap has 12 columns* by using this we can safely assume that in the left box we need one div that's 12 columns wide in the first nested row (since we have two rows of smaller boxes we are using a nested row) and two boxes that are 6 columns wide in the second nested row.
Ofcourse in your case the inline style attributes will be moved to your style.css file
Hope this helps!
i am just wondering if i have layout like this
<div class="container">
<div class="left"> Left </div>
<div class="right"> Right </div>
</div>
changing view port to 320 needs right div appear first and left div below it , Is this possible ??????
yes. just use the flex-box setup on the pertinent media query, as exemplified below and the boxes will show up reversed.
<html><head></head><body><div class="container" style="
display: -webkit-flex;
">
<div class="left" style="
-webkit-flex-flow: column;
background: lightgray;
"> Left </div>
<div class="right" style="
-webkit-flex-flow: column;
background: yellow;
-webkit-order: -1;
"> Right </div>
</div>
</body></html>
Original source: https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Flexible_boxes
It is possible and widely used. Take a look at this mobile first approach:
<div class="container">
<div class="right"> Right </div>
<div class="left"> Left </div>
</div>
This will be rendered one box below another on mobile. And now we use CSS to rearrange them on bigger screens (above 320px):
#media only screen and (min-width : 481px) {
.left { float: left; }
.right { float: right; }
}