What would cause bootstrap columns to act like rows? - html

I cannot figure out why these column classes are not acting properly. They are vertically stacking. I am fairly new to boostrap, so I could be missing something obvious.
Any help would be appreciated. Thanks ahead of time.
HTML-
<div class="row content-container">
<div class="row top-nav">
<div class="row header">
<div class="col-lg-4 logo">
<img src="images/logo.png">
</div>
<div class="col-lg-8 nav-area">
<div class="row number">
888.888.8888
</div>
<div class="row navigation">
</div>
<div class="row heading">
</div>
</div>
</div>
<div class="row sub-nav">
</div>
</div>
<div class="row content-footer"></div>
</div>
SCSS-
.content-container{
position: relative;
background-image:url("images/border-vertical.png"), url("images/parchment-bg.jpg"), url("images/border-vertical.png");
background-position: top left, top center, top right;
background-origin: border-box, content-box, border-box;
background-repeat: repeat-y, repeat-y, repeat-y;
height: 1500px;
width: 972px;
margin: auto;
padding: 20px 56px 0 56px;
.nav-area{
position: relative;
.number{
background-image:url("images/phone-number-bg.png")
}
}
.content-footer{
background-image: url("images/border-horizontal.png");
background-repeat: repeat-x;
background-origin:content-box;
height: 31px;
width: 892px;
position: absolute;
bottom: 0px;
left: 40px;
}
}

First off, you don't need to put the class row in every div that contained your col-lg-*
But you can still stack them however you want though.
Example :
<div class="row">
<div class="col-lg-12">
<div class="row">
<div class="col-lg-4">
...
</div>
</div>
</div>
</div>
As for your problem, you were right about the columns breaking up when you reach the min-width of col-lg-*. This is a feature of bootstrap. This prevents your columns shrinking so much that it becomes unreadable.
You could however, add the grid classes for smaller views. Like this:
<div class="row header">
<div class="col-md-4 col-lg-4 logo">
<img src="images/logo.png">
</div>
<div class="col-md-8 col-lg-8 nav-area">
<div class="row number">
888.888.8888
</div>
<div class="row navigation">
</div>
<div class="row heading">
</div>
</div>
</div>

Related

how do i create a photo collage with html css and bootstrap

