Bootstrap - Stop container from resizing (ie shrinking) when resizing browser - html

I have a bootstrap container in which I have 1 row with 6 columns, like so:
<div class="container-fluid m-0 p-0 bg-primary">
<div class="row">
<div class="card col-2">
</div>
<div class="card col-2">
</div>
<div class="card col-2">
</div>
<div class="card col-2">
</div>
<div class="card col-2">
</div>
<div class="card col-2">
</div>
</div>
</div>
In each column I am adding some additional cards with text content in them. When the browser is fully expanded, the text looks nicely.
However, when I shrink the browser to half size, the entire container shrinks... so the 6 columns are now tiny and unreadable. Not only that, my inner components end up growing vertical scrollbars which makes it look horrible.
Is there a way to keep the container from shrinking when you shrink the window? I want the size to be fixed.
This means that it is possible that there will be a horizontal scrollbar since the container won't fit on the browser screen if it is shrunk.
Thank you. I found an answer from 2012-2013 about shrinking but I want something more updated.

I found the solution myself (based on my device). I didn't find how to programmatically find my device screen width, but in either case, absolute positioning with pixels seems to be the way to go.
<div class="container-fluid m-0 p-0 bg-primary" style="position: absolute; width: 1518px;">
<div class="row">
<div class="card col-2" style="position: absolute; width: 253.0px; left: 0.0px;">
<div class="card col-2" style="position: absolute; width: 253.0px; left: 253.0px;">
<div class="card col-2" style="position: absolute; width: 253.0px; left: 506.0px;">
<div class="card col-2" style="position: absolute; width: 253.0px; left: 759.0px;">
<div class="card col-2" style="position: absolute; width: 253.0px; left: 1112.0px;">
<div class="card col-2" style="position: absolute; width: 253.0px; left: 1265.0px;">
</div>
</div>

Related

Bootstrap 5 - Make div with flex-grow-1 class scrollable

I'm trying to make the indicated div below scrollable, but it always seems to extend the document size beyond screen space instead of creating a scrollbar. One solution is to set a fixed pixel height for the div, but I want to avoid this to ensure scalability between devices. Any ideas?
<div class="row no-gutters w-100 flex-grow-1">
<div class="col-8">
<div id="playarea" class="container-fluid border-top border-end h-100 px-0">
<!-- Cards go here -->
</div>
</div>
<div class="col-4">
<div class="container-fluid border rounded-top w-100 h-100 d-flex flex-column">
<div class="container my-3 d-flex mb-0">
<h5 class="flex-grow-1">Side Content</h5>
</div>
<hr class="border mt-2 mb-3">
<div class="container mb-3 d-flex">
<!-- Non-scrollable search area -->
</div>
<div class="container flex-grow-1 overflow-auto">
<!-- Scrollable content goes here -->
</div>
<div class="card mt-2 bg-light mb-3" id="info-panel">
<div class="card-body">
<!-- Non-scrollable info box -->
</div>
</div>
</div>
</div>
</div>
Many thanks in advance
Your question is a bit confusing because your .row has .flex-grow-1 which one would only add if you want .row to grow in available height of its parent, not in width. This would mean .row should always have a height and my solution can be simplified. So let me know if that's the case, because my answer assumes .row has no height.
My solution that requires no fixed height uses a container inside col-4 with absolute positioning:
#overflow-container {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
padding: inherit;
}
This container will take up all available space inside col-4 and will grow or shrink with it. Now the element with overflow: scroll will work as you want.
The only drawback here is that if col-8 (or row) has no content - and thus no height - the #overflow-container will also have no height and any content inside the .overflow-auto element will not be visible. So if col-8 can be empty, a min-height on col-4s parent is needed.
The line padding: inherit is there to give the column its padding back; Bootstrap uses the selector row > * to give columns their padding.
I removed all unnecessary classes for this snippet to work for simplicity, but I added the sm breakpoint on the columns so they stack on mobile screen sizes. If you don't want this, you can simply remove the -sm part on the columns and the #media in the CSS. It's only there to show how it can be done.
.col-sm-8 {
background: lightyellow;
}
.col-sm-4 {
background: lightgreen;
}
#media (min-width: 576px) {
#overflow-container {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
padding: inherit;
}
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.3.0-alpha1/dist/js/bootstrap.bundle.min.js" integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN" crossorigin="anonymous"></script>
<div class="container-fluid">
<div class="row">
<div class="col-sm-8">
<p>This column should have enough content...</p>
<br><br><br><br><br>
<p>...So `Overflowing content` will have a height.</p>
</div>
<div class="col-sm-4 position-relative">
<div class="d-flex flex-column" id="overflow-container">
<div class="">
<h5>Aside Content</h5>
</div>
<div class="">
<p>Some content here.</p>
</div>
<div class="overflow-auto">
<p>Overflowing content.</p>
<br><br><br><br><br><br><br><br><br>
<p>Unless col-8 is long enough for me to fit.</p>
</div>
<div class="">
<p>Some content here.</p>
</div>
</div>
</div>
</div>
</div>

