Bootstrap - cards in a row have a strange width - html

The cards html looks like this:
<div class="container-fluid">
<img src="http://clipart-library.com/img/1279251.png" style="max-width: 100px; filter: invert(1); float: left">
<h1 style="color: white;">Favourite <br>apps </h1>
<div class="row flex-row overflow-auto flex-nowrap" id="favourites" style="max-height: 400px">
<div tabindex="0" class="card" style="max-width: 18rem;" id="ytdroid2">
<img src="https://tse2.mm.bing.net/th?id=OIP.qHEnapkicCACp91KvwDYUAHaFj" class="card-img-top">
<div class="card-body" style="height: 200px;">
<h1 class="card-title" style="color: white;">
<b>Test 2</b>
</h1>
</div>
</div>
<div tabindex="0" class="card" style="max-width: 18rem;" id="ytdroid">
<img src="https://tse2.mm.bing.net/th?id=OIP.qHEnapkicCACp91KvwDYUAHaFj" class="card-img-top">
<div class="card-body" style="height: 200px;">
<h1 class="card-title" style="color: white;">
<b>Test 1</b>
</h1>
</div>
</div>
</div>
</div>
and it creates:
The background color for both the card and the card body is set in a css sheet to white with an opacity of 0.4. As you can see the width of the card is bigger than the width of the image and the card body. If i remove the row related classes from this, they are the same size however this will not work as they stack vertically. I cannot use a card deck because i want these to have a fixed width and be horizontally scrollable which doesn't seem to work with a card deck. How can I make the width of the card match the width of the image and body?

The cards should be placed inside columns.
"Rows are wrappers for columns. Each column has horizontal padding
(called a gutter) for controlling the space between them... "
Also...
"When building grid layouts, all content goes in columns. The
hierarchy of Bootstrap’s grid goes from container to row to column to
your content. "
You don't want to...
Use a col-* without a row as it's immediate parent.
Place content directly inside the row.