I tried adding images to the div it did't work for me,
<img
class="img-fluid"
src="https://via.placeholder.com/800x800"
style="border-radius: 20px"
/>
Therefore I tried adding background images to divs, and when i add images to the divs the images wont show?can anyone tell me a solution to this and why this is hapenning?
<div class="col-lg-6">
<!-- ??????? how do i create the grid -->
<div class="row g-0">
<div class="col-lg-4">
<div
class="imgcollage"
style="background-image: url(../img/img2.jpg)"
></div>
</div>
<div class="col-lg-8">
<div
class="imgcollage"
style="background-image: url(../img/img2.jpg)"
></div>
</div>
</div>
<div class="row g-0">
<div class="col-lg-8">
<div
class="imgcollage"
style="background-image: url(../img/img2.jpg)"
></div>
</div>
<div class="col-lg-4">
<div
class="imgcollage"
style="background-image: url(../img/img3.jpg)"
></div>
</div>
</div>
</div>
here's the css
.imgcollage {
height: 100%;
width: 100%;
background-position: center;
background-size: cover;
border-radius: 20px;
}
sorry i'm posting another answer with working pictures the other pics didn't work because they aren't actually urls
.imgcollage {
height: 100%;
width: 100%;
background-position: center;
background-size: cover;
border-radius: 20px;
}
.col-lg-6{
display:grid;
/* declares how many columns there will automaticaly be and how big they will be +rows and how big of a gap between them*/
grid-template-columns: 250px 250px;
grid-template-rows: 250px 250px;
grid-gap: 15px;
<div class="col-lg-6">
<!-- ??????? how do i create the grid -->
<div
class="imgcollage"
style="background-image: url(https://images.pexels.com/photos/2253275/pexels-photo-2253275.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500)"
></div>
<div
class="imgcollage"
style="background-image: url(https://images.pexels.com/photos/1108099/pexels-photo-1108099.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500)"
></div>
<div
class="imgcollage"
style="background-image: url(https://images.pexels.com/photos/731022/pexels-photo-731022.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500)"
></div>
<div
class="imgcollage"
style="background-image: url(https://images.pexels.com/photos/2623968/pexels-photo-2623968.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500)"
></div>
</div>

Bootstrap images in columns overlapping

I have been trying to get 3 images to be responsive using bootstrap columns. They seem to be responsive, but the problem is that the images overlap except for the last column which remains being normal.
<div class="row">
<div class="col-sm-2 offset-sm-3">
<img class="img-responsive" src="../assets/images/roy-creates-categories-02.png">
</div>
<div class="col-sm-2">
<img class="img-responsive" src="../assets/images/roy-creates-categories-02.png">
</div>
<div class="col-sm-2">
<img class="img-responsive" src="../assets/images/roy-creates-categories-02.png">
</div>
</div>
I would like all 3 columns to like the one all the way on the right.
I've tried adding class "img-responsive" & "img-fluid" and neither have worked.
I'm using bootstrap 4.0.
The images are overflowing their container. The image on the right is full height but it is overflowing its container. Using the bootstrap '.col-2' means that you are limiting the column widths based on the window width. You could use background css rules instead of img elements to ensure containment or coverage of images or you could just use .col-auto instead of .col-2 with .justify-content-center provided you have appropriately sized images.
All three examples are in the snippet.
.row {
min-height: 150px;
}
.col-auto {
background-color: green;
}
.col-sm-2 {
background-color: red;
}
.bg-image {
width: 100%;
height: 100%;
background-image: url("https://picsum.photos/100");
background-position: center;
background-size: contain;
background-repeat: no-repeat;
}
.bg-image.bg-image--cover {
background-size: cover;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<div class="row justify-content-center">
<div class="col-auto">
<img class="img-fluid" src="https://picsum.photos/100">
</div>
<div class="col-auto">
<img class="img-fluid" src="https://picsum.photos/100">
</div>
<div class="col-auto">
<img class="img-fluid" src="https://picsum.photos/100">
</div>
</div>
<div class="row">
<div class="col-sm-2 offset-sm-3">
<div class="bg-image"></div>
</div>
<div class="col-sm-2">
<div class="bg-image"></div>
</div>
<div class="col-sm-2">
<div class="bg-image"></div>
</div>
</div>
<div class="row">
<div class="col-sm-2 offset-sm-3">
<div class="bg-image bg-image--cover"></div>
</div>
<div class="col-sm-2">
<div class="bg-image bg-image--cover"></div>
</div>
<div class="col-sm-2">
<div class="bg-image bg-image--cover"></div>
</div>
</div>

how to keep the div from overflowing on col-md-12? (bootstrap 3)

Want to keep the image and div below at the same width.
Works fine until I get to around 545px to 575px window size. The .header changes width proportion only at col-md-12. Is there a way to keep the same aspect ratio?
SCREENSHOT
CODEPEN
HTML
<div class="container">
<div class="row">
<div class="first-column col-md-4 col-sm-6 col-xs-12">
<img class="img-responsive" src="https://unsplash.it/500">
<div class="header">header</div>
</div>
<div class="second-column col-md-4 col-sm-6 col-xs-12">
<img class="img-responsive" src="https://unsplash.it/500">
<div class="header">header</div>
</div>
<div class="third-column col-md-4 col-sm-6 col-xs-12">
<img class="img-responsive" src="https://unsplash.it/500">
<div class="header">header</div>
</div>
<!--END ROW-->
</div>
<!--END CONTAINER-->
</div>
CSS
.first-column{background-color: #c0c0c0}
.second-column{background-color: #808080}
.third-column{background-color: #778899}
.header{
background-color:rgba(45,44,89,0.7);
width: 100%;
color: #ffffff;
position: relative;
bottom: 40px;
padding-top: 10px;
padding-bottom: 10px;
text-align: center;
}
The bootstrap .img-responsive class has a max-width:100%; but it doesn't set the width.
So add a width to the class.
.img-responsive {
width: 100%;
}
https://codepen.io/rickydam/pen/XarXYX

Bootstrap responsive column layout stacking columns

I'm building a grid structure and I have changed the bootstrap container classes to new dimension which is working fine. I am currently trying to achieve the layout below and have gotten this far. Each column has a background image. I am trying to put another col-md-3 in the black section but have had no luck. Any suggestions?
My HTML
<div class="container">
<div class="row">
<div class="col-sm-6 col-sx-6 col-md-3 col-lg-3 boats-row">
</div>
<div class="col-md-3 home-row-red">
</div>
<div class="col-md-6 col-sm-12 home-row-big">
</div>
</div>
</div>
CSS
.boats-row {
max-height: 720px;
height: 100%;
height: 720px;
background: url(img/boats.png);
background-size: cover;
}
.home-row-red {
height: 360px;
background: red;
max-height: 360px;
}
.home-row-big {
height: 720px;
max-height: 720px;
background: url(img/panel-large.png);
background-size: cover;
}
And something like this?
<div class="row">
<div class="col-sm-12 col-md-6">
<div class="col-sx-6 col-sm-6 col-md-6 boats-row ">
</div>
<div class="col-sx-6 col-sm-6 col-md-6 home-row-red">
</div>
<div class="col-sx-6 col-sm-6 col-md-6 home-row-blue">
</div>
</div>
<div class="col-md-6 col-sm-12 home-row-big">
</div>
</div>

bootstrap grid to fill page width and height

I have the following 4 squares (two rows and two columns):
<section id="gallery">
<div class="container-fluid">
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
<div style="background-image: url(http://placehold.it/675x400)">
</div>
</div>
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
<div style="background-image: url(http://placehold.it/675x400)">
</div>
</div>
</div>
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
<div style="background-image: url(http://placehold.it/675x400)">
</div>
</div>
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
<div style="background-image: url(http://placehold.it/675x400)">
</div>
</div>
</div>
</div>
</section>
I would like them to be displayed in a 4 square fashion and that the grid takes the whole width and height of the page. I also want it to be responsive and I don't want any spaces between each square.
I tried setting the css on my section tag like this:
section
{
height: 100vh;
}
But that had no effect. Does anybody know how to achieve this please?
Thank you
Try this as the CSS
section#gallery
{
height:100%;
width:100%;
}
div.row
{
height:50%;
}
div.col-lg-6.col-md-6.col-sm-6.col-xs-12
{
width:50%;
}
I think you are looking for something like this? https://jsfiddle.net/01djtnyd/
note: I changed all classes to "-6" so you can see it work easily in the fiddle
add class no-padding to the divs that are wrapping the img div
in the css add this:
.no-padding {
padding: 0 !important;
margin: 0;
}
.no-padding > div {
background-repeat: no-repeat;
background-size: cover;
height: 50vh;
}
You can do this with css flexbox and jQuery. Here are two options to maintain the square shape of each div.
Option 1:
HTML:
<section id="gallery">
<div class="container-fluid">
<div class="row grid-wrapper">
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12 grid-block">
<div style="background-image: url(http://placehold.it/675x400)">
</div>
</div>
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12 grid-block">
<div style="background-image: url(http://placehold.it/675x400)">
</div>
</div>
</div>
<div class="row grid-wrapper">
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12 grid-block">
<div style="background-image: url(http://placehold.it/675x400)">
</div>
</div>
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12 grid-block">
<div style="background-image: url(http://placehold.it/675x400)">
</div>
</div>
</div>
</div>
</section>
CSS:
section
{
height: 100vh;
}
.grid-wrapper{
display: flex;
flex-direction: row;
}
.grid-block{
margin: 0;
padding: 0;
background-color: #e2e2e2;
border: 1px solid #000;
}
Jquery:
$(document).ready(function(){
var grid_w = $(".grid-block").width();
$(".grid-block").height(grid_w);
});
Fiddle: https://jsfiddle.net/puxLmy1y/2/
Option 2 (without jQuery):
HTML: Same as above
CSS:
section
{
height: 100vh;
}
.grid-wrapper{
display: flex;
flex-direction: row;
}
.grid-block{
width: 50vh;
height: 50vh;
margin: 0;
padding: 0;
background-color: #e2e2e2;
border: 1px solid #000;
}
Fiddle: https://jsfiddle.net/puxLmy1y/3/