How would I fix material icons always showing on top? (HTML)

I have a webpage with a loading menu that greys out the background while the loading menu is shown. The menu is last in the document as to be on-top of the rest of the page. However, when using Google's Material Icons, the icon appears above the loading menu.
My guess would be that the icons load last, and as such are infront of static parts of the webpage.
I would expect and prefer the icon to be behind the loading menu. How could I achieve this?
In addition, I use bootstrap. I do not believe that my issue resides with bootstrap, however it may be crucial to understanding the code snippits.
Snippit of buttons: (I included more than neccesary incase my issue resides outside the icons)
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">Link:</span>
</div>
<input type="text" class="form-control" id="studentLink" value="<?=studentLink?>" readonly>
<div class="input-group-append">
<button class="btn btn-light h-100" onclick="copyLinkToClipboard()">
<span class="material-icons"style="font-size: 1em">
content_copy
</span>
</button>
</div>
</div>
Snippit of Loading Menu:
<!-- Loading Alert -->
<div class="d-flex justify-content-center align-items-center" style="position: absolute; top:0px; width: 100%; height: 100%; visibility: visible" id="loadingAlert">
<div class="bg-light opacity-75" style="position: absolute; top:0px; width: 100%; height: 100%"> </div>
<div class="shadow col-6 card bg-info text-white">
<div class="card-header">
<div class="d-flex">
<div class="me-2 spinner-border align-self-center"></div>
<div class="vr"></div>
<h3 class="mx-2 align-self-end">Loading:</h3>
</div>
</div>
<div class="card-body text-center">
<h1>Creating Session</h1>
<h3>Please wait</h3>
</div>
</div>
</div>
Thank you #Kip for the answer.
Add the css style 'z-index' to the loading element.
Example (Based upon my code snippit):
<div class="d-flex justify-content-center align-items-center" style="position: absolute; top:0px; width: 100%; height: 100%; visibility: visible; z-index: 1000" id="loadingAlert">
...
</div>
Note the section style="z-index: 1000".
This feels like a very clunky solution, as why would you need to update the z-index, but here the solution is.

Boostrap grid height and placing row with height: auto