Regardless of how you use the grid classes (correctly or incorrectly), in your case the source of the space is padding BS applies to .card.
You can add .p-0 to the .card or otherwise set the padding to zero on the element. In the snippet below I have added .p-0 only to the first card for comparison:
div.container-fluid {
background-color: DarkSlateBlue;
}
div.card,
div.card-body {
background-color: rgba(255, 255, 255, 0.4);
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-KyZXEAg3QhqLMpG8r+8fhAXLRk2vvoC2f3B09zVXn8CA5QIVfZOJ3BCsw2P0p/We" crossorigin="anonymous">
<div class="container-fluid">
<img src="http://clipart-library.com/img/1279251.png" style="max-width: 100px; filter: invert(1); float: left">
<h1 style="color: white;">Favourite <br>apps </h1>
<div class="row flex-row overflow-auto flex-nowrap" id="favourites" style="max-height: 400px">
<div tabindex="0" class="card p-0" style="max-width: 18rem;" id="ytdroid2">
<img src="https://tse2.mm.bing.net/th?id=OIP.qHEnapkicCACp91KvwDYUAHaFj" class="card-img-top">
<div class="card-body" style="height: 200px;">
<h1 class="card-title" style="color: white;">
<b>Test 2 .card.p-0</b>
</h1>
</div>
</div>
<div tabindex="0" class="card" style="max-width: 18rem;" id="ytdroid">
<img src="https://tse2.mm.bing.net/th?id=OIP.qHEnapkicCACp91KvwDYUAHaFj" class="card-img-top">
<div class="card-body" style="height: 200px;">
<h1 class="card-title" style="color: white;">
<b>Test 1 .card</b>
</h1>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.1.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-U1DAWAznBHeqEIlVSCgzq+c9gqGAJn5c/t99JyeKa9xxaYpSvHU5awsuZVVFIhvj" crossorigin="anonymous"></script>

Related

How to fixed TEXT center in HTML css

i have image and text like this image
When width logo image is correct Text is center , its is work
But when i have image box shape like bellow
TEXT not center, how to fixed text center without deppends image width ??
this is my code..
<div class="row">
<div class="col-12 mb4" style="display: flex; display: -webkit-box;margin-top:30px; ">
<th><img style="max-width: 100%; height: auto;" t-att-src="'data:image/png;base64,%s' % to_text(logo)"/></th>
<h4 style="margin-top:60px;margin-left:140px;font-size:40px;font-weight:bold;width:600px;text-align:center;"><th><span t-esc="nama_ou"/></th> </h4>
<!-- <h4 style="max-width:450px;margin-left:500px;overflow-wrap: break-word;font-size:30px;"> <th><span t-esc="operating_unit"/></th> </h4> -->
</div>
<div class="col-9 text-right" style="margin-top:22px;" name="moto"/>
</div>
Plis help, i stack about this, Thanks
You need to change in your html structure. Use below html and check it.
<div class="row">
<div class="col-12 mb4" style="display: flex; display: -webkit-box;margin-top:30px; ">
<div><img style="max-width: 100%; height: auto;" t-att-src="'data:image/png;base64,%s' % to_text(logo)"></div>
<h4 style="margin-top:60px;margin-left:140px;font-size:40px;font-weight:bold;width:600px;text-align:center;">
<span t-esc="nama_ou">
</h4>
<!-- <h4 style="max-width:450px;margin-left:500px;overflow-wrap: break-word;font-size:30px;"> <th><span t-esc="operating_unit"></th> </h4> -->
</div>
<div class="col-9 text-right" style="margin-top:22px;" name="moto"></div>
</div>

How to make text written on the image when decreasing the screen size

I am facing a problem in which I want the content which is written on the left half of the screen should be written on the image which is on the right side when decreasing the screen size.
for reference, check the image as I want this problem image
to be like this Solution image when I decrease the size of my screen, But my screen looks like this at present. I need the solution as soon as possible.
Note: I used mostly pre-defined classes of bootstrap4 for this.
code is-
<div class="row">
<div class="col p-0 col-6 bg-creame" style="height: 100vh;">
<div class="h-100 d-flex flex-column justify-content-start pt-5">
<div class="m-5 pt-5 pr-5">
<h1 class="mb-5"><b style="font-weight: 900;"><b>Contact</b></b></h1>
<p class="m-0" style="font-weight: 900;font-size: 18px;">Email Address</p>
<p><a style="color: inherit !important;font-size: 23px;" href="mailto:support#regid.ca">support#XXX.com</a>
</p>
<p class="m-0 mt-5" style="font-weight: 900;font-size: 18px;">Mailing Address</p>
<p style="font-size: 23px;">
XXXXXX, 77 XXXX XXX X,
XXXXXX, XX XXX 6XX
</p>
<div class="d-none d-lg-block">
<button class="text-uppercase btn pr-5 pl-5 color-creame bg-orange"
style="border-radius: 50px; letter-spacing: 1px;font-size: 20px;">
Contact Us
</button>
</div>
</div>
</div>
</div>
<div class="col p-0 col-6 bg-orange" style="height: 100vh;">
<div style="position: absolute; bottom: 0; right: 0;">
<div class="h-50 bg-orange d-flex flex-column justify-content-end" style="padding-top: 14rem;">
<div class="text-center p-4">
<i class="fas fa-arrow-up bg-black" style="font-size: 2rem;"></i>
</div>
</div>
</div>
<div class="d-flex flex-column h-100">
<img height="100%" width="100%" src="./assets/img/Rectangle 8 (2).png" class="img img-responsive">
</div>
</div>
</div>
You could use z-index to push the image behind the text and do something like this
#media (max-width: 600px) {
img {
width: 100%;
z-index: -1;
}
div {
z-index: 1;
}
}

background color is not applied?

