I've created a basic grid-based layout with Bootstrap 4.
I have two columns: Left and Right. The left column is a div.col-12.col-md-5 and the right one is div.col-12.col-md-7. Thing is, the left column has a table inside and since tables are not that resizables I want the left column to have a min width of 460px (so the data in the table can always be seen correctly). But I do want the other column in the right to be fully responsive and that it keeps resizing (until screen size < md breakpoint -768px-).
My layout looks something like this:
To try to achieve that behavior I've created this piece of css:
#media (min-width: 768px) {
.min-width-460-md {
min-width: 460px;
}
}
And I've applied the .min-width-460-md class to the left column. So my html code looks something like the next one:
<section class="container-fluid">
<div class="row">
<div class="col-12 col-md-5 min-width-460-md">
First column (left) which contains a table and needs to be min-width 460px.
</div>
<div class="col-12 col-md-7">
Second column (it contains more resizable data, so no min-width required here).
</div>
</div>
</section>
The problem is that with this new class applied to the left column, when it reaches 460px it stops resizing (as I wanted to) but the right column is being positioned below the left one, like this:
I obviously don't want this to happen. What I really want is that when the left column reaches 460px it stops resizing but the right one keeps resizing until the screen reaches less than 768px -md- (then both columns will be col-12).
Is there a way to do this with css + Bootstrap 4?
Thanks in advance!
Simplest way is to use an auto-layout column (.col) on the right...
<section class="container-fluid">
<div class="row">
<div class="col-12 col-md-5 min-width-460-md border">
<table class="table table-striped">
..
</table>
</div>
<div class="col bg-dark text-white">
Second column (it contains more resizable data, so no min-width required here).
</div>
</div>
</section>
Demo: https://www.codeply.com/go/IB5xTytQAq
This is simple issue. You can't use col-* col-md-* for this type of work. It's hard to display properly.
Check the snippet below.
.new-section{
background-color: black;
color: white;
padding: 30px;
}
.new-section .row{
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: horizontal;
-webkit-box-direction: normal;
-ms-flex-direction: row;
flex-direction: row;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
margin-left: -15px;
margin-right: -15px;
}
#media (min-width: 768px){
.new-section .row{
-ms-flex-wrap: nowrap;
flex-wrap: nowrap;
}
}
.new-section .row .min-width-460-md,
.new-section .row .right-column{
padding-left: 15px;
padding-right: 15px;
}
.new-section .row .min-width-460-md{
border: 1px solid #f2f2f2;
-ms-flex-preferred-size: 100%;
flex-basis: 100%;
-webkit-box-flex: 0;
-ms-flex-positive: 0;
flex-grow: 0;
-ms-flex-negative: 0;
flex-shrink: 0;
}
#media (min-width: 768px){
.new-section .row .min-width-460-md{
-ms-flex-preferred-size: 460px;
flex-basis: 460px;
}
}
.new-section .row .right-column{
width: 100%;
}
<section class="container-fluid new-section">
<div class="row">
<div class="min-width-460-md">
First column (left) which contains a table and needs to be min-width 460px.
</div>
<div class="right-column">
Second column (it contains more resizable data, so no min-width required here).
</div>
</div>
</section>
This is not proper solution with bootstra#4. This snippet is what you expected. Below code for bootstrap#4 solution.
#media (min-width: 768px) {
.min-width-460-md {
flex-basis: 460px !important;
max-width: 460px !important;
}
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<section class="container-fluid">
<div class="row flex-md-row flex-md-nowrap">
<div class="col-12 min-width-460-md bg-secondary">
First column (left) which contains a table and needs to be min-width 460px.
</div>
<div class="col-12 bg-warning">
Second column (it contains more resizable data, so no min-width required here).
</div>
</div>
</section>
Change col-md-5 and col-md-7 both to col-md and remove your custom min-width-460-md. col-md will auto-adjust to table width on smaller screens and make both columns equal width when the screen gets a bit bigger.
For large screens, add the col-xl-5 class to the table column.
Click the "run code snippet" button below and expand to full page:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<section class="container-fluid">
<div class="row">
<div class="col-12 col-md col-xl-5 bg-secondary">
The following line will give this div 460px min-width. <br>
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
<br>
First column (left) which contains a table and needs to be min-width 460px.
</div>
<div class="col-12 col-md bg-warning">
Second column (it contains more resizable data, so no min-width required here). Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ex totam qui voluptatibus reiciendis possimus laboriosam dolor libero alias quasi sequi at voluptas, porro, obcaecati amet minima fuga consectetur facilis eligendi.
</div>
</div>
</section>
Related
So here is the link to my project repository
https://github.com/iamlovingawareness/EdgeLedger/tree/main
In the following code snippet I am not able to implement this change:
in the solutions and cases section when the max-width is 768px it should stack one on top of the other but when I make the necessary changes in my styles.css file it shows as an error.
This is what I implemented as follows:
#media (max-width: 768px) {
.navbar {
flex-direction: column;
height: 120px;
padding: 20px;
}
.navbar a {
padding: 10px 10px;
margin: 0 3px;
}
.flex-items {
flex-direction: column;
}
.flex-columns .column,
.flex-grid .column {
flex-direction: column;
flex: 100%;
max-width: 100%;
}
.team img {
width: 70%;
}
}
Supporting HTML snippet
<section class="solutions flex-columns">
<div class="row">
<div class="column">
<div class="column-1">
<img src="./image_resources/home/people.jpg" alt="" />
</div>
</div>
<div class="column">
<div class="column-2 bg-primary">
<h4>What you are loooking for</h4>
<h2>We provide bespoke solutions</h2>
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Est,
aut!
</p>
<a href="#" class="btn btn-outline"
><i class="fas fa-chevron-right"></i> Read More</a
>
</div>
</div>
</div>
</section>
Where .flex-columns . columns is what is supposed to do the thing but is not.
Kindly help me out thank you
Update: Went to chrome dev tools to see what was going on and saw this in the element property section:
Here as you can see there is a slash on the property that is supposed to be acting when the max-width is 768px. My question now is how do I find out where it has been overridden and make the necessary changes.
Thanks !
I'm using Bootstrap 4 (now I'm on alpha-6).
I have this situation:
<body>
<!-- HERE I HAVE one div automatically generated with randomly ID and class -->
<div class="bigone">
<div class="container-fluid">
<div class="header">
My header
</div>
</div>
<div class="mybar">
Nav bar
</div>
<div class="main">
<div class="container-fluid">
<div class="row">
<div class="col-6">
<div class="card">
<div class="card-header">
Card Header
</div>
<div class="list-group list-group-flush">
<b>FIRST LINK</b>
Dapibus ac facilisis in
Dapibus ac facilisis in
Morbi leo risus
<b>LAST LINK</b>
</div>
<div class="card-footer">
Card Footer
</div>
</div>
</div>
<div class="col-6">
<h1>FIRST LINE</h1> So many words, so many words. So many words, so many words. So many words, so many words.
<br> So many words, so many words. So many words, so many words. So many words, so many words.
<br> So many words, so many words. So many words, so many words. So many words, so many words.
<br>
<h1>LAST LINE</h1>
</div>
</div>
</div>
</div>
<div class="footer">
Footer
</div>
</div>
<!-- HERE THAT DIV CLOSED -->
</body>
This is the css:
.bigone {
display: flex;
min-height: 100vh;
flex-direction: column;
}
.main {
flex: 1;
}
There is a DEMO on plnkr: https://plnkr.co/edit/Q9PQIj8uDFY80bxJGks3
I need footer to be on bottom when the page content is empty, for this reason I'm using: .bigone { height: 100vh; } and Bootstrap Flexbox align utilities like: <div class="bigone d-flex flex-column">
Now I need the list-group in card and the col-6 with "so many words" to be scrollable, so to have an height for both max to the bottom where the footer is.
In a nutshell: BODY must not have the scroll bar.
My header and footer height are not fixed, they change.
How to? I'm not a flexbox expert.
I don't need IE, just Chrome.
IMPORTANT:
I can't make my card height fixed with something like this:
height: calc(100vh - header.height - footer.height - etc...);
because my header, footer, etc. heights change dynamically.
Picture of the problem:
According to the spec, the setting flex: 1 (on the .main element) is equivalent to flex: 1 1 0, shorthand for:
flex-grow: 1
flex-shrink: 1
flex-basis: 0
However, for some reason, flex: 1 is not working as expected in your code. (I'm only checking in Chrome, per your question).
However, if you give .main the full shorthand – and make it a flex container and add overflow – your layout appears to work.
.main {
flex: 1 1 0; /* flex: 1, which you had before, is equivalent but doesn't work */
display: flex;
flex-direction: column;
overflow-y: scroll;
}
revised plunkr
Reference:
7.1.1. Basic Values of flex
EDIT (based on changes to the question)
My answer above removes scrollbars from the body and provides a vertical scrollbar for the .main section.
To make vertical scroll bars available for each column in the .main section, make this adjustment:
.main {
flex: 1 1 0;
display: flex;
}
.container-fluid {
display: flex;
}
.col-6 {
overflow-y: auto;
}
revised plunkr
I have
<div class="fixed-top collapse show wrapper">
<ul class="list-group bg-white menu">
</ul>
</div>
I fixed it by
.wrapper {
margin-top: 48px; /* place it under navbar */
height: 100vh;
overflow: scroll;
padding-bottom: 48px; /* compensate margin top */
}
Created a new Plunker to showcase what you're looking for.
To keep the footer on the bottom use Bootstrap Flexbox Auto Margins.
If you want to keep your main content within the initial viewport height, use the flex-grow:1 property with overflow-y:scroll. Its height will adopt responsively based on the space the other elements use.
Hope this helped.
I'm trying to create some CSS for a list of rectangles, with wrapping, that is responsive. The rectangles can contain a variable amount of text. The rectangles should have a minimum width of 300px, but can grow if there is more space available. It should work no matter the number of rectangles.
This is an image of what I want it to look like, in a wide desktop screen, a normal desktop screen and a phone, roughly:
(I realise that most phone and desktops are wider than that in pixels, but these numbers are easier to work with when it comes to SO's code snippets.)
I'm trying three techniques, and none of them do what I want:
1. Flexbox doesn't work:
Flexbox would seem ideal for this job. The trouble with the flexbox implementation is that I can't find a way to make sure the last rectangle stays the same size as the rest, while also allowing the rectangles to grow in very wide screens. Here's an image of the best flexbox result that I could come up with, which has the problem with the last line:
Here's the code of the flexbox implementation:
.container {
display: flex;
flex-wrap: wrap;
}
.rect {
flex: 1 0 300px;
height: 150px;
}
<div class="container">
<div class="rect" style="background-color: #2F80ED"></div>
<div class="rect" style="background-color: #2D9CDB"></div>
<div class="rect" style="background-color: #56CCF2"></div>
<div class="rect" style="background-color: #A6E2F5"></div>
<div class="rect" style="background-color: #D6EBF2"></div>
</div>
2. float: left technique doesn't work:
Another responsive technique is to use floats, but I can't find a way to keep the rectangles the same width (with varying text content), while also allowing them to grow in the widest screens. Here's an image of what I ended up with:
Here's the code of the float: left implementation:
.container:after {
content: "";
clear: both;
}
.rect {
float: left;
min-width: 300px;
height: 150px;
overflow-y: hidden;
}
<div class="container">
<div class="rect" style="background-color: #2F80ED">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod</div>
<div class="rect" style="background-color: #2D9CDB"></div>
<div class="rect" style="background-color: #56CCF2">Lorem ipsum dolor sit amet, consectetur</div>
<div class="rect" style="background-color: #A6E2F5">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed</div>
<div class="rect" style="background-color: #D6EBF2"></div>
</div>
3. Why not media queries?
I'm looking for a solution that doesn't involve media queries, as media queries only let you put conditions on the screen width, and not on the .container width.
You may keep using flex with an extra element via a pseudo with no height:
.container {
display: flex;
flex-wrap: wrap;
background:gray;/*see me */
}
.container:after {
content:'';
flex: 1 0 300px;
margin-bottom:auto;
}
.rect {
flex: 1 0 300px;
height: 150px;
}
<div class="container">
<div class="rect" style="background-color: #2F80ED"></div>
<div class="rect" style="background-color: #2D9CDB"></div>
<div class="rect" style="background-color: #56CCF2"></div>
<div class="rect" style="background-color: #A6E2F5"></div>
<div class="rect" style="background-color: #D6EBF2"></div>
</div>
:Note that is fine for five, for six boxes behavior is different.
I know you said that you were looking for an answer that didn't involve media-queries, but I believe it would be the best way to handle this situation.
If you set position: relative; on your .container all of it's children will base their width percentage off of .container's width. While technically you would still be basing your conditions off of the screen width you can still set the container width to any size you want and the .rect's will scale to that width, it would just depend on which of your media queries were active for what percentage your .rect's would be scaling to.
You could also set a max-width: for your .container in any of those media queries if you don't want it to grow past a certain size.
Here is a link to a pen which has the layout looking like your intended images above. http://codepen.io/bryanrunner/pen/BppzbE
.container {
position: relative;
display: flex;
flex-flow: row wrap;
max-width: 1200px;
}
.rect {
height: 150px;
}
#media (max-width: 1920px) {
.rect {
width: 20%;
}
}
#media (max-width: 1000px) {
.rect {
width: 50%;
}
}
#media (max-width: 600px) {
.rect {
width: 100%;
}
}
Since I'm new to flexbox, I can't find a way to get this layout work (or maybe it's impossible with flexbox).
Basically I want to have 3 columns: first one is the image, second is the H1 and description, and third is the button. The thing is I want the description to be able to expand underneath the button (the button should be on same row with the H1). Using float this is easy, but since I'm designing mobile first I want to use flexbox as much as possible. Can this be done with flexbox?
you can nest flexboxes. You'll need 3 nesting levels
Img + Text
In Text you'll have two units - Head + body
In Head you'll have two units - Title + button
<div class="flex">
<div>
<img src="#">
</div>
<div class="flex column">
<div class="flex head">
<h1>Title goes here</h1>
<button>Button</button>
</div>
<p>Lorem ipsum dolor sit amet</p>
</div>
live sample: http://codepen.io/anon/pen/mvzid?editors=110
I know this is old, This is another solution:
<div class="wrapper">
<div class="image-cont">
<img src="https://via.placeholder.com/150">
</div>
<div class="details-cont">
<h1>H1 title</h1>
<button type="button">Click Me!</button>
<p>long desription here... long description here... long description here</p>
</div>
</div>
CSS:
.wrapper {
display: flex;
}
.details-cont {
display: flex;
flex-wrap: wrap;
padding: 10px;
justify-content: center;
align-items: center;
}
p {
width: 100%;
margin: 0;
}
button {
margin-left: auto;
}
I am using Bootstrap to create a responsive web page. I need to add a padding-left and padding-right to the body to always have a 50px wide >empty safety area< on each side.
Problem: When I resize the viewport, the content of container overflow on the right.
Is there a simple way how to achieve this effect? I only tried the following one, but it doesn't look very good (the container is too narrow in the end).
// container responsivity fix
.container {
.container-fixed();
#media (min-width: #screen-sm-min) {
width: calc(~'#{container-sm} - 100px');
}
#media (min-width: #screen-md-min) {
width: calc(~'#{container-md} - 80px');
}
#media (min-width: #screen-lg-min) {
width: calc(~'#{container-lg} - 100px');
}
}
HTML structure:
<header>
<div class="container">
<div class="row">
<div class="col-xs-12 col-sm-4">
<a href="#">
LOGO
</a>
</div>
<div class="col-xs-12 col-sm-5">
<h2>Lorem ipsum dolor sit amet, <strong> consectetur adipiscing elit.</strong> </h2>
</div>
<div class="col-xs-12 col-sm-3 text-right">
<i class="flag cz active">A</i>
<i class="flag uk">B</i>
<i class="flag ge">C</i>
</div>
</div>
</div>
</header>
Fiddle: http://jsfiddle.net/o5bkpv7c/
The text is not stretchy so it won't fit inside the header past a certain breakpoint. I usually use break word or just size the text down or use fitText.js. There's cleaner ways of doing this.
DEMO: http://jsfiddle.net/o5bkpv7c/4/
body {
padding: 0 20px;
}
header {
background: lightblue;
padding: 1em 0;
}
header h2 {font-size:1.2rem;margin:10px 0;}
.flag {
width: 29px;
height: 20px;
display: inline-block;
background: red;
}
#media (min-width:768px) {
header h2 {font-size:1.3rem;margin:0;}
}
Also, see the layout you are going for, I wouldn't use the grid system for it. Here's a cleaner way.
http://jsbin.com/tuyeta/1/edit