<div class="row">
<div class="col-lg-3 " style="border: groove;">
<p class="circle col-xs-1 center-block">01</p>
<h3>trending courses</h3>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Repellat, consectetur?</p>
</div>
<div class="col-lg-1"></div>
<div class="col-lg-3" style="border: groove;">
<p class="circle text-center">02</p>
<h3>books&library</h3>
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Sit nostrum voluptates tempore, pariatur nobis
tempora repellendus deserunt suscipit, sed ex nihil eum impedit maiores quia modi qui aut velit
veritatis quam deleniti? Quasi dolor, asperiores ut cumque laboriosam accusamus eveniet esse. Officiis
quidem perferendis qui.</p>
</div>
<div class="col-lg-1">
</div>
<div class="col-lg-3" style="border: groove;">
<p class="circle">03</p>
<h3>certified teachers</h3>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Repellat, consectetur?</p>
</div>
</div>
Used bs-5,bootstrap.bundle.min.css
This is the below output for this code
3. This is the code of css
.circle {
border-radius: 50%;
width: 60px;
height: 60px;
padding: 10px;
background: purple;
border: 3px solid #000;
display: flex;
color: #fff;
text-align: center;
font: 28px arial, sans-serif;
}
I tried various ways of flex, it did not work until I change margin
Please help me, why this is not working
text: center on your .circle element can't work because it will only center text inside the element and not the element itself.
If what you want to center the circle then you have to set margin to auto for the element .
Or if you want to do it using flexbox then you have to wrap your p element with a div which has display: flex and justify-content: center styles.
Here's a flexbox-only solution:
.circle {
border-radius: 50%;
width: 60px;
height: 60px;
padding: 10px;
background: purple;
border: 3px solid #000;
display: flex;
color: #fff;
text-align: center;
font: 28px arial, sans-serif;
}
<!-- Bootstrap CDN -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.2.3/dist/css/bootstrap.min.css" rel="stylesheet" />
<div class="row">
<div class="col-lg-3 " style="border: groove;">
<!-- 👇 flexbox wrapper for circle -->
<div class="d-flex justify-content-center">
<p class="circle col-xs-1 center-block">01</p>
</div>
<h3 class="text-center">trending courses</h3>
<p class="text-center">Lorem ipsum dolor sit amet consectetur adipisicing elit. Repellat, consectetur?</p>
</div>
<div class="col-lg-1"></div>
<div class="col-lg-3" style="border: groove;">
<!-- 👇 flexbox wrapper for circle -->
<div class="d-flex justify-content-center">
<p class="circle text-center">02</p>
</div>
<h3 class="text-center">books&library</h3>
<p class="text-center">Lorem ipsum, dolor sit amet consectetur adipisicing elit. Sit nostrum voluptates tempore, pariatur nobis tempora repellendus deserunt suscipit, sed ex nihil eum impedit maiores quia modi qui aut velit veritatis quam deleniti? Quasi dolor, asperiores
ut cumque laboriosam accusamus eveniet esse. Officiis quidem perferendis qui.</p>
</div>
<div class="col-lg-1">
</div>
<div class="col-lg-3" style="border: groove;">
<!-- 👇 flexbox wrapper for circle -->
<div class="d-flex justify-content-center">
<p class="circle">03</p>
</div>
<h3 class="text-center">certified teachers</h3>
<p class="text-center">Lorem ipsum dolor sit amet consectetur adipisicing elit. Repellat, consectetur?</p>
</div>
</div>
If you wrap each circle with a flexbox that has justify-content: center;, any items in the flexbox will be centered horizontally.
EDIT: OP wanted to center paragraph text as well.
Use it to center all elements:
<div class="col-lg-3 d-flex flex-column align-items-center justify-content-center"></div>
Try using margin:auto in css or m-auto in bootstrap
Using Css
.circle {
margin:auto
}
Using BootStrap add a class name to the div m-auto
<p class="circle text-center m-auto">02</p>
Using Flex
Add a class called dop to parent and chi to child circle
<div className="col-lg-3 dop" style={{ border: "groove" }}>
<p className="circle text-center chi">02</p>
CSS:
.dop {
display: flex;
flex-direction: column;
}
.chi {
align-self: center;
}
Try This
Related
This question already has answers here:
Floated elements of variable height push siblings down
(3 answers)
Closed 1 year ago.
JSFiddle
<div class="container">
<div class="row">
<div class="col-6">
<div class="card">
<!-- plane icon img -->
<img src="https://i.imgur.com/JhOKdVb.png" alt="plane" class="card__icon">
<div class="card__body">
<h3>Lorem Ipsum</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Placeat dolore eaque veniam architecto. Impedit expedita facilis error nostrum harum cumque, iste aspernatur</p>
</div>
</div>
</div>
<div class="col-6">
<div class="card">
<!-- game-pad icon img -->
<img src="https://i.imgur.com/c5O6IOS.png" alt="plane" class="card__icon">
<div class="card__body">
<h3>Lorem Ipsum</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Placeat dolore eaque veniam architecto. Impedit expedita facilis error nostrum harum cumque, iste aspernatur</p>
</div>
</div>
</div>
<div class="col-6">
<div class="card">
<!-- plane icon img -->
<img src="https://i.imgur.com/JhOKdVb.png" alt="plane" class="card__icon">
<div class="card__body">
<h3>Lorem Ipsum</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Placeat dolore eaque veniam architecto. Impedit expedita facilis error nostrum harum cumque, iste aspernatur</p>
</div>
</div>
</div>
</div>
</div>
.container{
max-width: 1200px;
margin-right: auto;
margin-left: auto;
}
.row:before,.row:after{
content: '';
display: block;
clear: both;
display: table;
}
.col-6{
width: 50%;
float: left;
}
.card{
margin-bottom: 50px;
}
img{
max-width: 100%;
height: auto;
}
I created the columns using the CSS float property. No framework! Everything is working fine but the last column in the row isn't floating left. can anyone explain?
Interesting Fact:
I'm using only two icons called Plane and Gamepad. Interestingly when I changed the Gamepad icon with the 'Plane' icon, it fixes the problem! Still can't figure out why this is happening.
You need to use:
float: right;
That's what you need.
body{
margin: 0;
padding: 0;
}
.bg-color{
background: linear-gradient(180deg, #BA894D 0%, #FFBC6A 100%);
}
.main-content{
display: flex;
justify-content: center;
align-items: center;
}
.main-content div{
max-width: 595px;
margin-bottom: 100px;
text-align: center;
}
<div class="container-fluid">
<div class="row">
<div class="col-lg-5 bg-color">
<div class="main-content">
<div>
<img src="./download.jpeg" alt="LOGO" class="img-fluid">
<h5>Brand Name</h5>
<h3>Build your own shop</h3>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Eaque inventore perferendis sit optio vero totam voluptatibus alias expedita, in neque natus, rerum officia nobis nihil, sapiente maxime beatae porro perspiciatis.</p>
</div>
</div>
</div>
<div class="col-lg-7">
<h1>CONTACT US</h1>
</div>
</div>
</div>
It is a contact form with 2 columns, One side is logo and text with the background of full height and one side is formed with inputs like name, email I want to center the logo and text below vertically and horizontally with a background color of 100% height.
body{
margin: 0;
padding: 0;
}
.contact{
min-height: 100vh;
}
.bg-color{
background: linear-gradient(180deg, #BA894D 0%, #FFBC6A 100%);
}
.main-content{
display: flex;
justify-content: center;
align-items: center;
}
.main-content div{
max-width: 595px;
text-align: center;
}
<div class="container-fluid">
<div class="row contact">
<div class="col-lg-5 bg-color main-content">
<div>
<img src="./download.jpeg" alt="" class="img-fluid">
<h5>Brand Name</h5>
<h3>Build your own shop</h3>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Eaque inventore perferendis sit optio vero totam voluptatibus alias expedita, in neque natus, rerum officia nobis nihil, sapiente maxime beatae porro perspiciatis.</p>
</div>
</div>
<div class="col-lg-7">
<h1>CONTACT US</h1>
</div>
</div>
</div>
I think this is what you are expecting.
I'm trying to align the contents of a row, which is inside of a container, to the top of said row.
This is my current html:
<div class="container">
<div class="row">
<div class="ticket">
<!-- content -->
</div>
</div>
</div>
CSS for ticket:
<style>
.ticket{
border:5px solid black;
border-radius: 15px 50px 30px 5px;
width:20%;
height: fit-content;
display:inline-block;
clear: left;
margin-left:30px;
background-color:#eee;
}
</style>
"row" and "container" are both bootstrap.
Trying to align the 'tickets' with the top (red line)
I've tried using align-content and align-items but neither seem to be doing anything. Any help would be appreciated! Thank you.
You can use align-items: flex-start; in container of tickets.
.ticket {
display:flex;
align-items:flex-start;
}
.tick {
padding:20px;
border:4px solid #000;
margin:50px;
border-radius:0 30px 0 0;
}
<div class="container">
<div class="row">
<div class="ticket">
<div class="tick">Lorem ipsum dolor sit amet consectetur, adipisicing elit. Quisquam adipisci suscipit, labore accusamus, libero ad dolorum officia error quo, et molestiae fugit placeat maxime ratione vel minus delectus magni. Consequatur! Lorem ipsum dolor sit amet consectetur, adipisicing elit. Quisquam adipisci suscipit, labore accusamus, libero ad dolorum officia error quo, et molestiae fugit placeat maxime ratione vel minus delectus magni. Consequatur!Lorem ipsum dolor sit amet consectetur, adipisicing elit. Quisquam adipisci suscipit, labore accusamus, libero ad dolorum officia error quo, et molestiae fugit placeat maxime ratione vel minus delectus magni. Consequatur!</div>
<div class="tick">Lorem ipsum dolor sit amet consectetur, adipisicing elit. Quisquam adipisci suscipit, labore accusamus</div>
<div class="tick">Lorem ipsum dolor sit amet consectetur, adipisicing elit. </div>
</div>
</div>
</div>
Try to use next css code:
.ticket {
display: flex;
}
.item-in-container {
#flex: 1;
}
Uncomment flex: 1; if you want them to have the same width
If you used the default behaviour of bootstrap it's aligned to the top:
.ticket {
height: 100px;
background-color: red;
}
.ticket:nth-child(2) {
height: 70px;
}
.ticket:nth-child(3) {
height: 50px;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<div class="container">
<div class="row">
<div class="ticket col-3 m-3"></div>
<div class="ticket col-3 m-3"></div>
<div class="ticket col-3 m-3"></div>
</div>
</div>
What I am trying to do is to get the red text just after the blue title of each boxes.
It seems I will have to add another div? I have added and modified the posotion of .card-indus img but the outcome is never what I want.
Do you know why it does not work even when I apply a position:relative; to .industries .container-industries .card-indus img? Do you have any suggestions?
.industries .container-industries .card-indus {
position: relative;
border: red solid 1px;
color: white;
max-height: 300px;
overflow: hidden;
height: 100%;
}
.industries .container-industries .card-indus img {
display: block;
width: 100%;
height: 100%;
object-fit: cover;
opacity: 0.5;
}
.industries .container-industries .card-indus .text-image {
position: absolute;
color: red;
left: 0;
top: 0;
}
.industries .container-industries .card-header {
height: 4rem;
display: flex;
align-items: center;
background: rgba(82, 134, 236, 0.6);
}
.industries .container-industries .card-header p {
margin-left: 1rem;
}
<div class="industries">
<div class="industries-icons">
<h2> Our Industries</h2>
<span class="border-1"></span>
<div class="container-industries">
<div class="card-indus">
<div class="card-header">
<p>Banking</p>
</div>
<div class="card-content">
<img src="../images/services/finance.jpg">
<p class="text-image">Lorem ipsum dolor, sit amet consectetur adipisicing elit. Quia voluptatibus numquam eveniet doloremque dignissimos veniam.</p>
</div>
</div>
<div class="card-indus">
<div class="card-header">
<p>Admin</p>
</div>
<div class="card-content">
<img src="../images/services/admin.jpg">
<p class="text-image">Lorem ipsum dolor, sit amet consectetur adipisicing elit. Quia voluptatibus numquam eveniet doloremque dignissimos veniam.</p>
</div>
</div>
<div class="card-indus">
<div class="card-header">
<p>Law</p>
</div>
<div class="card-content">
<img src="../images/services/law.jpg">
<p class="text-image">Lorem ipsum dolor, sit amet consectetur adipisicing elit. Quia voluptatibus numquam eveniet doloremque dignissimos veniam.</p>
</div>
</div>
<div class="card-indus">
<div class="card-header">
<p>Retail</p>
</div>
<div class="card-content">
<img src="../images/services/retail.jpg">
<p class="text-image">Lorem ipsum dolor, sit amet consectetur adipisicing elit. Quia voluptatibus numquam eveniet doloremque dignissimos veniam.</p>
</div>
</div>
<div class="card-indus">
<div class="card-header">
<p>Telecom</p>
</div>
<div class="card-content">
<img src="../images/services/telecom.jpg">
<p class="text-image">Lorem ipsum dolor, sit amet consectetur adipisicing elit. Quia voluptatibus numquam eveniet doloremque dignissimos veniam.</p>
</div>
</div>
</div>
</div>
</div>
You would have to do two things:
1- move text-image div before the img div.
2- remove position: absolute; from img as you mentioned.
.industries .container-industries .card-indus {
position: relative;
border: red solid 1px;
color: white;
max-height: 300px;
overflow: hidden;
height: 100%;
}
.industries .container-industries .card-indus img {
display: block;
width: 100%;
height: 100%;
object-fit: cover;
opacity: 0.5;
}
.industries .container-industries .card-indus .text-image {
color: red;
left: 0;
top: 0;
}
.industries .container-industries .card-header {
height: 4rem;
display: flex;
align-items: center;
background: rgba(82, 134, 236, 0.6);
}
.industries .container-industries .card-header p {
margin-left: 1rem;
}
<div class="industries">
<div class="industries-icons">
<h2>Our Industries</h2>
<span class="border-1"></span>
<div class="container-industries">
<div class="card-indus">
<div class="card-header">
<p>Banking</p>
</div>
<div class="card-content">
<p class="text-image">
Lorem ipsum dolor, sit amet consectetur adipisicing elit. Quia
voluptatibus numquam eveniet doloremque dignissimos veniam.
</p>
<img src="../images/services/finance.jpg" />
</div>
</div>
<div class="card-indus">
<div class="card-header">
<p>Admin</p>
</div>
<div class="card-content">
<p class="text-image">
Lorem ipsum dolor, sit amet consectetur adipisicing elit. Quia
voluptatibus numquam eveniet doloremque dignissimos veniam.
</p>
<img src="../images/services/admin.jpg" />
</div>
</div>
<div class="card-indus">
<div class="card-header">
<p>Law</p>
</div>
<div class="card-content">
<p class="text-image">
Lorem ipsum dolor, sit amet consectetur adipisicing elit. Quia
voluptatibus numquam eveniet doloremque dignissimos veniam.
</p>
<img src="../images/services/law.jpg" />
</div>
</div>
<div class="card-indus">
<div class="card-header">
<p>Retail</p>
</div>
<div class="card-content">
<p class="text-image">
Lorem ipsum dolor, sit amet consectetur adipisicing elit. Quia
voluptatibus numquam eveniet doloremque dignissimos veniam.
</p>
<img src="../images/services/retail.jpg" />
</div>
</div>
<div class="card-indus">
<div class="card-header">
<p>Telecom</p>
</div>
<div class="card-content">
<p class="text-image">
Lorem ipsum dolor, sit amet consectetur adipisicing elit. Quia
voluptatibus numquam eveniet doloremque dignissimos veniam.
</p>
<img src="../images/services/telecom.jpg" />
</div>
</div>
</div>
</div>
</div>
I have two columns and certain contents in both the columns.
I want a scroll to the each div when content is bigger.
I have fixed header and when I scroll then two divs is also scrolling.
I want only one div to be scrolled whenever I want to do so.
.b-r{
border-right: thin black solid;
}
.margin_top_600px{
margin-top:600px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-6 b-r padding_bottom_70" >
<p class="margin_top_600px">
Left side Data
</p>
</div>
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-6 b-r padding_bottom_70" >
<p class="margin_top_600px">
Right side Data
</p>
</div>
</div>
If I want to scroll for only left side data then only that div should scroll.
Any help would be great.
Thank you.
You need to set height and overflow: auto; to .b-r:
.b-r{
border-right: thin black solid;
height: 100vh;
overflow: auto;
}
.margin_top_600px{
margin-top:600px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-6 b-r padding_bottom_70" >
<p class="margin_top_600px">
Left side Data
</p>
</div>
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-6 b-r padding_bottom_70" >
<p class="margin_top_600px">
Right side Data
</p>
</div>
</div>
To hide scrollbar you need to define one more wrapping div with overflow-y: scroll;. Outer div should have overflow: hidden;
scroll available with hidden scrollbars
.b-r{
border-right: thin black solid;
height: 100vh;
overflow: hidden;
}
.margin_top_600px{
margin-top:600px;
}
.scrll_hide {
float: right;
height: 100%;
width: calc(100% + 48px);
overflow-y: scroll;
margin: 0 -32px 0 0 !important;
box-sizing: border-box;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<div class="container-fluid">
<div class="row">
<div class="col-xs-6 b-r padding_bottom_70" >
<div class="scrll_hide">
<p class="margin_top_600px">
Left side Data
</p>
</div>
</div>
<div class="col-xs-6 b-r padding_bottom_70" >
<div class="scrll_hide">
<p class="margin_top_600px">
Right side Data
</p>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-6 my-content">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ipsam neque repellat libero facere, inventore natus! Laudantium laborum unde veritatis, nemo commodi ducimus quasi quam incidunt accusamus dolore asperiores optio repellendus!
</div>
<div class=" col-lg-6 col-md-6 col-sm-6 col-xs-6 my-content">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Exercitationem soluta corrupti, veniam sit, delectus sunt ipsum placeat recusandae eaque, voluptatum nemo optio cumque omnis veritatis quam itaque ab. Cupiditate, exercitationem?Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quo dolorem adipisci sint ducimus voluptates eveniet qui nisi error reiciendis laborum sed, neque officia aspernatur omnis dolore consequuntur, natus optio, mollitia!Lorem ipsum dolor sit amet, consectetur adipisicing elit. Culpa dignissimos enim expedita temporibus iure. Quam vitae autem laborum magnam optio nihil quisquam, est aliquid perspiciatis quia tempora cumque, enim vel.Lorem ipsum dolor sit amet, consectetur adipisicing elit. Vero quis veritatis, alias dicta, commodi adipisci sint natus reiciendis. Atque eius labore alias cum ratione beatae provident voluptatum eum id mollitia.
</div>
</div>
.my-content{
height: 200px;
overflow: auto;
border: 1px solid #000;
}
Working Fiddle https://jsfiddle.net/DTcHh/29480/
For all the React/Next JS and Tailwind Devs.
<div className="flex overflow-auto">
<div className="overflow-auto w-1/4">
<div className="flex flex-col w-full bg-red-200 h-[1000px]">
a
</div>
</div>
<div className="overflow-auto w-3/4">
<div className="flex flex-col w-full bg-blue-200 h-[1000px]">
a
</div>
</div>
</div>