I am stuck with a problem , when am trying to give background colour on my top bar its won't applied , I tried lots of time but still its won't working, please try to fix my error
This is my simple top bar code
topbar.html
<div class="header-top bg-dark" style="background-color: black;">
<div class="container-fluid bg-dark" style="background-color: black;">
<div class="left-side float-left ml-5">
<p>Search</p>
<p style="text-indent: 20px;">About Us</p>
<p style="text-indent: 20px;">Contact Us</p>
</div>
<div class="right-side float-right mr-5">
<p>Login</p>
<p style="text-indent: 20px;">Register</p>
</div>
</div>
</div>
Two problems:
Your float is breaking the layout, so you need to add the class .clearfix to the parent to fix it.
The class bg-dark adds !important, so if you want to override it, you need to do like background-color: black !important;
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<div class="header-top bg-dark" style="background-color: black !important;">
<div class="container-fluid bg-dark clearfix" style="background-color: black !important;">
<div class="left-side float-left ml-5">
<p>Search</p>
<p style="text-indent: 20px;">About Us</p>
<p style="text-indent: 20px;">Contact Us</p>
</div>
<div class="right-side float-right mr-5">
<p>Login</p>
<p style="text-indent: 20px;">Register</p>
</div>
</div>
</div>
i think because you are using inline css, you could do like this
open another file for css and give it the
css file
mycolor{ background-color: black;}
you are getting other color because of the class you are using bg-dark so either you remove that from div class names or replace your codes with following lines :
<div class="header-top bg-dark" style="background-color: black !important; ">
<div class="container-fluid bg-dark clearfix" style="background-color: black !important;">
OR
<div class="header-top" style="background-color: black; ">
<div class="container-fluid clearfix" style="background-color: black;">
this !important will overwrite bg-dark attribute of the div class
Instead of using inline styles for multiple paragraph or other repeating elements, you can simply put <styles> tag and add your styles there so it will be more readable or put your styles in different file and link it to your html.
As for the code, you can try the !important ending if the style is not applied, also you need to change the color of your text
Here is an example
<div class="header-top bg-dark">
<div class="container-fluid bg-dark clearfix">
<div class="left-side float-left ml-5">
<p>Search</p>
<p>About Us</p>
<p>Contact Us</p>
</div>
<div class="right-side float-right mr-5">
<p>Login</p>
<p>Register</p>
</div>
</div>
<style>
.header-top, .container-fluid {
background-color: black !important;
}
p {
text-indent: 20px;
color: white;
}
</style>

Decreasing Column spacing - Bootstrap 4

