I am using Bootstrap and I have an image, and I want to have the card on the right of the image, but it is at the bottom.
I tried using display: inline-block, but that did not work. I looked at the other answers on the site and they did not work for me either, so please don't recommend those.
<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">
<h1 style="text-align: center; font-size: 70px; ">Crabapple Lake Parc</h1>
<img src="https://th.bing.com/th/id/R.bb60507b5a1f567e6b6592f375bf5e8d?rik=FgkA6Taf%2fHwJsA&pid=ImgRaw&r=0" alt="Group Picture" style="display: block; margin-left: auto; margin-right: auto; width: 50%;">
<div class="card" style="width: 18rem;">
<div class="card-body">
<h5 class="card-title">Have Questions?</h5>
FAQ
Contact Us
</div>
</div>
To have a card next to the image using Bootstrap, you can use the grid system. In the code below, the col-md-4 class is used to specify that the image will take up four columns out of a possible twelve, and the col-md-8 class is used to specify that the card will take up the remaining eight columns. If you find that the card is appearing below the image, it may be because the image is too wide for the column. To fix this, you can add the img-fluid class to the image to ensure that it is responsive and will fit within the column.
<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">
<h1 style="text-align: center; font-size: 70px; ">Crabapple Lake Parc</h1>
<div class="container">
<div class="row">
<div class="col-md-4">
<img src="https://th.bing.com/th/id/R.bb60507b5a1f567e6b6592f375bf5e8d?rik=FgkA6Taf%2fHwJsA&pid=ImgRaw&r=0" class="img-fluid" alt="Group Picture">
</div>
<div class="col-md-8">
<div class="card">
<div class="card-body">
<h5 class="card-title">Have Questions?</h5>
FAQ
Contact Us
</div>
</div>
</div>
</div>
</div>
<h1 style="text-align: center; font-size: 70px;">Crabapple Lake Parc</h1>
<div class="row">
<div class="col-md-6">
<img src="https://th.bing.com/th/id/R.bb60507b5a1f567e6b6592f375bf5e8d?rik=FgkA6Taf%2fHwJsA&pid=ImgRaw&r=0" alt="Group Picture" style="display: block; margin-left: auto; margin-right: auto; width: 100%;">
</div>
<div class="col-md-6">
<div class="card" style="width: 18rem;">
<div class="card-body">
<h5 class="card-title">Have Questions?</h5>
FAQ
Contact Us
</div>
</div>
</div>
</div>
In your parent element you can use these styles
display: flex;
justify-content: space-between;
Or in Bootstrap: d-flex and justify-content-between classes:
<div class="d-flex justify-content-between">
<h1 style="text-align: center; font-size: 70px; ">Crabapple Lake Parc</h1>
<img src="https://th.bing.com/th/id/R.bb60507b5a1f567e6b6592f375bf5e8d?rik=FgkA6Taf%2fHwJsA&pid=ImgRaw&r=0" alt="Group Picture" style="display: block; margin-left: auto; margin-right: auto; width: 50%;">
<div class="card" style="width: 18rem;">
<div class="card-body">
<h5 class="card-title">Have Questions?</h5>
FAQ
Contact Us
</div>
</div>
</div>
WITH TITLE IN THE TOP:
<h1 style="text-align: center; font-size: 70px; ">Crabapple Lake Parc</h1>
<div class="d-flex justify-content-between">
<img src="https://th.bing.com/th/id/R.bb60507b5a1f567e6b6592f375bf5e8d?rik=FgkA6Taf%2fHwJsA&pid=ImgRaw&r=0" alt="Group Picture" style="display: block; margin-left: auto; margin-right: auto; width: 50%;">
<div class="card" style="width: 18rem;">
<div class="card-body">
<h5 class="card-title">Have Questions?</h5>
FAQ
Contact Us
</div>
</div>
</div>
You could* use .d-inline-block if it is appropriate for your layout. You need to use it on both the img and the .card.
*I'm not necessarily recommending this, but it does what you ask.
<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">
<h1 style="text-align: center; font-size: 70px; ">Crabapple Lake Parc</h1>
<img class="d-inline-block w-50" src="https://th.bing.com/th/id/R.bb60507b5a1f567e6b6592f375bf5e8d?rik=FgkA6Taf%2fHwJsA&pid=ImgRaw&r=0" alt="Group Picture">
<div class="card d-inline-block" style="width: 18rem;">
<div class="card-body">
<h5 class="card-title">Have Questions?</h5>
FAQ
Contact Us
</div>
</div>
Related
This question already has answers here:
Bootstrap Center Vertical and Horizontal Alignment
(17 answers)
Closed 2 years ago.
I have a problem. I have to cards (please see the picture )
As you can see, the two card boxes are not in the middle. I tried something, please see the code below. I hope you can help me out! Thank you in advance!
<div class="test" style="margin-left: auto; margin-right:auto; text-align: center; position: relative;">
<div class="container-fluid padding" style="margin-left: auto; margin-right:auto;">
<div class="row padding">
<div class="cold-md-4" style="margin-right: 1%; margin-left: 1%; margin-top: 1%; margin-bottom: 1%;">
<div class="card" style="width: 18rem; margin-left: 1%; ">
<img class="card-img-top" src="img\festival-tickets\ticket3.png">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
Go somewhere
</div>
</div>
</div>
<div class="cold-md-4" style="margin-right: 1%; margin-left: 1%; margin-top: 1%; margin-bottom: 1%;">
<div class="card" style="width: 18rem;">
<img class="card-img-top" src="img\festival-tickets\ticket3.png">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
Go somewhere
</div>
</div>
</div>
</div>
</div>
</div>
Just add a justify-content: center; to the parent element (that .row .padding) of the elements you want to center (the cards, in this case).
.center {
justify-content: center;
}
<div class="test" style="margin-left: auto; margin-right:auto; text-align: center; position: relative;">
<div class="container-fluid padding" style="margin-left: auto; margin-right:auto;">
<div class="row padding center">
<div class="cold-md-4" style="margin-right: 1%; margin-left: 1%; margin-top: 1%; margin-bottom: 1%;">
<div class="card" style="width: 18rem; margin-left: 1%; ">
<img class="card-img-top" src="img\festival-tickets\ticket3.png">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
Go somewhere
</div>
</div>
</div>
<div class="cold-md-4" style="margin-right: 1%; margin-left: 1%; margin-top: 1%; margin-bottom: 1%;">
<div class="card" style="width: 18rem;">
<img class="card-img-top" src="img\festival-tickets\ticket3.png">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
Go somewhere
</div>
</div>
</div>
</div>
</div>
</div>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
I created a simple page in my Laravel and in that page, I have three sections which is mainly navigation, content and footer. I got the navigation and footer layout completed. In the content section, I wish to use bootstrap to place my images layout like this:
Image:
This is just a general idea but I need it to be responsive so it fits the mobile layout as well.
What I have tried is to use Masonry for CSS but it does not fit the mobile layout responsively. I tried using bootstrap 4 but the alignment between IMG3 and IMG4/5 are too far apart and placing margin does not align them near enough.
My code:
#section('content')
<div class="container">
<div class="row">
<div class="col-sm">
<img src="{{asset('/images/Home_Bed.jpg')}}" class="img-fluid custom-position-1" alt="">
</div>
<div class="col-sm col-8">
<img src="//via.placeholder.com/350x150" class="img-fluid custom-position-2" alt="">
</div>
<div class="col-sm custom-position-3">
<img src="{{asset('/images/Home_Kitchen.jpg')}}" class="img-fluid custom-position-3" alt="">
</div>
</div>
<div class="row align-items-end">
<div class="col col-8">
<img src="{{asset('/images/Shop_Page.jpg')}}" class=" img-fluid custom-position-4" alt="">
</div>
<div class="col">
<img src="{{asset('/images/Home_Sofa.jpg')}}" class="img-fluid custom-position-5" alt="">
</div>
</div>
</div>
#endsection
.row {
margin-bottom: 30px;
}
.custom-position-1{
position: relative;
bottom: -160px;
left: 50px;
height:100px;
object-fit: cover;
}
.custom-position-2{
position:relative;
right:100px;
object-fit:cover;
}
.custom-position-3{
position: relative;
bottom: -160px;
left: 50px;
height:100px;
object-fit: cover;
}
.custom-position-4{
position: relative;
height: 400px;
width:800px;
object-fit: cover;
}
.custom-position-5{
position: relative;
height:300px;
left:50px;
top: 100px;
object-fit: cover;
}
Does anyone have any idea how to make it good?
Are you looking for a solution like this?
If you want to have some spacing use margin classes.
img {
width: 100%;
height: 100%;
}
[class*="col-"],
.flex-grow-0 {
border: 1px solid black;
}
.img-fluid {
padding: 5px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
<div class="container">
<div class="row m-0">
<div class="col-8 p-0">
<div class="row m-0">
<div class="col-6 p-0">
<img src="http://placehold.it/300x300" class="img-fluid" alt="" />
</div>
<div class="col-6 p-0">
<img src="http://placehold.it/300x300" class="img-fluid" alt="" />
</div>
<div class="col-12 p-0">
<img src="http://placehold.it/300x300" class="img-fluid" alt="" />
</div>
</div>
</div>
<div class="col-4 p-0 d-flex">
<div class="d-flex flex-column">
<div class="flex-grow-0 mt-auto">
<img src="http://placehold.it/300x500" class="img-fluid" alt="" />
</div>
<div class="flex-grow-0">
<img src="http://placehold.it/400x400" class="img-fluid" alt="" />
</div>
</div>
</div>
</div>
</div>
I've just got back in to learning bootstrap, html and css. So far I have three cards in a row of different widths using the bootstrap grid the horizontal card template. My problem is that I want my layout to be the same in each card, The title and paragraph should be the same distance away in each and the fav / info button the same distance from the title. Also, I managed to get the first two columns close but somehow there is weird extra large spacing between the image and title of the last and largest column. How can I do this?
I've tried to manually adjust the positions of the elements in each card but it's hard to get them consistent, it also made my code a mess with extra ids for very similar things. As for the odd spacing I've tried to find the issue using developer tools on chrome to change the width, padding etc but not sure what is causing this. The columns I have are col-md-3, col-md-4 and col-md-5.
these are my cards
<div class="row">
<div class="col-md-3">
<div class="card mb-3">
<div class="row no-gutters">
<div class="col-md-4">
<div class="img-container"><img src="https://cdn.myanimelist.net/images/anime/1517/100633l.jpg" class="card-img-top" class="card-img" alt="..."></div>
</div>
<div class="col-md-8">
<div class="card-body">
<h5 class="card-title">Attack on Titan</h5>
<p class="card-text">Airs Sunday :: 10 eps</p>"
<div class="col-md-4">
<div class="card mb-3">
<div class="row no-gutters">
<div class="col-md-3">
<div class="img-container"><img src="https://cdn.myanimelist.net/images/anime/1068/97169l.jpg" class="card-img-top" class="card-img" alt="..."></div>
</div>
<div class="col-md-8">
<div class="card-body">
<h5 class="card-title">The Rising of the Shield Hero</h5>
<p class="card-text">Airs Wednesday :: 26 eps</p>
<div class="status"></div>
</div>
</div>
</div>
</div>
</div>
<div class="col-md-5">
<div class="card mb-3">
<div class="row no-gutters">
<div class="col-md-3">
<div class="img-container"><img src="https://cdn.myanimelist.net/images/anime/1130/99458l.jpg" class="card-img-top" class="card-img-top" class="card-img" alt="..."></div>
</div>
<div class="col-md-8">
<div class="card-body">
<h5 class="card-title">Hitori Bocchi no Maru Maru Seikatsu</h5>
<p class="card-text">Airs Saturday :: 12 eps</p>
<div class="status"></div>
</div>
</div>
</div>
I also added it to my codepen to better see also https://codepen.io/Shiro01/pen/YbRQmQ
I'm trying to get them similar to the cards on this site https://anichart.net/airing
I want to have the column fit the content and don't want the title breaking on to another line. I want the distance of the elements to be as equally spaced as possible so the whole design looks consistent. Thank you.
remove that class=" no-gutters" , and add class="container-fluid" before row
not try to edit boostrap class it destroy its responsive structure
And your stutus bar can adjust with position absolute or change your style
status {
background-color: #662481;
height: 76px;
width: 10px;
position: relative;
left: 187px;
top: -103px;
margin: 0;
padding: 0;code here
<div class="row outer_row">
<div class="col-md-4">
<div class="row inside_row">
<div class="col-sm-4">
<div class="img-container">
<img src="https://cdn.myanimelist.net/images/anime/1517/100633l.jpg" class="card-img-top" alt="..."></div>
</div>
<div class="col-sm-6">
<div class="card-data">
<h5 class="card-title">Attack on Titan</h5>
<p class="card-text">Airs Sunday :: 10 eps</p>
</div>
</div>
<div class="col-sm-2">
<div class="status"></div>
</div>
</div>
</div>
<div class="col-md-4">
<div class="row inside_row">
<div class="col-sm-4">
<div class="img-container">
<img src="https://cdn.myanimelist.net/images/anime/1517/100633l.jpg" class="card-img-top" class="card-img" alt="..."></div>
</div>
<div class="col-sm-6">
<div class="card-data">
<h5 class="card-title">Attack on Titan</h5>
<p class="card-text">Airs Sunday :: 10 eps</p>
</div>
</div>
<div class="col-sm-2">
<div class="status"></div>
</div>
</div>
</div>
<div class="col-md-4">
<div class="row inside_row">
<div class="col-sm-4">
<div class="img-container">
<img src="https://cdn.myanimelist.net/images/anime/1517/100633l.jpg" class="card-img-top" class="card-img" alt="..."></div>
</div>
<div class="col-sm-6">
<div class="card-data">
<h5 class="card-title">Attack on Titan</h5>
<p class="card-text">Airs Sunday :: 10 eps</p>
</div>
</div>
<div class="col-sm-2">
<div class="status"></div>
</div>
</div>
</div>
here is css for HTML code :
body {
padding: 70px;
}
.card-img-top {
width: 100%;
margin-left: -15px;
height: 80px;
}
.status {
background-color: #662481;
height: 80px;
width: 10px;
}
.card-data{
margin-left:-30px;
margin-top:6px;
}
.inside_row{
width: 100%;
border:1px solid lightgray;
height:80px;
}
.outer_row{
width: 100%;
}
here is my solution for your question in a codepen https://codepen.io/nick4434/pen/joQGVM?editors=1100
please try this code:
body {
padding: 70px;
font-family: arial, helvetica;
background-color: #ebebeb;
}
.navbar {
background-color: #fff;
}
.navbar-brand {
color: #2980b9; /* Clips image */
font-size: 20px;
font-weight: bold;
}
.nav-link {
color: #2980b9;
}
.mb-3 {
max-height: 100px;
}
.md-3 {
max-width: auto;
}
.card-title {
font-size: 16px;
font-weight: bold;
margin-top: -10px;
margin-bottom: 2px;
margin-left: -10px;
}
.card-text {
margin-top: -4px;
margin-bottom: 40px;
margin-left: -10px;
font-size: 12px;
}
/* Clips image */
.img-container {
display: inline-block;
width: 100px;
height: 100px;
overflow: hidden;
}
.card-img-top {
position: relative; top: 50%;
transform: translateY(-35%);
}
.status {
background-color: #662481;
height: 100px;
width: 10px;
position: relative;
top: -96px;
margin-left: auto;
z-index: 99;
padding: 0;
right: -20px;
}
<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8">
<meta name="viewport"content="width=device-width, initial scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<link rel="stylesheet" href="assets/font/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="index-css-mini.css">
<title>AniWatch</title>
</head>
<body>
<div class="container">
<nav class="navbar navbar-expand-md fixed-top">
Brand
<button type="button" class="navbar-toggler" data-toggle="collapse" data-target="#navbarCollapse">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarCollapse">
<div class="navbar-nav">
Airing
Finished
</div>
</div>
</nav>
</div> <!-- nav container -->
<div class="row">
<div class="col-md-3">
<div class="card mb-3">
<div class="row no-gutters">
<div class="col-md-4">
<div class="img-container"><img src="https://cdn.myanimelist.net/images/anime/1517/100633l.jpg" class="card-img-top" class="card-img" alt="..."></div>
</div>
<div class="col-md-8">
<div class="card-body">
<h5 class="card-title">Attack on Titan</h5>
<p class="card-text">Airs Sunday :: 10 eps</p>
<div class="status"></div>
</div>
</div>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card mb-3">
<div class="row no-gutters">
<div class="col-md-3">
<div class="img-container"><img src="https://cdn.myanimelist.net/images/anime/1068/97169l.jpg" class="card-img-top" class="card-img" alt="..."></div>
</div>
<div class="col-md-9">
<div class="card-body">
<h5 class="card-title">The Rising of the Shield Hero</h5>
<p class="card-text">Airs Wednesday :: 26 eps</p>
<div class="status"></div>
</div>
</div>
</div>
</div>
</div>
<div class="col-md-5">
<div class="card mb-3">
<div class="row no-gutters">
<div class="col-md-3">
<div class="img-container"><img src="https://cdn.myanimelist.net/images/anime/1130/99458l.jpg" class="card-img-top" class="card-img-top" class="card-img" alt="..."></div>
</div>
<div class="col-md-9">
<div class="card-body">
<h5 class="card-title">Hitori Bocchi no Maru Maru Seikatsu</h5>
<p class="card-text">Airs Saturday :: 12 eps</p>
<div class="status"></div>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
</body>
</html>
I use mainly Bootstrap, but in this case nor pure CSS nor Bootstrap could make the case. I have an HTML like this:
#filling{
display: flex;
flex-direction: column;
overflow-y: scroll;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<div>
<div class="container">
<div class="row align-items-center mt-3">
<div class="col-6 text-center">
<img width="150" height="150" src="img/user-placeholder.svg">
<p class="mt-2 mb-0">pholder</p>
</div>
<div class="col-6">
<div class="mb-2">
<div class="row">
<div class="col-6 text-center">pholder</div>
<div class="col-6 text-center">pholder</div>
</div>
<div class="row">
<div class="col-6 text-center">Friends</div>
<div class="col-6 text-center">Posts</div>
</div>
</div>
<butto class="btn btn-transparent mt-2">Click</button>
</div>
</div>
<br>
<p class="text-center m-0">Contents</p>
<hr class="mt-0 mb-2">
</div>
<div id="filling" class="text-center">
<div class="sample">
<img width="270" height="270" src="my_img.jpg">
<p>coding</p>
</div>
<div class="sample">
<img width="270" height="270" src="my_img.jpg">
<p>coding</p>
</div>
<div class="sample">
<img width="270" height="270" src="my_img.jpg">
<p>coding</p>
</div>
</div>
</div>
Now the issue is: the #filling div has to be populated dynamically and I want it to behave like ListView in Android programming. I must be able to scroll it. Therefore I added some CSS:
#filling{
display: flex;
flex-direction: column;
overflow-y: scroll;
}
But if I populate the div by appending children like those three .sample divs, the list grows vertically but the #filling div does too. In other words, its' forcing me to scroll the entire page rather than just the div.
I hope I have been clear, this sure will be marked as a duplicate of any flex question but I'd like to receive a working solution because other than fixing the height of the div, say, at 250px I cannot find a "responsive" way to do it.
I created a quick solution where I set the max-heigth of your #filling div to 50%.
Please note, you need to set the height of all outer containers to 100% for this to work.
JSBin link: https://jsbin.com/nofobak/edit?html,css,output
<div id="my-container">
<div class="container h-40">
<div class="row align-items-center mt-3">
<div class="col-6 text-center">
<img width="150" height="150" src="img/user-placeholder.svg">
<p class="mt-2 mb-0">pholder</p>
</div>
<div class="col-6">
<div class="mb-2">
<div class="row">
<div class="col-6 text-center">pholder</div>
<div class="col-6 text-center">pholder</div>
</div>
<div class="row">
<div class="col-6 text-center">Friends</div>
<div class="col-6 text-center">Posts</div>
</div>
</div>
<butto class="btn btn-transparent mt-2">Click</button>
</div>
</div>
<br>
<p class="text-center m-0">Contents</p>
<hr class="mt-0 mb-2">
</div>
<div id="filling" class="h-60 text-center">
<div class="sample">
<img width="270" height="270" src="my_img.jpg">
<p>coding</p>
</div>
<div class="sample">
<img width="270" height="270" src="my_img.jpg">
<p>coding</p>
</div>
<div class="sample">
<img width="270" height="270" src="my_img.jpg">
<p>coding</p>
</div>
</div>
</div>
#filling{
display: flex;
flex-direction: column;
overflow-y: scroll;
max-height: 50%;
}
html {
height: 100%
}
body {
height: 100%;
}
#my-container {
height: 100%;
}
A couple of things, h-40 is not a Bootstrap class, unless you have it as a custom class you made; Bootstrap's height utility classes are just h-25, h-50, h-75, h-100, h-auto.
As mentioned in my comment and the answers linked, you if you want to use percentages, you need to have a parent with a fixed height so the percentage can take that as a reference; the other option is to use vh units to set the height relative to the viewport's height.
Bootstrap also provides some utilities for this
Now you would need to take into account the headers content of course
#posts_list {
display: flex;
flex-direction: column;
overflow-y: scroll;
max-height: 60vh;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<div>
<div class="container">
<div class="row align-items-center mt-3">
<div class="col-6 text-center">
<img width="150" height="150" src="img/user-placeholder.svg">
<p class="mt-2 mb-0">pholder</p>
</div>
<div class="col-6">
<div class="mb-2">
<div class="row">
<div class="col-6 text-center">pholder</div>
<div class="col-6 text-center">pholder</div>
</div>
<div class="row">
<div class="col-6 text-center">Friends</div>
<div class="col-6 text-center">Posts</div>
</div>
</div>
<butto class="btn btn-transparent mt-2">Click</button>
</div>
</div>
<br>
<p class="text-center m-0">Contents</p>
<hr class="mt-0 mb-2">
</div>
<div id="posts_list" class="h-60 text-center">
<div class="sample">
<img width="270" height="270" src="my_img.jpg">
<p>coding</p>
</div>
<div class="sample">
<img width="270" height="270" src="my_img.jpg">
<p>coding</p>
</div>
<div class="sample">
<img width="270" height="270" src="my_img.jpg">
<p>coding</p>
</div>
</div>
</div>
I have 7 images. I need to see 5 images in one row, and 2 more images in another row below in the center. I made 5 images in a row, but I can not position the other 2 images in the center below. Also, in responsive version I need 2 images under each other and 1 image in the center and they need to have border-radius:100%, but it does not work. What`s wrong with my code?
This is html:
#media all and (max-width: 1024px) {
.ring {
border-radius: 100%;
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
<div class="container">
<div class="row">
<div class="col-sm col-6">
<div class="single-specials text-center wow fadeInUp" data-wow-delay="0.1s" style="border-radius: 0;">
<img src="img/1.jpg" style="border-radius: 100%;">
</div>
</div>
<div class="col-sm col-6">
<div class="single-specials text-center wow fadeInUp" data-wow-delay="0.3s" style="border-radius: 0;">
<img src="img/2.jpg" style="border-radius: 100%;">
</div>
</div>
<div class="col-sm col-6 hightechxl">
<div class="single-specials text-center wow fadeInUp" data-wow-delay="0.5s" style="border-radius: 0;">
<img src="img/1.jpg" style="border-radius: 100%;">
</div>
</div>
<div class="col-sm col-6">
<div class="single-specials text-center wow fadeInUp" data-wow-delay="0.7s" style="border-radius: 0;">
<img src="img/2.png" style="border-radius: 100%;">
</div>
</div>
<div class="col-sm col-6">
<div class="single-specials text-center wow fadeInUp" data-wow-delay="0.9s" style="border-radius: 0;">
<img src="img/1.png" style="border-radius: 100%;">
</div>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-sm">
<div class="single-specials text-center wow fadeInUp" data-wow-delay="1.1s" style="border-radius: 0;">
<img src="img/2.png" style="border-radius: 100%; width: 150px; height: 150px;">
</div>
</div>
<div class="col-sm">
<div class="single-specials text-center wow fadeInUp" data-wow-delay="1.3s" style="border-radius: 0;">
<img src="img/1.png" style="border-radius: 100%;">
</div>
</div>
</div>
</div>
I am using bootstrap4, if there is another decision without bootstrap, please, show me how.
I just make to demonstrate code for you at: https://codepen.io/tien-bui/pen/mamemO
So the basic ideas of Bootstrap is every row have 12 col, so if you want to display 5 item in 1 row you need to set the col prefix at 2. For example: target small screen col-sm-2, target large screen col-lg-2. And you need to target all the device to achieve the responsive, it will look like this:
<div class="col-lg-2 col-md-2 col-sm-6 col-6"></div>
You can use flex, set width to 18% for example - that little less than 20% , which can take 5 items and it will give you some space for margin.
Use media query for the second version and set flex-basis to 48%.
.cont{
display: flex;
justify-content: space-around;
flex-wrap: wrap;
}
.item{
flex-basis: 18%;
flex-shrink: 0;
flex-grow: 0;
border: 1px solid black;
height: 50px;
margin: 5px;
}
#media all and (max-width: 1024px) {
.item {
flex-basis: 48%;
}
}
<div class="cont">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
<div class="item">4</div>
<div class="item">5</div>
<div class="item">6</div>
<div class="item">7</div>
</div>