I'm currently messing a bit around with the bootstrap grid system, I kinda get to understand it, but if I change the width of the elements inside a col, then it's overlapping when I resize the browser.
Just trying to make cards responsive when resizing the browser, but I want to change the size of the cards aswell without making them overlap.
This is how it looks like when I change the width
This is how it's supposed to look like
that's how I do it right now:
<main>
<div class="container-fluid">
<div class="row">
<div class="col-xl-4">
<div class="card card-cascade dashboard-card bg-lightblue">
<div class="data mt-4 ml-3">
<div class="button px-2">
<a class="btn-floating btn-lg float-right"><i class="fas fa-thumbs-down"></i></a>
</div>
<h4 class="text-white mb-2">1</h4>
<p class="text-white">Test Card</p>
</div>
</div>
</div>
<div class="col-xl-4">
<div class="card card-cascade dashboard-card bg-lightblue">
<div class="data mt-4 ml-3">
<div class="button px-2">
<a class="btn-floating btn-lg float-right"><i class="fas fa-thumbs-up"></i></a>
</div>
<h4 class="text-white mb-2">0</h4>
<p class="text-white">Test Card 2</p>
</div>
</div>
</div>
<div class="col-xl-4">
<div class="card card-cascade dashboard-card bg-lightblue">
<div class="data mt-4 ml-3">
<div class="button px-2">
<a class="btn-floating btn-lg float-right"><i class="fas fa-ticket"></i></a>
</div>
<h4 class="text-white mb-2">0</h4>
<p class="text-white">Test Card 3</p>
</div>
</div>
</div>
</div>
</div>
</main>
Kinda stuck on that.
Thanks for any help.
Give col-xl-4 class:
width of (94/3)%
padding left of 1%
padding right of 1%
Give container-fluid class:
padding left of 20px
padding right of 20px
Related
I've been trying to implement a container where I have 4 images side-by-side, and a button under each of them. When the screen's size changes, the "items" inside should be responsive and keep the button along with them. This is what I have until now:
<pre><code>
<div class="container-md">
<div class="row">
<div class="col-md-3">
<img src="img1.png">
<button class="btn mt-2 btn-secondary">Button 1</button>
</div>
<div class="col-md-3">
<img src="img2.png"">
<button class="btn mt-2 btn-secondary">Button 2</button>
</div>
<div class="col-md-3">
<img src="img3.png">
<button class="btn mt-2 btn-secondary">Button 3</button>
</div>
<div class="col-md-3">
<img src="img4.png">
<button class="btn mt-2 btn-secondary">Button 4</button>
</div>
</div>
</div>
</code></pre>
It should behave as the drawings below:
Big screen size:
Medium screen size
Small screen size
But, in my code, the images are way too big, the buttons are on the same line as the images and it's not responsive at all (used emoji images as examples):
I know I should resize the images first, but I've tried many ways and I'm not sure which one is the most appropriate.
Also, styling tips are very welcome
With Bootstrap classes, perhaps start by try adding img-fluid class to img so that the images can scale with the parent width.
Also, try define some responsive classes for col, such as col-sm-6, col-md-6 and col-lg-3 classes, so that the column placement of div changes with the viewport width.
If the button need to fill the width of parent div, try wrap it with a div with d-grid as recommended by the Bootstrap document.
Lastly, perhaps consider to add a vertical gutter in Bootstrap by also adding a gy-3 class to the div as row, so that there will be spaces between the elements when wrapped.
Example with the modifications: (changed the src to use dummy images)
<link
href="https://cdn.jsdelivr.net/npm/bootstrap#5.2.3/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65"
crossorigin="anonymous"
/>
<div class="container-md">
<div class="row gy-3">
<div class="col-sm-6 col-md-6 col-lg-3">
<img src="https://picsum.photos/1000?random=1" class="img-fluid" />
<div class="d-grid">
<button class="btn mt-2 btn-secondary">Button 1</button>
</div>
</div>
<div class="col-sm-6 col-md-6 col-lg-3">
<img src="https://picsum.photos/1000?random=2" class="img-fluid" />
<div class="d-grid">
<button class="btn mt-2 btn-secondary">Button 2</button>
</div>
</div>
<div class="col-sm-6 col-md-6 col-lg-3">
<img src="https://picsum.photos/1000?random=3" class="img-fluid" />
<div class="d-grid">
<button class="btn mt-2 btn-secondary">Button 3</button>
</div>
</div>
<div class="col-sm-6 col-md-6 col-lg-3">
<img src="https://picsum.photos/1000?random=4" class="img-fluid" />
<div class="d-grid">
<button class="btn mt-2 btn-secondary">Button 4</button>
</div>
</div>
</div>
</div>
I have some HTML/CSS where I am trying to make use of Bootstrap 5.2 and justify-content-between to push 2 buttons out to the edges of the container.
<div class="container">
<div class="row">
<div class="col-12">
<ul class="d-flex justify-content-center align-items-center bg-grey">
<li>Test</li>
</ul>
</div>
<div class="col-12">
<div class="row justify-content-between">
<div class="col-2 text-start">
<button class="btn btn-primary btn-lg">LEFT</button>
</div>
<div class="col-2 text-end">
<button class="btn btn-primary btn-lg">RIGHT</button>
</div>
</div>
</div>
</div>
</div>
This is how I want it to look - with the LEFT and RIGHT buttons aligned to the edges.
It's fine until the viewport reaches anything under 768px wide (sm or xs), at which point the RIGHT button sticks out.
I can tweak the margin at the relevant responsive break points but it seems like I've got something wrong and shouldn't have to do that.
Is there a correct / better way to achieve this?
With your second attempt, you had rows inside of rows. The rows need to be direct children of the container.
I'd probably just use some explicit flex boxes here if you don't need the column collapsing provided by Bootstrap grids:
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.0.2/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="col-12">
<div class="d-flex flex-column">
<ul style='background:grey' class="d-flex justify-content-center align-items-center bg-grey">
<li>Test</li>
</ul>
</div>
<div class="d-flex justify-content-between">
<button class="btn btn-primary btn-lg">LEFT</button>
<button class="btn btn-primary btn-lg">RIGHT</button>
</div>
</div>
</div>
</div>
A flex-box column to stack them, then a flex-box row for the buttons. The current .container element isn't really necessary, but it maintains the padding you had.
You can try this :
<div class="container">
<div class="row">
<div class="col-12">
<ul class="d-flex justify-content-center align-items-center bg-dark">
<li>Test</li>
</ul>
</div>
<div class="col-12">
<div class="row justify-content-between">
<div class="col text-start">
<button class="btn btn-primary btn-lg">LEFT</button>
</div>
<div class="col text-end">
<button class="btn btn-primary btn-lg">RIGHT</button>
</div>
</div>
</div>
</div>
</div>
I have 2 "contents" in their divs next to each other. 1) is a slim categorized link list with buttons loading the content on 2). When there is nothing loaded yet on 2) it shows you an overview of the same listed items in 1) with little more information as cards.
Now, after I am having so many buttons I need to show in 1), I made the list scroll-able and added jump-to buttons, so that the user doesn't have to scroll to the bottom to reach the last category of the list. Logically 2) is scroll-able as well, as this is the main content of the site, respectively showing the big cards as an overview.
How do I realize to have the jump-to buttons working for both scroll-able divs at once? And is there maybe a solution without js, since I have absolutely no idea about js coding?
The only thing I am getting to work is only one of both divs jump-to-able
Btw. I am using bootstrap 5.2 . But unfortunately I didn't find a solution to that problem in their docs either :/
I also tried the documented anchors via scrollspy without success ( https://getbootstrap.com/docs/5.2/components/scrollspy/#usage )
Thank you very much in advance for any help!
in CodePen
https://codepen.io/KeenaBiacym/pen/qBYaLVQ
The scroll list
<div id="content">
<div class="container p-5 pt-3">
<div class="gallery d-flex">
<v class="btncontainer gallery nav justify-content-end">
<div class="scrollbar stickynator gallery">
<div class="slidebtn_galtab active" id="tab0" data-bs-toggle="tab" data-bs-target="#tab0-pane" type="button" role="tab" aria-controls="tab0-pane" aria-selected="true">
Overview
</div>
<div class="text-center pt-4">
▼ Category2 ▼
</div>
<h3 class="pt-4 text-center content-title" id="content_cat1">Category1</h3>
<div class="slidebtn_galtab mt-3" id="tab1" data-bs-toggle="tab" data-bs-target="#tab1-pane" type="button" role="tab" aria-controls="tab1-pane" aria-selected="false" style="width:400px">
Title1
</div>
<div class="slidebtn_galtab mt-3" id="tab2" data-bs-toggle="tab" data-bs-target="#tab1-pane" type="button" role="tab" aria-controls="tab1-pane" aria-selected="false" style="width:400px">
Title2
</div>
<br><br><br><br>
<h3 class="pt-4 text-center content-title" id="content_cat2">Category2</h3>
<div class="slidebtn_galtab mt-3" id="tab3" data-bs-toggle="tab" data-bs-target="#tab1-pane" type="button" role="tab" aria-controls="tab1-pane" aria-selected="false" style="width:400px">
Title1
</div>
<div class="slidebtn_galtab mt-3" id="tab4" data-bs-toggle="tab" data-bs-target="#tab1-pane" type="button" role="tab" aria-controls="tab1-pane" aria-selected="false" style="width:400px">
Title2
</div>
<div class="text-center pt-4">
▲ Category1 ▲
</div>
</div>
Content
<div class="tab-content container" id="TabContent">
<!-- CONTENT 0 -->
<div class="tab-pane fade active show" id="tab0-pane" role="tabpanel" aria-labelledby="tab0" tabindex="0">
<div class="container" id="content_cat1"><h3 class="pb-3 text-center content-title">Category1</h3>
<div class="row row-cols-1 row-cols-md-3 g-4 allcards">
<div class="col" id="gallerytablink1">
<div class="card mozoom h-100">
<div class="card-img-top moopacity cardsoverview">
<img src="https://images.unsplash.com/photo-1665597652829-bf80107d7045?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MnwzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2NjYwOTgzNDI&ixlib=rb-1.2.1&q=80&w=400" class="card-img-top">
</div>
<div class="card-body">
<h5 class="card-title">Title1</h5>
<p class="card-text">Subtitle1</p>
</div>
<div class="card-footer">
<small class="text-muted">img1desc</small>
</div>
</div>
</div>
<div class="col" id="gallerytablink2">
<div class="card mozoom h-100">
<div class="card-img-top moopacity cardsoverview">
<img src="https://images.unsplash.com/photo-1665597652829-bf80107d7045?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MnwzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2NjYwOTgzNDI&ixlib=rb-1.2.1&q=80&w=400" class="card-img-top">
</div>
<div class="card-body">
<h5 class="card-title">Title2</h5>
<p class="card-text">Subtitle2</p>
</div>
<div class="card-footer">
<small class="text-muted">img2desc</small>
</div>
</div>
</div>
</div>
<div class="container" id="content_cat2"><h3 class="pb-3 text-center content-title">Category2</h3>
<div class="row row-cols-1 row-cols-md-3 g-4 allcards">
<div class="col" id="gallerytablink3">
<div class="card mozoom h-100">
<div class="card-img-top moopacity cardsoverview">
<img src="https://images.unsplash.com/photo-1665597652829-bf80107d7045?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MnwzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2NjYwOTgzNDI&ixlib=rb-1.2.1&q=80&w=400" class="card-img-top">
</div>
<div class="card-body">
<h5 class="card-title">Title1</h5>
<p class="card-text">Subtitle1</p>
</div>
<div class="card-footer">
<small class="text-muted">img1desc</small>
</div>
</div>
</div>
<div class="col" id="gallerytablink4">
<div class="card mozoom h-100">
<div class="card-img-top moopacity cardsoverview">
<img src="https://images.unsplash.com/photo-1665597652829-bf80107d7045?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MnwzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2NjYwOTgzNDI&ixlib=rb-1.2.1&q=80&w=400" class="card-img-top">
</div>
<div class="card-body">
<h5 class="card-title">Title2</h5>
<p class="card-text">Subtitle2</p>
</div>
<div class="card-footer">
<small class="text-muted">img2desc</small>
</div>
</div>
</div>
I have this piece of code:
<div class="container">
<div class="border rounded-lg" style="height:500px;">
<div class="ml-2 mt-2">
<h1 class="display-3">#Model.Name</h1>
<!-- Image and pay box -->
<div class="mt-4 container">
<img src="~/Resources/default.jpg" class="" style="height:300px;" />
<div class="d-inline align-top float-right border rounded-lg" style="height:250px;width:250px;">
#if (!Model.OnSale)
{
<h3 class="mt-2 text-nowrap text-center text-warning">#Model.Price</h3>
}
else
{
<div class="row">
<div class="col-2 text-center">
<div class="text-secondary font-italic" style="text-align:center;"><s>#Model.PriceBeforeDiscount</s></div>
<div class="mt-2 text-nowrap text-warning">#Model.Price</div>
</div>
</div>
}
<button class="btn btn-success text-white text-center font-weight-bold w-100 mt-3">
BUY NOW
</button>
given a model, it looks like
I want to center both price texts (the ones on the right), but for some reason, it will refuse to use "text-center", any ideas on how I can solve this? (the # sign is just from Razor syntax, it's the variables it displays)
The text prices are center aligned in your code but they're being constrained by the column width
col-2 should be col-12_ thus:
#if (!Model.OnSale)
{
<h3 class="mt-2 text-nowrap text-center text-warning">#Model.Price</h3>
}
else
{
<div class="row">
<div class="col-12 text-center">
<div class="text-secondary font-italic"><s>#Model.PriceBeforeDiscount</s></div>
<div class="mt-2 text-nowrap text-warning">#Model.Price</div>
</div>
</div>
}
I can't recreate the code here but have tested it locally and col-12 appears to solve the problem
Have you tried <div class="row d-flex justify-content-center"></div>
This should work
I need your help in the following case - I just cant figure out a clean and simple way to solve it.
I want to realize the following design:
3 Boxes with content and overlapping buttons
But i struggle with pushing the buttons out of the divs because it expands the main div or I cant get them centered / positioned properly in mobile views. My current code looks like this (based on bootstrap 4 grid) (Light blue background is applied at the div with container-fluid class in the 2nd row)
<section id="threeblocks" class="">
<div class="container-fluid">
<div class="container">
<div class="row">
<div class="col p-5 d-flex flex-column">
<h3 class="pb-2">HEADLINE</h3> Content goes here
<a class="btn btn-darkblue align-self-baseline" href="#" role="button">Mehr erfahren</a></div>
<div class="col p-5 d-flex flex-column">
<h3 class="pb-2">HEADLINE</h3> Content goes here
<a class="btn btn-darkblue align-self-baseline" href="#" role="button">Mehr erfahren</a></div>
<div class="col p-5 d-flex flex-column">
<h3 class="pb-2">HEADLINE</h3> Content goes here
<a class="btn btn-darkblue align-self-baseline" href="#" role="button">Mehr erfahren</a></div>
</div>
</div>
</div>
</section>
I was thinking about adding three aditional cols underneath the div with the background, but then there are problems with responsive views, where the buttons should be in the boxes again and not underneath all three off them.
So this dirty solution would look like this:
<section id="threeblocks" class="">
<div class="container-fluid">
<div class="container">
<div class="row">
<div class="col p-5 d-flex flex-column">
<h3 class="pb-2">HEADLINE</h3> Content goes here
</div>
<div class="col p-5 d-flex flex-column">
<h3 class="pb-2">HEADLINE</h3> Content goes here
</div>
<div class="col p-5 d-flex flex-column">
<h3 class="pb-2">HEADLINE</h3> Content goes here
</div>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col"><a class="btn btn-darkblue align-self-baseline pushback" href="#" role="button">Mehr erfahren</a></div>
<div class="col"><a class="btn btn-darkblue align-self-baseline pushback" href="#" role="button">Mehr erfahren</a></div>
<div class="col"><a class="btn btn-darkblue align-self-baseline pushback" href="#" role="button">Mehr erfahren</a></div>
</div>
</div>
</section>
So any idea how to get them to this position where I can change the position for different breakpoints?
Thanks in advance!
Here's a solution, where the buttons are inside the three boxes, but have absolute positioning that forces them to spill outside the bottom of the div by around half.
<section id="threeblocks" class="">
<div class="container-fluid">
<div class="container">
<div class="row">
<div id="box1" class="col p-5 d-flex flex-column headlineBox">
<h3 class="pb-2">HEADLINE</h3> Content goes here
<button>lorem ipsum</button>
</div>
<div id="box2" class="col p-5 d-flex flex-column headlineBox">
<h3 class="pb-2">HEADLINE</h3> Content goes here
<button>lorem ipsum</button>
</div>
<div id="box3" class="col p-5 d-flex flex-column headlineBox">
<h3 class="pb-2">HEADLINE</h3> Content goes here
<button>lorem ipsum</button>
</div>
</div>
</div>
</div>
</section>
CSS
.headlineBox button{
background-color: #466f75;
color: #fff;
position: absolute;
bottom: -10px;
margin:0 auto;
display:block;
}
#box1{
background-color: #e6f4f6;
}
#box2{
background-color: #d8eef1;
}
#box3{
background-color: #e6f4f6;
}
Codepen https://codepen.io/Washable/pen/bYwGzR