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
Related
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 the following piece of code and I am use bootstrap 5:
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"/>
<br><br>
<div class="list-group-item d-flex flex-row">
<div class="flex-column">
<h4>A Test Recipe</h4>
<p>This is simply a test</p>
</div>
<div class="flex-row align-self-center justify-content-end">
<img src="https://cdn.pixabay.com/photo/2016/06/15/19/09/food-1459693_1280.jpg"
alt="A Test Recipe"
style="max-height: 50px !important">
</div>
</div>
I'm trying to get the image to the end of list-group-item div. I tried using justify-content-end but this has no effect. I also tried align-self-end this also doesn't bring the image to the right side.
And as for the div with the flex-column class I'm trying to vertically center its content. But it's not working either, it should be centered like the image is. I got the image vertically centered by making use of the align-self-center class. However when I apply this class to the div that has flex-column class it doesn't work.
What am I doing wrong?
؟
<linkhref="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"/>
<div class="list-group-item d-flex justify-content-center align-items-center flex-wrap">
<div class="card m-3 border-0" style="max-width: 250px;">
<div class="row g-0">
<div class="col-5">
<img src="https://cdn.pixabay.com/photo/2016/06/15/19/09/food-1459693_1280.jpg"
class="img-fluid rounded-5"
alt="A Test Recipe">
</div>
<div class="col-7">
<div class="card-body">
<h5 class="card-title">A Test Recipe </h5>
<p class="card-text">This is simply a test.</p>
</div>
</div>
</div>
</div>
</div>
try this.
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"/>
<br><br>
<div class="list-group-item d-flex justify-content-center align-items-center flex-wrap">
<div class="card m-3 border-0" style="max-width: 350px;">
<div class="row g-0">
<div class="col-5">
<img src="https://cdn.pixabay.com/photo/2016/06/15/19/09/food-1459693_1280.jpg"
class="img-fluid rounded-3"
alt="A Test Recipe">
</div>
<div class="col-7">
<div class="card-body">
<h5 class="card-title">A Test Recipe </h5>
<p class="card-text">This is simply a test.</p>
</div>
</div>
</div>
</div>
</div>
This question already has answers here:
Flexbox: center horizontally and vertically
(14 answers)
Bootstrap Center Vertical and Horizontal Alignment
(17 answers)
Closed 1 year ago.
I've got a basic bootstrap grid with two rows and I'm trying to align the content vertically in these cells but no matter what I try the content doesn't seem to budge..
I've tried adding various classes to the rows and container div, i.e. align-middle, align-items-center but nothing seems to do anything.
<div id="header">
<p>< BACK TO HOMEPAGE</p>
</div>
<div id="main-content" style="height:85vh;">
</div>
<div id="menu-bar">
<div class="container-fluid text-center ">
<div class="row border-bottom border-dark">
<div class="col">
Preview text
</div>
<div class="col">
Preview text
</div>
<div class="col">
Preview text
</div>
<div class="col">
Preview text
</div>
<div class="col">
Preview text
</div>
<div class="col col-3">
6
</div>
<div class="col col-2">
7
</div>
<div class="col col-2">
<button type="button" class="btn btn-dark">Play Video</button>
</div>
</div>
<div class="row" style="font-size: smaller;">
<div class="col col-3">
1
</div>
<div class="col">
Preview text
</div>
<div class="col">
Preview text
</div>
<div class="col col-3">
Colour
</div>
<div class="col col-4">
Preview text
</div>
</div>
</div>
</div>
Change
<div class="row border-bottom border-dark">
To
<div class="row border-bottom border-dark align-items-center">
Here's a JSFiddle with that change. I've added a border to each div, so you can see that it is centered vertically. http://jsfiddle.net/bqfa74y0/
If you want the lower row to be centered vertically, just add align-items-center to the class of the row.
I would also strongly recommend that you change:
<p>< BACK TO HOMEPAGE</p>
To
<p>< BACK TO HOMEPAGE</p>
Because < has a special meaning in HTML (it's for starting/ending tags), so using it as text could have unexpected consequences.
Did you mean this?
.menu-bar{
length: 200px;
width: 100%
}
.col{
display: inline-block;
width: 11%;
margin-left: auto;
margin-right: auto;
text-align: center;
height: 50px;
}
<div id="header">
<p> BACK TO HOMEPAGE</p>
</div>
<div id="main-content" style="height:85vh;">
</div>
<div id="menu-bar">
<div class="container-fluid text-center ">
<div class="row border-bottom border-dark">
<div class="col">
Preview text
</div>
<div class="col">
Preview text
</div>
<div class="col">
Preview text
</div>
<div class="col">
Preview text
</div>
<div class="col">
Preview text
</div>
<div class="col col-3">
6
</div>
<div class="col col-2">
7
</div>
<div class="col col-2">
<button type="button" class="btn btn-dark">Play Video</button>
</div>
</div>
<div class="row" style="font-size: smaller;">
<div class="col col-3">
1
</div>
<div class="col">
Preview text
</div>
<div class="col">
Preview text
</div>
<div class="col col-3">
Colour
</div>
<div class="col col-4">
Preview text
</div>
</div>
</div>
</div>
I have a list of header icons in a Stepper inside a container and I am trying to get them to be responsive to the page size changes but it is not working. I have tried to change the place of the container in different div but it did not work.
I am using Bootstrap5
Here is the current output:
I am trying to get the numbers inside the container
here is the template:
<div class="container flex-grow-1 flex-shrink-0 py-5">
<div class="mb-5 p-4 bg-white shadow-sm">
<h1 class="text-center">Plan</h1>
<div id="stepper1" class="bs-stepper">
<div class="bs-stepper-header" role="tablist">
<!-- General Information -->
<div class="step active" data-target="#test-l-1">
<button
type="button"
class="step-trigger"
role="tab"
id="stepper1trigger1"
aria-controls="test-l-1"
aria-selected="true"
>
<span class="bs-stepper-circle">1</span>
<!-- <span class="bs-stepper-label">General Information</span>-->
</button>
</div>
<!-- Summary -->
<div class="step" data-target="#test-l-2">
<button
type="button"
class="step-trigger"
role="tab"
id="stepper1trigger2"
aria-controls="test-l-2"
aria-selected="false"
>
<span class="bs-stepper-circle">2</span>
<!-- <span class="bs-stepper-label">Summary</span>-->
</button>
</div>
</div>
</div>
</div>
You can use col class inside the div with a row class, for each button. It automatically adjusts the width for each button as per the width of the screen. Using col class, each div with button will occupy equal space. In our case since there are 10 button elements, with each occupying 10% of the whole width.
You can do it like this:
HTML:
<div class="container flex-grow-1 flex-shrink-0 py-5">
<div class="mb-5 p-4 bg-white shadow-sm">
<h1 class="text-center">Plan</h1>
<div id="stepper1" class="bs-stepper">
<div class="row mt-5 bs-stepper-header" role="tablist">
<div class="col d-flex justify-content-center" data-target="#test-l-1">
<button type="button" class="step-trigger" role="tab" id="stepper1trigger1" aria-controls="test-l-1" aria-selected="true">
<span class="bs-stepper-circle">1</span>
</button>
</div>
<div class="col d-flex justify-content-center">
<button>2</button>
</div>
<div class="col d-flex justify-content-center">
<button>3</button>
</div>
<div class="col d-flex justify-content-center">
<button>4</button>
</div>
<div class="col d-flex justify-content-center">
<button>5</button>
</div>
<div class="col d-flex justify-content-center">
<button>6</button>
</div>
<div class="col d-flex justify-content-center">
<button>7</button>
</div>
<div class="col d-flex justify-content-center">
<button>8</button>
</div>
<div class="col d-flex justify-content-center">
<button>9</button>
</div>
<div class="col d-flex justify-content-center">
<button>10</button>
</div>
</div>
</div>
</div>
</div>
You can add CSS as well:
button {
border: none;
display: flex;
padding: 5px;
justify-content: center;
align-items: center;
border-radius: 50%;
width: 30px;
height: 30px;
}
You can through the official documentation here for more information about the Bootstrap grid system: https://getbootstrap.com/docs/5.1/layout/grid/
Demo sample: https://codepen.io/Hitesh_Vadher/pen/xxrdYYb
I have an idea for a dashboard which I like to create using Bootstrap. Please find the following image of the layout I would like to achieve using Bootstrap 4.
Layout Image
I can make everything happen but except the left box highlighted in red. Following is my current code and appreciate if anyone could help.
JSFIDDLE
HTML
<div class="d-flex">
<!-- Side Nav Start -->
<ul class="navbar-nav sidebar">
<!-- Nav Item - Dashboard -->
<li class="nav-item active d-flex justify-content-center mt-12" data-toggle="tooltip" data-placement="right" title="Dashboard">
<a class="nav-link" href="#">
Side Menu
</a>
</li>
</ul>
<div class="content-wrapper d-flex flex-column">
<div class="content">
<nav class="navbar navbar-top navbar-expand navbar-light bg-white topbar mb-4 static-top border-bottom">
<!-- Topbar Search -->
<div class="logo mr-auto ml-md-3 my-2 my-md-0 mw-100">Header</div>
</nav>
<div class="container-fluid">
<div class="d-sm-flex align-items-center justify-content-between mb-4">
<h1 class="h3 mb-0 text-gray-800">Dashboard</h1>
</div>
<div class="row">
<div class="col-sm-4 mb-5">
<div class="card">
<div class="card-body">
<h5 class="card-title">Special title treatment</h5>
<p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
Go somewhere
</div>
</div>
</div>
<div class="col-sm-4 mb-5">
<div class="card">
<div class="card-body">
<h5 class="card-title">Special title treatment</h5>
<p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
Go somewhere
</div>
</div>
</div>
<div class="col-sm-4 mb-5">
<div class="card">
<div class="card-body">
<h5 class="card-title">Special title treatment</h5>
<p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
Go somewhere
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
CSS
.navbar-nav {
&.sidebar {
width: 5.6rem !important;
min-height: 100vh;
background-color: #000;
.nav-item {
display: block;
width: 100%;
text-align: left;
margin: 15px 0;
&.active {
.nav-link {
color: #fff;
position: relative;
}
}
&:hover {
.nav-link {
color: #fff;
}
}
.nav-link {
color: #5C6A7C;
}
}
}
}
<div class="bg-info">
<div class="container" style="padding: 20px">
<p>Put your Navbar here </p>
</div>
</div>
<div class="row">
<div class="col col-md-2 bg-warning" style="height: 100vh">
<h4>Side Nav</h4>
</div>
<div class="col col-md-10">
<div class="container">
<!-- for the padding in the main body -->
<!-- an other row and cols for the inner content -->
<h5 class="text-center">Main content</h5>
<br /><br />
<div class="row">
<div class="col col-md-4">
<div class="container bg-danger" style="height: 50vh">
<h4>First Block</h4>
</div>
</div>
<div class="col col-md-4">
<div class="container bg-success" style="height: 50vh">
<h4>First Block</h4>
</div>
</div>
<div class="col col-md-4">
<div class="container bg-primary" style="height: 50vh">
<h4>First Block</h4>
</div>
</div>
</div>
</div>
</div>
</div>
The above code snipet would help.
using .row and .col classes will achieve the purpose.