I am doing a simple page with a bootstrap grid and I am having some problems with placing the middle row occupying the full height in the middle.
These are the 3 rows: page
I want to place the row with the logo in the middle, but I am having problems with it. I placed height: 100%;, height: auto;. I even placed the container height to 100% and auto and nothing works!
I think there is a concept about bootstrap heigh that I am missing, because its the heigh that I have problems
html:
<div class="container-fluid">
<div class="row">
<div class="col-md-1 col-2">
<img id="menuIcon" (click)="toggleRightSidenav()" onmouseover="this.src='../../../assets/Images/generic/menuIcon_hover.png'" src="/assets/Images/generic/menuIcon.png" onmouseout="this.src='/assets/Images/generic/menuIcon.png'">
</div>
<div class="col-md-10 col-8">
</div>
<div class="col-md-1 col-2">
<img id="helpIcon" routerLink="/guide" onmouseover="this.src='../../../assets/Images/home/helpIconHover.png'" src="/assets/Images/home/helpIcon.png" onmouseout="this.src='/assets/Images/home/helpIcon.png'">
</div>
</div>
<div class="row row align-items-center mh-100" >
<div class= "col-md-12">
<img id="logo" src="/assets/Images/home/Logo.png">
</div>
</div>
<div class="row align-items-center justify-content-around fixed-bottom">
<div class="col-md-2 col-sm-2">
<img id="addButton" routerLink="/addPlayer" onmouseover="this.src='../../../assets/Images/generic/addIcon_hover.png'" src="../../../assets/Images/generic/addIcon.png" onmouseout="this.src='/assets/Images/generic/addIcon.png'" />
</div>
<div class="col-md-2 col-sm-2">
<p>Players Waiting: {{playerWaiting}} </p>
</div>
<div class="col-md-2 col-sm-2">
<p>Listed Players: {{playersListed}}</p>
</div>
<div class="col-md-2 col-sm-2">
<img id="searchButton" routerLink="/search" onmouseover="this.src='../../../assets/Images/generic/searchIcon_hover.png'" src="../../../assets/Images/generic/searchIcon.png" onmouseout="this.src='/assets/Images/generic/searchIcon.png'" />
</div>
</div>
</div>
css:
div{
border: yellow 1px solid;
}
#menuIcon{
width: 100%;
height: auto;
}
#helpIcon{
width: 100%;
height: auto;
}
#addButton{
width: 100%;
height: auto;
max-width: 127px;
}
#searchButton{
width: 100%;
height: auto;
max-width: 127px;
}
https://www.codeply.com/p/Xd0xi5hFNc
Couple of things.
To be able to fill several rows, you'd need a height for the container div.
Current HTML
<div class="container-fluid">
Update as
<div class="container-fluid d-flex vh-100 flex-column">
Now you can easily make your middle div fill the remaining gap by adding a fill-height class.
Current HTML
<div class="row row align-items-center mh-100" >
Update as
<div class="row row align-items-center fill-height">
Add this to your css
.fill-height {
flex: 1;
}
.fixed-bottom {
position: sticky;
}
jsFiddle

How to make responsive cards as shown below?