I am trying to embed two websites onto my website. My goal is to display these websites next to one another in a custom sized iframe while being responsive to the view port size. I am utilizing Bootstrap 4's column and row functions to try and accomplish this. However, the spacing between the columns is too large:
Note this is a previously asked question and I have looked at the Seen Forum A and SeenForumB however neither have been any good at solving my problem.
code:
<div class="col-auto mb-3">
<div class="card" style="border: none;">
<div class="card-body">
<div class="card container-fluid justify-content-center" style="margin-top: 80px; min-width: 44vw; border: 0;">
<div class="card-header" style="background-color: #3c525d; color: white; width: 100%;">
<b>EXAMPLE WEBSITE
<span style="float: right; font-size: 20px;">
<a style="color: white;" href="https://getbootstrap.com/docs/4.0/getting-started/introduction/">
<i class="fas fa-expand"></i>
</a>
</span>
</b>
</div>
<div class="card-body" style="padding: 0;">
<iframe src="https://getbootstrap.com/docs/4.0/getting-started/introduction/" style="width: 100%; height: 600px; border: none;"></iframe>
</div>
</div>
</div>
</div>
</div>
```
You can use the .no-gutters class to knock off the spacing between the columns. I'd do it on the same line as your row so basically :
<div class="row no-gutters">
In your case - the key element is padding and margin added to .card and .card-body classes. Have a look below what happens if you override margins and paddings to 0. The big gap disappears and you can control it by adding your own paddings and margins according to how big the gap between columns you want to create. Code below:
<div class="container">
<div class="row">
<div class="col-6 m-0 p-0">
<div class="card m-0 p-0" style="border: none;">
<div class="card-body m-0 p-0">
<div class="card container-fluid justify-content-center" style="margin-top: 80px; min-width: 44vw; border: 0;">
<div class="card-header" style="background-color: #3c525d; color: white; width: 100%;">
<b>EXAMPLE WEBSITE
<span style="float: right; font-size: 20px;">
<a style="color: white;" href="https://getbootstrap.com/docs/4.0/getting-started/introduction/">
<i class="fas fa-expand"></i>
</a>
</span>
</b>
</div>
<div class="card-body" style="padding: 0;">
<iframe src="https://getbootstrap.com/docs/4.0/getting-started/introduction/" style="width: 100%; height: 600px; border: none;"></iframe>
</div>
</div>
</div>
</div>
</div>
<div class="col-6 m-0 p-0">
<div class="card p-0 m-0" style="border: none;">
<div class="card-body p-0 m-0">
<div class="card container-fluid justify-content-center" style="margin-top: 80px; min-width: 44vw; border: 0;">
<div class="card-header" style="background-color: #3c525d; color: white; width: 100%;">
<b>EXAMPLE WEBSITE
<span style="float: right; font-size: 20px;">
<a style="color: white;" href="https://getbootstrap.com/docs/4.0/getting-started/introduction/">
<i class="fas fa-expand"></i>
</a>
</span>
</b>
</div>
<div class="card-body" style="padding: 0;">
<iframe src="https://getbootstrap.com/docs/4.0/getting-started/introduction/" style="width: 100%; height: 600px; border: none;"></iframe>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
Another possibility is to recompile bootstrap from scss and override padding's and margin's of columns at the source. That would probably be a cleaner solution but a bit more time consuming.

Issue aligning div's using width and float

So what I am trying to do is align these divs within a bootstrap card. My issue is, I am able to get the left half of it right, but I can't figure out how to align the far right elements. I am currently using width percentages to allow this to stay responsive, though I have one thing set as fixed due to pictures always being the same size.
<div class="card" style="width:65%;float:left;">
<h5 class="card-header">Window Latch Black (Small)</h5>
<div class="card-body clearfix text-center" style="width:100%;display:inline-block;background-color: aqua;">
<div class="cartimage" style="background-color:red;float:left">
<img class="rounded-circle" src="data:image/gif;base64,R0lGODlhAQABAIAAAHd3dwAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" alt="Generic placeholder image" width="140" height="140">
</div>
<div class="carttext" style="height:50%;width:75%;background-color:green;">
khjg
</div>
<div class="cartamt" style="height:50%;width:75%;background-color:yellow;">
amt
</div>
<div class="cartprice" style="height:50%;width:15%;background-color:purple;float:right">
price
</div>
<div class="cartbutton" style="height:50%;width:15%;background-color:pink;float:right">
button
</div>
</div>
</div>
You need to adjust the order and replace 15% with 25% to have a total of 100% per row. You need to also set a height to parent container to use % height with child element:
.rounded-circle {
border-radius:50%;
vertical-align:top;
}
<div class="card" style="width:65%;float:left;">
<h5 class="card-header">Window Latch Black (Small)</h5>
<div class="card-body clearfix text-center" style="width:100%;display:inline-block;background-color: aqua;height:140px">
<div class="cartimage" style="background-color:red;float:left">
<img class="rounded-circle" src="data:image/gif;base64,R0lGODlhAQABAIAAAHd3dwAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" alt="Generic placeholder image" width="140" height="140">
</div>
<div class="cartprice" style="height:50%;width:25%;background-color:purple;float:right">
price
</div>
<div class="carttext" style="height:50%;width:75%;background-color:green;">
khjg
</div>
<div class="cartbutton" style="height:50%;width:25%;background-color:pink;float:right">
button
</div>
<div class="cartamt" style="height:50%;width:75%;background-color:yellow;">
amt
</div>
</div>
</div>
By the way, since you are using Bootstrap V4 you can rely on flex to create your layout:
.rounded-circle {
border-radius: 50%;
vertical-align: top;
}
.cartprice {
background: red;
flex-basis: 75%;
}
.carttext {
background: green;
flex-basis: 25%;
}
.cartbutton {
background: blue;
flex-basis: 75%;
}
.cartamt {
background: yellow;
flex-basis: 25%;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="card">
<h5 class="card-header">Window Latch Black (Small)</h5>
<div class="card-body text-center d-flex">
<div class="cartimage">
<img class="rounded-circle" src="data:image/gif;base64,R0lGODlhAQABAIAAAHd3dwAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" alt="Generic placeholder image" width="140" height="140">
</div>
<div class="d-flex flex-wrap w-100" >
<div class="cartprice">
price
</div>
<div class="carttext">
khjg
</div>
<div class="cartbutton">
button
</div>
<div class="cartamt">
amt
</div>
</div>
</div>
</div>
If you are using bootstrap4, I don't understand why using float...Use boostartp4 [Flex Utilities] classes instead to make these type of grid layout...Also for good practice try to wrap your divs into a wrapper divs
Stack Snippet
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="card">
<h5 class="card-header">Window Latch Black (Small)</h5>
<div class="card-body text-center p-0 d-flex no-gutters" style="background-color: aqua;">
<div class="cartimage" style="background-color:red;">
<img class="rounded-circle" src="data:image/gif;base64,R0lGODlhAQABAIAAAHd3dwAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" alt="Generic placeholder image" width="140" height="140">
</div>
<div class="d-flex flex-column" style="flex: 2;">
<div class="carttext col" style="background-color:green;">
khjg
</div>
<div class="cartamt col" style="background-color:yellow;">
amt
</div>
</div>
<div class="d-flex flex-column col">
<div class="cartprice col" style="background-color:purple">
price
</div>
<div class="cartbutton col" style="background-color:pink">
button
</div>
</div>
</div>
</div>