I'm attempting to create the following (mockup) with Bootstrap
https://i.stack.imgur.com/vkgBu.jpg
The idea is that each of those squares is an image and I'll have Javascript control when they appear/disappear when the background image is clicked. What I'm having trouble with is getting the little squares to stack on top like I have it. I've done research here, tried a bunch of things on my own, but get close but no cigar.
This is the closest I've come (testing with 1 row first).
https://i.stack.imgur.com/mqTc1.jpg
The squares line up next to eachother pretty well however they aren't showing within the same grid column/row correctly.
Relevant HTML:
<div class="container-fluid">
<div class="row-centered">
<div class="row row-centered">
<div class="col-">
<img src="resources/images/grey.jpg" class="character-img" onclick="StockCount();" />
<img src="resources/images/blue.jpg" class="stock-img">
<img src="resources/images/blue.jpg" class="stock-img">
<img src="resources/images/blue.jpg" class="stock-img">
<img src="resources/images/blue.jpg" class="stock-img">
<img src="resources/images/blue.jpg" class="stock-img">
</div>
<div class="col-">
<img src="resources/images/grey.jpg" class="character-img">
</div>
<div class="col-">
<img src="resources/images/grey.jpg" class="character-img">
</div>
<div class="col-">
<img src="resources/images/grey.jpg" class="character-img">
</div>
<div class="col-">
<img src="resources/images/grey.jpg" class="character-img">
</div>
<div class="col-">
<img src="resources/images/grey.jpg" class="character-img">
</div>
</div>
</div>
<div class="row row-centered">
<div class="col- col-centered">
<img src="resources/images/grey.jpg" class="character-img">
</div>
<div class="col-">
<img src="resources/images/grey.jpg" class="character-img">
</div>
<div class="col-">
<img src="resources/images/grey.jpg" class="character-img">
</div>
<div class="col-">
<img src="resources/images/grey.jpg" class="character-img">
</div>
<div class="col-">
<img src="resources/images/grey.jpg" class="character-img">
</div>
<div class="col-">
<img src="resources/images/grey.jpg" class="character-img">
</div>
</div>
</div>
CSS:
.character-img{
position: relative;
z-index: 10;
}
.stock-img{
position: relative;
z-index: 20;
}
EDIT:
Updated version yields slightly better results? Included adding the blue boxes to the second row.
HTML
<div class="container-fluid">
<div class="row-centered">
<div class="row row-centered">
<div class="col-2">
<img src="resources/images/grey.jpg" class="character-img" onclick="StockCount();" />
<img src="resources/images/blue.jpg" class="stock-img">
<img src="resources/images/blue.jpg" class="stock-img">
<img src="resources/images/blue.jpg" class="stock-img">
<img src="resources/images/blue.jpg" class="stock-img">
<img src="resources/images/blue.jpg" class="stock-img">
</div>
<div class="col-2">
<img src="resources/images/grey.jpg" class="character-img">
</div>
<div class="col-2">
<img src="resources/images/grey.jpg" class="character-img">
</div>
<div class="col-2">
<img src="resources/images/grey.jpg" class="character-img">
</div>
<div class="col-2">
<img src="resources/images/grey.jpg" class="character-img">
</div>
<div class="col-2">
<img src="resources/images/grey.jpg" class="character-img">
</div>
</div>
</div>
<div class="row-centered">
<div class="row row-centered">
<div class="col-2">
<img src="resources/images/grey.jpg" class="character-img" onclick="StockCount();" />
<img src="resources/images/blue.jpg" class="stock-img">
<img src="resources/images/blue.jpg" class="stock-img">
<img src="resources/images/blue.jpg" class="stock-img">
<img src="resources/images/blue.jpg" class="stock-img">
<img src="resources/images/blue.jpg" class="stock-img">
</div>
<div class="col-2">
<img src="resources/images/grey.jpg" class="character-img">
</div>
<div class="col-2">
<img src="resources/images/grey.jpg" class="character-img">
</div>
<div class="col-2">
<img src="resources/images/grey.jpg" class="character-img">
</div>
<div class="col-2">
<img src="resources/images/grey.jpg" class="character-img">
</div>
<div class="col-2">
<img src="resources/images/grey.jpg" class="character-img">
</div>
</div>
</div>
</div>
CSS
.character-img{
position: relative;
z-index: 10;
}
.stock-img{
position: relative;
z-index: 20;
}
Result: https://imgur.com/vd3IZsP
Based on the images you've shown us to depict your desired outcome, I think Bootstrap is a smart choice. Much of what you want to do in your layout can be achieved using native classes. But it's also pretty apparent that you lack a fundamental understanding of the Bootstrap Framework, and I would strongly encourage you to revisit their documentation.
A full example of the structure you're trying to achieve can be viewed at: https://www.bootply.com/SwuSKmlKWe
But let's look at the HTML of a single 'box' item:
<div class="col-6 col-md-4 col-lg-3 mb-4">
<div class="h-100 bg-secondary p-4">
<img src="//placehold.it/200x200" class="rounded-circle img-fluid d-block mx-auto" />
<div class="row mt-4">
<div class="col-3 text-center mb-2"><img src="//placehold.it/50x50" class="img-fluid" /></div>
<div class="col-3 text-center mb-2"><img src="//placehold.it/50x50" class="img-fluid" /></div>
<div class="col-3 text-center mb-2"><img src="//placehold.it/50x50" class="img-fluid" /></div>
<div class="col-3 text-center mb-2"><img src="//placehold.it/50x50" class="img-fluid" /></div>
<div class="col-3 text-center mb-2"><img src="//placehold.it/50x50" class="img-fluid" /></div>
<div class="col-3 text-center mb-2"><img src="//placehold.it/50x50" class="img-fluid" /></div>
<div class="col-3 text-center mb-2"><img src="//placehold.it/50x50" class="img-fluid" /></div>
<div class="col-3 text-center mb-2"><img src="//placehold.it/50x50" class="img-fluid" /></div>
</div>
</div>
</div>
The first <div> element is a column wrapper that supplies information on the breakpoints that will affect the display. From left to right it is written with the smallest breakpoint (col-*) to the largest. If we were to translate this to something readable it might read:
At the smallest breakpoint use 6/12 columns. At the medium breakpoint
begin using 4/12 columns, and at the large breakpoint use 3/12
columns.
Note: col-sm-* exists but was not used here. Because a 'small' breakpoint was not used Bootstrap will default to the next smallest (in this case col-6
Inside the column wrapper we have another wrapper with several classes:
.h-100 helps us create equal-height items regardless of whether the
content dictates a smaller height.
.bg-secondary is a utility class that provides the dark background color
.p-4 is a utility class that provides padding on both the X and Y margins (4 indicates the 'level' of padding and can be as low as 0 and as high as 5)
At this point we start seeing the actual content. Your primary image has several classes that affect its shape and its position:
.rounded-circle is an image thumbnail class that forces a circular border radius.
.img-fluid is a responsive class that helps the image size up and down proportional to the element in which it resides.
.d-block transforms the img into a block-level element
.mx-auto sets the X margins to 'auto' which, in combination with d-block, centers the image.
From here we reach the 8 button/images referenced in your original post. The Bootstrap Grid is the perfect solution for this sort of organization, but since we're already working with content inside a Grid Element we need to create a new .row.
Inside the new .row we have a single breakpoint column (.col-3) with a couple of utility classes: text-center centers the content and mb-2 sets the bottom margin in a similar way that the p-* utility class alters padding.
Related
I have this Bootstrap 5 code that shows some images like in this link in a grid, the images are affected by a few CSS code.
#projects img {
width: 100%;
height: 100%;
}
<section id="projects">
<div class="container text-center">
<h4 class="fw-bold mb-3 border-bottom border-3">Mis Proyectos</h4>
<div class="row g-4">
<div class="col-md-6">
<img
src="./images/cardcomponent.png"
alt="card component"
class="rounded-3"
>
</div>
<div class="col-md-6">
<img
src="./images/yardsale.png"
alt="yard sale"
class="rounded-3"
>
</div>
<div class="col-md-6">
<img
src="./images/qrcard.png"
alt="web developer"
class="qr card"
>
</div>
<div class="col-md-6">
<img
src="./images/cardcomponent.png"
alt="web developer"
class="rounded-3"
>
</div>
</div>
</div>
</section>
I want to add a title <h6></h6> to each image.
<div class="col-md-6">
<h6>Title</h6>
<img
src="./images/cardcomponent.png"
alt="card component"
class="rounded-3"
>
</div>
But for some reason, the title isn't included or recognized in the column, showing something like this, while this is similar to what i want to do.
#Emiliano Acevedo, Thanks to draw attention to the bug of bootstrap, I am sure the team must get those alignment issue fixed for row column.
Here's quick fix for the issue. <div class="row g-4 align-items-end"> You can fix the issue with adding item alignment in the row element.
I hope this helps.
CodePen Example
Div with text-center class makes all the text align at the center inside of it. But since you just want your <h4> tag align at the center only, just remove the text-center class from that div and add it to the <h4> tag. Once you do that, your <h6> tag inside of your column will work as you intended. Like:
#projects img {
width: 100%;
height: 100%;
}
<section id="projects">
<div class="container">
<h4 class="text-center fw-bold mb-3 border-bottom border-3">Mis Proyectos</h4>
<div class="row g-4">
<div class="col-md-6">
<h6>Title 1</h6>
<img src="./images/cardcomponent.png" alt="card component" class="rounded-3">
</div>
<div class="col-md-6">
<h6>Title 2</h6>
<img src="./images/yardsale.png" alt="yard sale" class="rounded-3">
</div>
<div class="col-md-6">
<h6>Title 3</h6>
<img src="./images/qrcard.png" alt="web developer" class="qr card">
</div>
<div class="col-md-6">
<h6>Title 4</h6>
<img src="./images/cardcomponent.png" alt="web developer" class="rounded-3">
</div>
</div>
</div>
</section>
Now, there is a white space in the bottom part of the left column. Or the right column exceeds the baseline.
enter image description here
<section class="courses">
<div class="container-fluid">
<!-- Gallery -->
<div class="row g-0">
<div class="col-lg-5 col-md-12">
<h2 class="p-3 text-center text-white">Courses</h2>
<img src="./img/courses1.png" class="w-100" alt=""/>
<img src="./img/courses3.png" class="w-100" alt=""/>
<img src="./img/courses6.png" class="w-100" alt=""/>
<h4 class="p-3 text-center text-white">Get The Best Training</h4>
</div>
<div class="col-lg-7">
<img src="./img/courses2.png" class="w-100" alt="" />
<h4 class="p-3 text-center text-white">Get The Best Training</h4>
<div class="row g-0">
<div class="col-lg-6">
<img src="./img/courses4.png" class="w-100" alt=""/>
</div>
<div class="col-lg-6">
<img src="./img/courses5.png" class="w-100" alt="" />
</div>
</div>
<img src="./img/courses6.png" class="w-100" alt=""/>
</div>
</div>
<!-- Gallery -->
</div>
</section>
I am new to bootstrap and I'm stuck on the following problem:
In mobile, I want "big-guy" to occupy the whole width and the "small-guys" to be evenly positioned underneath it. So far so good.
The problem is: in medium displays, I want the "big-guy" to occupy 75% of the width and the small-guys should be placed on its left, stacked on top of each other.
So far, this is the code I have, I would like to keep this structure if possible.
<div class="row">
<div id="big-guy" class="col-sm-12"></div>
<div id="small-guy-1" class="col-sm-4"></div>
<div id="small-guy-2" class="col-sm-4"></div>
<div id="small-guy-3" class="col-sm-4"></div>
</div>
Image for reference:
You would use nesting and the appropriate responsive grid sizes...
<div class="row">
<div id="big-guy" class="col-sm-9 py-sm-0 py-3">
</div>
<div class="col-sm-3">
<div class="row">
<div id="small-guy-1" class="col-4 col-sm-12">
</div>
<div id="small-guy-2" class="col-4 col-sm-12 py-sm-4 py-0">
</div>
<div id="small-guy-3" class="col-4 col-sm-12">
</div>
</div>
</div>
</div>
Responsive demo
Here it is.
<div class="container">
<div class="row">
<div class="col-md-9 pt-5">
<img class="img-fluid pb-3" src="https://cdn.pixabay.com/photo/2019/12/26/11/04/new-years-day-4720210_960_720.jpg" title="" alt="">
</div>
<div class="col-md-3">
<div class="row pt-5">
<div class="col-4 col-md-12 col-sm-4">
<img class="img-fluid pb-3" src="https://cdn.pixabay.com/photo/2013/02/21/19/14/firecracker-84715_960_720.jpg" title="" alt="">
</div>
<div class="col-4 col-md-12 col-sm-4">
<img class="img-fluid pb-3" src="https://cdn.pixabay.com/photo/2013/02/21/19/14/firecracker-84715_960_720.jpg" title="" alt="">
</div>
<div class="col-4 col-md-12 col-sm-4">
<img class="img-fluid pb-3" src="https://cdn.pixabay.com/photo/2013/02/21/19/14/firecracker-84715_960_720.jpg" title="" alt="">
</div>
</div>
</div>
</div>
</div>
When adding the bootstrap class "img-fluid" to my images they don't appear, when inspecting the element it sets the image at 0x0 pixels.
The html:
<div class="col">
<div class="row no-gutters">
<div class="col">
<img src="assets/images/placeholder.png" class="img-fluid"
alt="placeholder">
</div>
<div class="col">
<img src="assets/images/placeholder.png" class="img-fluid" alt="placeholder">
</div>
<div class="w-100"></div>
<div class="col">
<img src="assets/images/placeholder.png" class="img-fluid" alt="placeholder">
</div>
<div class="col">
<img src="assets/images/placeholder.png" class="img-fluid" alt="placeholder">
</div>
</div>
</div>
The images are supposed to be the same size as the parent(div.col) and be responsive to the parent.
Here's an answer based on my comment.
Because you have a .col element as a child of a flex parent, the flex-basis is set to 0. That basically equates to width: 0.
To get around that, set the flex-basis to auto on the .col that are children of the .row element.
.row>.col {
flex-basis: auto;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" />
<div class="col">
<div class="row no-gutters">
<div class="col">
<img src="https://placehold.it/100x100" class="img-fluid" alt="placeholder">
</div>
<div class="col">
<img src="https://placehold.it/100x100" class="img-fluid" alt="placeholder">
</div>
<div class="w-100"></div>
<div class="col">
<img src="https://placehold.it/100x100" class="img-fluid" alt="placeholder">
</div>
<div class="col">
<img src="https://placehold.it/100x100" class="img-fluid" alt="placeholder">
</div>
</div>
</div>
I'm using bootstrap and I have a row with 1 column and another row with 2 columns.
All items have one picture in it, and should take up all the avaible space inside the column.
So far I can't get the first image on the first row to fill the div width,this image resizes correctly when I reduce the window, but when I enlarge it, the picture will
resize to its original maximum size when I want it to be always same as the div width
Here is the snippet : https://jsfiddle.net/gd0obgg9/
Here is the code :
<body>
<div class="container">
<div class="row">
<div class="col-lg-12">
<h1 class="page-header">Portfolio Item
</h1>
</div>
</div>
<div class="row">
<div></div>
<div class="col-md-12">
<img class="img-responsive" src="http://placehold.it/550x200" alt="">
</div>
<div></div>
</div>
<div class="row">
<hr>
<div class="col-sm-6 col-xs-12">
<a href="#">
<img class="img-responsive portfolio-item" src="http://placehold.it/300x300" alt="">
</a>
</div>
<div class="col-sm-6 col-xs-12">
<a href="#">
<img class="img-responsive portfolio-item" src="http://placehold.it/300x300" alt="">
</a>
</div>
</div>
</div>
</body>
I want my 550x200 to fill enterely the width
Any advice ? thanks
If I understood you correctly, to give the image full width use:
.img-responsive {
width: 100%;
}
Note that this will, in some cases, distort the image to cover the full div
In my test:
Update your css to set the width of img elements inside your columns to 100%.
you should add width:100% to your img
here the new code
<body>
<!-- Page Content -->
<div class="container">
<!-- Portfolio Item Heading -->
<div class="row">
<div class="col-lg-12 col-xs-12 col-md-12">
<h1 class="page-header">Portfolio Item
<small>Item Subheading</small>
</h1>
</div>
</div>
<!-- /.row -->
<!-- Portfolio Item Row -->
<div class="row">
<div>
</div>
<div class="col-md-12">
<img class="img-responsive" style="width:100%" src="http://placehold.it/550x200" alt="">
</div>
<div>
</div>
</div>
<!-- /.row -->
<!-- Related Projects Row -->
<div class="row">
<hr>
<div class="col-sm-6 col-xs-12">
<a href="#">
<img class="img-responsive portfolio-item" src="http://placehold.it/300x300" alt="">
</a>
</div>
<div class="col-sm-6 col-xs-12">
<a href="#">
<img class="img-responsive portfolio-item" src="http://placehold.it/300x300" alt="">
</a>
</div>
</div>
</div>
</body>