I am having some problem with that black box with date. I made it but it isn't responsive.
.date
{
width: 20%;
height: 15%;
background-color: black;
z-index: 1;
position: absolute;
top: 45%;
left: 8%;
}
<div class="card up" style="width:400px height:400px">
<img class="card-img-top" src="https://placehold.it/1900x1400" alt="Card image" style="width:100%">
<div class="date">
</div>
<div class="card-body">
<h4 class="card-title">John Doe</h4>
<p class="card-text">Some example text some example text. John Doe is an architect and engineer</p>
See Profile
</div>
</div>
Use position-absolute for the card-body
Put the date inside the card-body and give it negative top value.
Fixed size
.date {
width: 50px;
height: 50px;
background-color: black;
top: -25px;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.1/css/bootstrap.css" rel="stylesheet" />
<div class="container">
<div class="row">
<div class="col-6 mx-auto ">
<div class="card up" style="width:400px height:400px">
<img class="card-img-top" src="https://placehold.it/1900x1400" alt="Card image" style="width:100%">
<div class="card-body position-relative pt-5">
<div class="date position-absolute"></div>
<h4 class="card-title">John Doe</h4>
<p class="card-text">Some example text some example text. John Doe is an architect and engineer</p>
See Profile
</div>
</div>
</div>
</div>
</div>
Relative size
.date {
width: 3.8888888889em;
height: 3.8888888889em;
background-color: black;
top: -1.9em;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.1/css/bootstrap.css" rel="stylesheet" />
<div class="container">
<div class="row">
<div class="col-6 mx-auto ">
<div class="card up" style="width:400px height:400px">
<img class="card-img-top" src="https://placehold.it/1900x1400" alt="Card image" style="width:100%">
<div class="card-body position-relative pt-5">
<div class="date position-absolute"></div>
<h4 class="card-title">John Doe</h4>
<p class="card-text">Some example text some example text. John Doe is an architect and engineer</p>
See Profile
</div>
</div>
</div>
</div>
</div>
https://codepen.io/anon/pen/gKzQez
https://css-tricks.com/almanac/properties/p/position/
You can also do this with negative margin too.
First you have to respecify the width and height of 'card' and 'up' classes (missing semicolumn).
Then with the actual code snippet i can't clearly see what is wrong, but if you have responsive problem with absolute positioning, try to add "position: relative" to your container so the absolute elements won't overflow their parent block.
Lets understand the issue of this case first. As you have added width: 100% to the image, this has a responsive height. Therefore, .card doesn't have a fix height. When you use top: 40% (percentage value), this breaks the view.
Solution;
wrap image and .date inside another div.
<div style="position: relative;">
<img class="card-img-top" src="https://placehold.it/1900x1400" style="width: 100%;" alt="Card image">
<div class="date"></div>
</div>
And, set bottom: - 20% or appropreate value instead of top: 40% for .date class.
Hope this will fix the issue.

my divs are hidden under the others because of position absolute and 0 height

I have a problem with some cards I've made with Bootstrap. Here's the code:
formacion {
color: white;
position: relative;
}
.formacion .puesto {
position: relative;
z-index: 1;
}
.formacion .puesto img{
margin-top: 10px;
}
.formacion .empresa {
width: 100%;
position: absolute;
top: 52px;
background: rgb(255, 255, 255);
color: #000;
z-index: 0;
}
<div class="col-md-4 col-sm-4">
<h2>Formación<br><small>Experiencias académicas destacadas</small></h2>
<div class="col-md-12 capsula-formacion">
<div class="formacion row" style="background-color: #8224e3">
<div class="col-sm-3 col-md-3 puesto">
<img src="http://jdlcgarcia.es/wp-content/uploads/2016/10/Captura-de-pantalla-2016-10-17-a-las-14.50.26-150x150.png" alt=" # " title=" # " class="img-circle img-responsive center-block">
</div>
<div class="col-sm-9">
<h3 class="text-center">Ingeniero en informatica</h3>
</div>
<div class="col-sm-9 empresa" style="background-color: #e688ff">
<h4 class="text-center col-sm-offset-3">Universidad<br><small></small></h4>
<div class="row-fluid text-center col-sm-offset-3">
01-09-2004 - 01-04-2011 linea1
<br> linea2
<br> linea3
<br>
</div>
<div class="row-fluid">
</div>
</div>
</div>
</div>
<div class="col-md-12 capsula-formacion">
<div class="formacion row" style="background-color: #81d742">
<div class="col-sm-3 col-md-3 puesto">
<img src="http://jdlcgarcia.es/wp-content/uploads/2016/10/Captura-de-pantalla-2016-10-17-a-las-15.41.22-150x150.png" alt=" # " title=" # " class="img-circle img-responsive center-block">
</div>
<div class="col-sm-9">
<h3 class="text-center">Curso 1</h3>
</div>
<div class="col-sm-9 empresa" style="background-color: #e5ffa6">
<h4 class="text-center col-sm-offset-3">La institución<br><small></small></h4>
<div class="row-fluid text-center col-sm-offset-3">
01-10-2016 - 31-10-2016 linea1
<br> linea2
<br> linea3
<br>
</div>
<div class="row-fluid">
</div>
</div>
</div>
</div>
This code makes my divs look like this:
When they have to show like this (achieved by adding a fixed height to .capsula-formacion, but I don't want to put it because some of the divs could be longer than others):
I have always the same problem when I'm using absolute positioning so I'm assuming I'm doing it wrong. Which's the way to achieve my desired layout? Thank you in advance!!
Don't put absolute position in content div. You can manage image by position absolute.
You can set image by minus position and also you can set image width and height.
In responsive view you can manage image width and height by break point(Media query css).