Here is the HTML code. I am good with coding in react.js and vue.js, but I am having a hard time getting the sense of making things responsive. I dont have experience with it. But got to start somewhere. Any suggestions would be helpful.
Right now, if you make the screen size smaller. It looks horrible.
Html/bootstrap
<section id="info" class="py-3 ">
<div class="container text-white">
<div class="row justify-content-center">
<h2 class="text-white title">Lorem ipsum dolor sit</h1>
<p class="text-white cyp-para">Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut</p>
</div>
<div class="row">
<div class="col-6 align-self-center">
<div class="placeholder mx-auto"></div>
<h1 class="text-center exp"> Lorem ipsum dolor</h1>
</div>
<div class="col-6 justify-content-center">
<div class="placeholder mx-auto"></div>
<h1 class="text-center exp">Lorem ipsum dolor</h1>
</div>
</div>
</div>
</section>
CSS:
#info{
height: 515px;
width: 732px;
background: #151515 0% 0% no-repeat padding-box;
}
.cyp-para{
padding: 0px 200px;
font-size: 14px;
}
.placeholder{
width: 236px;
height: 283px;
background: grey;
}
.title{
font-size: 38px;
}
.exp{
font-size: 33px;
}
Since you are using bootstrap, you can use break-point classes to make your code responsive.
Make small changes like below and your code will look better:
<section id="info" class="py-3 ">
<div class="container text-white">
<div class="row justify-content-center">
<h2 class="text-white title">Lorem ipsum dolor sit</h1>
<p class="text-white cyp-para">Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut</p>
</div>
<div class="row">
<div class="col-12 col-md-6 align-self-center">
<div class="placeholder mx-auto"></div>
<h1 class="text-center exp"> Lorem ipsum dolor</h1>
</div>
<div class="col-12 col-md-6 justify-content-center">
<div class="placeholder mx-auto"></div>
<h1 class="text-center exp">Lorem ipsum dolor</h1>
</div>
</div>
</div>
</section>
I have included col-12 and col-md-6 classed in your code. Which means till medium size devices, you have 12 column divs i-e 1 full column width div, and when your screen size becomes medium and above medium you'll have two column's per row
Related
I need help putting a button in the bottom-right corner of a Bootstrap col.
I want to put the button where the black outline is in the image below.
<div class="container-fluid m-0">
<div class="d-flex bg-secondary m-0 rounded">
<div class="container">
<div class="row">
<div class="col-sm bg-info">
<div>
</div>
</div>
<div class="col-sm">
<h3> Username</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque dolor leo, iaculis eu rhoncus quis</p>
<p>xxx Followers . xxx Following</p>
</div>
<div class="col-sm bg-danger">
<p class="ml-auto">
<button type="button" class="btn btn-primary">Cancel</button>
</p>
</div>
</div>
</div>
</div>
Check this out--
<div class="container-fluid m-0">
<div class="d-flex bg-secondary m-0 rounded">
<div class="container">
<div class="row">
<div class="col-sm bg-info">
<div>
</div>
</div>
<div class="col-sm">
<h3> Username</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque dolor leo, iaculis eu rhoncus quis</p>
<p>xxx Followers . xxx Following</p>
</div>
<div class="col-sm bg-danger">
<p style="height: 100%" class="d-flex justify-content-end align-items-end">
<button type="button" class="btn btn-primary">Cancel</button>
</p>
</div>
</div>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.6.1/dist/css/bootstrap.min.css" integrity="sha384-zCbKRCUGaJDkqS1kPbPd7TveP5iyJE0EjAuZQTgFLD2ylzuqKfdKlfG/eSrtxUkn" crossorigin="anonymous">
<div class="container-fluid">
<div class="bg-secondary rounded">
<div class="container bg-secondary">
<div class="row align-items-stretch">
<div class="col-12 col-sm bg-info"></div>
<div class="col-12 col-sm">
<div class="py-3">
<h3> Username</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque dolor leo, iaculis eu rhoncus quis</p>
<p>xxx Followers . xxx Following</p>
</div>
</div>
<div class="col-12 col-sm bg-danger">
<div class="h-100 d-flex align-items-end justify-content-end py-3">
<button type="button" class="btn btn-primary">Cancel</button>
</div>
</div>
</div>
</div>
</div>
</div>
There are two methods to implement this...
The first method:
<div class="container-fluid">
<div class="bg-secondary rounded">
<div class="container bg-secondary">
<div class="row align-items-stretch">
<div class="col-12 col-sm bg-info"></div>
<div class="col-12 col-sm">
<div class="py-3">
<h3> Username</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque dolor leo, iaculis eu rhoncus quis</p>
<p>xxx Followers . xxx Following</p>
</div>
</div>
<div class="col-12 col-sm bg-danger">
<div class="h-100 d-flex align-items-end justify-content-end py-3">
<button type="button" class="btn btn-primary">Cancel</button>
</div>
</div>
</div>
</div>
</div>
</div>
This is the easiest one.
The second method:
Go to index.css or App.css or you can go to any other CSS file if you have imported it into your file.
Write this piece of code:
.col-sm {
height: 100%; !important
display: flex; !important
justify-content: flex-end; !important
align-items: flex-end; !important
}
You can also give a class and then write the CSS code based on the class.
For bannerimage section which has texts on the specific position, I don't want to write custom CSS to place the div. The below code fits correctly according to design and it's good in responsive also. I've not used this code everywhere but only in 1 section where there is a condition to display div or text at a specific position. I don't want to write custom CSS. But using bootstrap empty div problem is solving, Is this correct or not.
<div class="mainbannerimagewithtext">
<div class=" row-cols-1 row-cols-md-3 g-4 py-5 ">
<div class="col">
</div>
<div class="col">
</div>
<div class="col">
</div>
</div>
<div class=" row-cols-1 row-cols-md-3 g-4 py-5 ">
<div class="col">
</div>
<div class="col">
</div>
<div class="col">
</div>
</div>
<div class=" row-cols-1 row-cols-md-3 g-4 py-5 ">
<div class="col">
</div>
<div class="col">
</div>
<div class="col">
</div>
</div>
<div class=" row-cols-1 row-cols-md-3 g-4 py-5 ">
<div class="col">
</div>
<div class="col">
</div>
<div class="col">
</div>
</div>
<div class=" row-cols-1 row-cols-md-3 g-4 py-5 media ">
<div class="col px-5 ">
<p class="twentyfive ">Lorem ipsum dolor sit amet, consectetur adipiscing elit</p>
<p class="fifteen">Lorem ipsum dolor sit amet, consectetur adipiscing elitLorem ipsum dolor sit amet,
consectetur adipiscing elitLorem ipsum dolor sit amet, consectetur adipiscing elit</p>
</div>
<div class="col">
</div>
<div class="col">
</div>
</div>
<div class="container py-5">
<div class=" ">
<div class="text-start px-5 py-5">
<p class="adm-nf-twenty"></p>
<p class="adm-nf-twentyitalic"></p>
</div>
</div>
</div>
<div class="container py-5">
<div class=" ">
<div class="text-start px-5 py-5">
</div>
</div>
</div>
<div class="container py-5">
<div class=" ">
<div class="text-start px-5 py-5">
</div>
</div>
</div>
<div class="container py-5">
<div class=" ">
<div class="text-start px-5 py-5">
</div>
</div>
</div>
<div class="container py-5">
<div class="bluebox ">
<div class="text-start px-5 py-5">
<p class="twenty">Lorem ipsum dolor sit amet, consectetur adipiscing elit</p>
<p class="twentyitalic">Lorem ipsum dolor sit amet, consectetur adipiscing elit</p>
<p class="fifteenwhite">Lorem ipsum dolor sit amet, consectetur adipiscing elit</p>
<p class="fifteenwhite">Lorem ipsum dolor sit amet, consectetur adipiscing elit</p>
<p class="fifteenwhite"> Lorem ipsum dolor sit amet, consectetur adipiscing elit</p>
</div>
</div>
</div>
My opinion is you should consider using offset for the best practice, also you can customize it for all available screen size Bootstrap provided.
Like this for example :
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<div class="container">
<div class="row">
<div class="col-md-4">normal .col-md-4</div>
<div class="col-md-4 offset-md-4">.col-4 getting offset for 4 col in md screen size</div>
</div>
<div class="row">
<div class="col-md-3 offset-md-3">.col-md-3 getting offset for 3 col in md screen size</div>
<div class="col-md-3 offset-md-3">.col-md-3 getting offset for 3 col in md screen size</div>
</div>
<div class="row">
<div class="col-md-6 offset-md-3">.col-md-6 getting offset for 3 col in md screen size</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
Also always remember offset always arrange the column to the right
I have a row with cards and images. I can see that the columns are not the same size (see picture). Do I need to set width and height for the images that the three are uniform in size?
I would appreciate your help!
see here
Here is my code:
<div class="row justify-content-md-center">
<div class="col-md-6 col-lg-4">
<div class="os-animation" data-animation="fadeInLeft">
<img class="card-img-top" src="/images/Bild_18.JPG" alt="Card image cap">
<div class="pricing-column text-center">
<h3>Lorem</h3>
<p class="ptext">Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor</p>
<div class="pricing-features text-sm-left">
<h4><span class="item">Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor
</h4>
</div>
<a class="btn btn-secondary btn-sm" href="/agostar" id="btn_1">mehr Erfahren</a>
</div>
</div>
</div>
<div class="col-md-6 col-lg-4">
<div class="os-animation" data-animation="fadeInUp">
<img class="card-img-top" src="/images/Bild_10.JPG" alt="Card image cap">
<div class="pricing-column text-center">
<h3>Lorem</h3>
<p class="ptext">Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor</p>
<div class="pricing-features text-sm-left">
<h4><span class="item">Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor
</h4>
</div>
<a class="btn btn-secondary btn-sm" href="/agotable" id="btn_1">mehr Erfahren</a>
</div>
</div>
</div>
<div class="col-md-6 col-lg-4">
<div class="os-animation" data-animation="fadeInRight">
<img class="card-img-top" src="/images/Bild_120.jpg" alt="Card image cap">
<div class="pricing-column text-center">
<h3>Lorem</h3>
<p class="ptext">Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor</p>
<div class="pricing-features text-sm-left">
<h4><span class="item">Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor
</h4>
</div>
<a class="btn btn-secondary btn-sm" href="/custom" id="btn_1">mehr Erfahren</a>
</div>
</div>
</div>
Hello you have 3 ways to achieve such design:
Add class <div class="card h-100">, that will give you 100% height.
Use Bootstrap equal-height columns Check this link
You can achieve it by using a template such as follows
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Card</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class="card-group">
<div class="card">
<img class="card-img-top" src="https://www.w3schools.com/w3images/fjords.jpg" alt="Card image cap">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">It's a broader card with text below as a natural lead-in to extra content. This content is a little longer.</p>
</div>
<div class="card-footer">
<small class="text-muted">Last updated 3 mins ago</small>
</div>
</div>
<div class="card">
<img class="card-img-top" src="https://www.w3schools.com/w3images/fjords.jpg" alt="Card image cap">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">This card has supporting text below as a natural lead-in to additional content.</p>
</div>
<div class="card-footer">
<small class="text-muted">Last updated 3 mins ago</small>
</div>
</div>
<div class="card">
<img class="card-img-top" src="https://www.w3schools.com/w3images/fjords.jpg" alt="Card image cap">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">It's a broader card with text below as a natural lead-in to extra content. This content is a little longer.This card has even longer content than the first to show that equal height action.</p>
</div>
<div class="card-footer">
<small class="text-muted">Last updated 3 mins ago</small>
</div>
</div>
</div>
</body>
</html>
If you want your images to all be the same size, you can set them as the background-image property on a div. Since padding-bottom is based on the width of the element, you can use it to create a fixed aspect ratio that all of your images will respect, as demonstrated in the .standardizedImage divs.
Using background-size: cover will crop to fit as seen below, if you want to display the entire image, though possibly at the cost of blank space to the top or sides, use background-size: contain
.card {
display: inline-block;
border: 1px solid black;
margin: 10px;
width: 100px;
}
p {
padding: 10px;
}
img {
width: 100%;
}
.standardizedImage {
padding-bottom: 40%;
background-size: cover;
background-position: center center;
width: 100%;
}
<h3>As images</h3>
<div class="card">
<img src="https://www.fillmurray.com/300/100" />
<p>Content goes here.</p>
</div>
<div class="card">
<img src="https://www.fillmurray.com/300/100" />
<p>Content goes here.</p>
</div><div class="card">
<img src="https://www.fillmurray.com/300/120" />
<p>Content goes here.</p>
</div>
<h3>As background images</h3>
<div class="card">
<div class="standardizedImage" style="background-image: url(https://www.fillmurray.com/300/100);"></div>
<p>Content goes here.</p>
</div>
<div class="card">
<div class="standardizedImage" style="background-image: url(https://www.fillmurray.com/300/100);"></div>
<p>Content goes here.</p>
</div>
<div class="card">
<div class="standardizedImage" style="background-image: url(https://www.fillmurray.com/300/120);"></div>
<p>Content goes here.</p>
</div>
I had to make div table, because I didn't see a way to do it with a bootstrap table element.
Here is image:
Here is the code:
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row border-top bg-primary pt-3 pb-0 mt-5">
<div class="col-12">
<p class="text-white"><b>Lorem ipsum</b></p>
</div>
</div>
<div class="row border-left border-right text-center">
<div class="col-8 pt-3 pb-0 border-right">
<p>Lorem ipsum</p>
</div>
<div class="col-4 pt-3 pb-0">
<p>Lorem ipsum</p>
</div>
</div>
<div class="row border text-center">
<div class="col-10">
<div class="row">
<div class="col pt-3 pb-0 border-right">
<p>Lorem ipsum dolor sit amet, consectetur</p>
</div>
<div class="col pt-3 pb-0 border-right">
<p>Lorem ipsum dolor sit amet, consectetur</p>
</div>
<div class="col pt-3 pb-0 border-right">
<p>Lorem ipsum dolor sit amet, consectetur</p>
</div>
<div class="col pt-3 pb-0 border-right">
<p>Lorem ipsum dolor sit amet, consectetur</p>
</div>
<div class="col pt-3 pb-0 border-right">
<p>Lorem ipsum dolor sit amet, consectetur</p>
</div>
</div>
<div class="row border-top">
<div class="col bg-primary-dark pt-3 pb-0" style="width: 80%; flex-basis: unset;">
<p class="text-white"><b>Lorem ipsum</b></p>
<p class="text-white">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
</p>
</div>
<div class="col border-right" style="width: 20%; flex-basis: unset;"></div>
</div>
<div class="row border-top">
<div class="col border-right" style="width: 20%; flex-basis: unset;"></div>
<div class="col bg-info-dark pt-3 pb-0 border-right" style="width: 80%; flex-basis: unset;">
<p class="text-white"><b>Lorem ipsum</b></p>
<p class="text-white">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
</p>
</div>
</div>
</div>
<div class="col-2 pt-3">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore
</p>
</div>
</div>
Now I want this to be responsive. Horizontal scroll, or any other way, any suggestions would be greatly appreciated
The class col in bootstrap will divide the row into amount of col elements you added.To make it responsive specify width of element for each screen type, using such classes as col-sm-12 (full width on small devices), col-md-6 (two column grid for medium screens) etc. Don't forget, bootstrap is mobile first.
https://codepen.io/jakedx6/pen/EOYBEM
In the above demo, I would expect the center 'col' to shrink but something seems to stop it. The code sample is originally for an angular 7 application using ngx-bootstrap for the dropdown so you will see those attributes in the code below.
Not sure if the issue is something not set up correctly, bootstrap 4 or CSS grid
HTML for referance:
<div class="page-layout">
<div class="page-header p-3">
<div class="text-truncate" body>Main Header</div>
</div>
<div class="page-subheader p-3">
<div class="text-truncate" body>Sub-Header</div>
</div>
<div class="page-content">
<main role="main" class="container-fluid">
<div class="row mx-3 my-3">
<div class="col-auto p-0">
<div class="row">
<div class="index-number mb-3 font-weight-bold py-2">1</div>
</div>
<div class="row">
<div class="index-number mb-3 font-weight-bold py-2">2</div>
</div>
<div class="row">
<div class="index-number mb-3 font-weight-bold py-2">3</div>
</div>
</div>
<div class="col px-0" cdkDropList>
<div class="col mb-3 pr-0 ngFor" cdkDrag>
<div class="card">
<div class="row m-0">
<div class="col-auto px-0" style="background:#ddd">
<div cdkDragHandle class="col-auto border-right draggable py-2">
Auto Left
</div>
</div>
<div class="col text-truncate py-2">
Center Text, This can be a pretty long text. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
</div>
<div class="col-auto border-left" style="background:#ddd">
<div class="btn-group py-2 ">
Auto-Right
</div>
</div>
</div>
</div>
</div>
<div class="col mb-3 pr-0 ngFor" cdkDrag>
<div class="card">
<div class="row m-0">
<div class="col-auto px-0" style="background:#ddd">
<div cdkDragHandle class="col-auto border-right draggable py-2">
Auto Left
</div>
</div>
<div class="col text-truncate py-2">
Center Text, This can be a pretty long text. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
</div>
<div class="col-auto border-left" style="background:#ddd">
<div class="btn-group py-2">
Auto-Right
</div>
</div>
</div>
</div>
</div>
<div class="col mb-3 pr-0 ngFor" cdkDrag>
<div class="card">
<div class="row m-0">
<div class="col-auto px-0" style="background:#ddd">
<div cdkDragHandle class="col-auto border-right draggable py-2">
Auto Left
</div>
</div>
<div class="col text-truncate py-2">
Center Text, This can be a pretty long text. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
</div>
<div class="col-auto border-left" style="background:#ddd">
<div class="btn-group py-2">
Auto-Right
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</main>
</div>
</div>
SCSS defining the grid:
.page-layout {
display: grid;
height: 100%;
grid-template-columns: 1fr;
grid-template-rows: 56px 56px 1fr;
grid-template-columns: 1fr;
grid-template-areas: "page-header" "page-subheader" "page-content";
.page-header {
grid-area: page-header;
background-color: #eee;
border-bottom: solid 1px #bbb;
height: 2em;
min-height: 56px; //fix for ie
}
.page-subheader {
grid-area: page-subheader;
background-color: #eee;
border-bottom: solid 1px #bbb;
height: 2em;
min-height: 56px; //fix for ie
}
.page-content {
grid-area: page-content;
}
}
without the CSS grid layout it works as expected:
https://codepen.io/jakedx6/pen/EOxjWv (demo without CSS grid)
Edit: when I change the grid 1fr unit to 100% it works as expected. Is there a way to fix this and still use the 1fr unit type?
The fix I implemented was using 100% instead of 1fr when defining the grid. I would love to know if there is a better way of fixing this!