I've created a div that uses flex to display 5 icons inside of a container. Each of these containers has a div with a text element inside. This text div has an opacity of 0 by default and is changed to 1 when it's parent is hovered.
The problem happens when you move your mouse into the text div. For some reason, it defaults to showing the text div of the very last parent element. I've recreated the issue here: JSFiddle
Here is the basic structure of the HTML. I've removed the last 3 content divs for readability.
<div class="container-fluid icon-repeater-fluid-container pt-5 pb-5">
<div class="container icon-repeater-container pb-lg-5">
<div class="text-center d-flex flex-column flex-lg-row justify-content-center justify-content-lg-around">
<div class="p-3 learn-more-main">
<i class="far fa-address-card learn-more-icon"></i>
<p class="learn-more-labels">Learn More</p>
<div class="learn-more-content-container">
<div class="learn-more-content h-100 w-100 d-flex justify-content-center align-items-center p-3">
<i class="fas fa-caret-up learn-more-caret caret-1"></i>
<p class="mb-0 text-center">
I am a sentence that belongs under the Learn More container. I should really only be a few sentences.
</p>
</div>
</div>
</div>
<div class="p-3 learn-more-main">
<i class="fab fa-angular learn-more-icon"></i>
<p class="learn-more-labels">Angular Skills</p>
<div class="learn-more-content-container">
<div class="learn-more-content h-100 w-100 d-flex justify-content-center align-items-center p-3">
<i class="fas fa-caret-up learn-more-caret caret-2"></i>
<p class="mb-0 text-center">
I am a sentence that belongs under the Angular Skills. I should really only be a few sentences.
</p>
</div>
</div>
</div>
...
</div>
</div>
</div>
and here's the line of css that I'm using to show the appropriate div
.learn-more-main:hover .learn-more-content-container{
opacity:1;
}
If you hover over any of the .learn-more-main containers, it shows the appropriate text. But if you try to move your mouse into one of these text containers, it removes the appropriate container and puts the very last container there instead.
Set your:
.learn-more-content-container{
position: absolute;
bottom:0;
left:0;
right:0;
opacity:0;
transition: opacity .25s;
pointer-events: none;
And on hover your back to pointer-events: auto; :
.flex-column .learn-more-main:hover > .learn-more-content-container{
opacity:1;
pointer-events: auto;
}
Your problem was the opacity, elements are still there and moving mouse it was losing selection, if you would go with mouse up from bottom it always shows last one because it was last learn-more-main in your HTML markup.
Related
I'm trying to add an icon to the bootstrap card. I want the icon, title, and text in the same row. for that, I used float left on the card icon but it didn't work. can someone advise how to do this?
thank you :)
.card-icon {
background: rgba(255,255,255,0.9);
border-radius: 50%;
width: 60px;
height: 60px;
float: left;
margin-right: 15px;
text-align: center;
}
.card-icon i {
font-size: 48px;
}
<div class="card m-b-30 card-body">
<div class="card-icon"><i class="mdi mdi-database"></i></div>
<h3 class="card-title font-24">Available Credits: 2</h3>
<p class="card-text">2 Email Verification Credits Left</p>
<div class="d-flex">
Buy More Credits
Track Your Credits
</div>
</div>
A good way to solve this problem is use flexbox.
Bootstrap 4 have a class d-flex to do that. By default, the flex-direction is row, so you will have your i h3 and p in the same row. And to make sure that the elements will fill all the width available, add flex-fill class in each element. The align-items-center class will try to center the vertical axis (but the margin top/bottom of elements can override this behavior).
<div class="card m-b-30 card-body">
<div class="d-flex align-items-center">
<div class="card-icon flex-fill"><i class="mdi mdi-database">a</i></div>
<h3 class="card-title font-24 flex-fill">Available Credits: 2</h3>
<p class="card-text flex-fill">2 Email Verification Credits Left</p>
</div>
<div class="d-flex">
Buy More Credits
Track Your Credits
</div>
</div>
Add your h3 and p elements to the inside of your div element. If this doesn't work make the widths of the elements percentages of the page, making sure they add up to 100% or less.
Edit:
In your css add
display: inline-block;
To ALL those elements.
As you can see, i do have 3 bootstrap cards having 3 images with different heights. I want to make the images having same height compared to others (like the bigger one "takes the lead" and all the other one in the row adapting to this bigger one).
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class="col-lg-4 col-md-6 mb-4">
<div class="card h-100">
<img class="card-img-top" src="/images/produits/1" alt=""><hr>
<div class="card-body">
<h6 class="card-title">
slt la mif
</h6>
<small class="text-muted">Puissance : 10 à 100W</small>
</div>
</div>
</div>
I already put the h-100 class in the card div but it only adapts the card's height, and I want the images to be adapted (in order to not have the blank after the text), how to do that pls?
Bootstrap class card-body has property flex: 1, it means, that this element also grows for available space.
You can add some special class, for example to row, or higher, where you use card, to modify that parameter. Something like that.
.special .card-body {
flex-grow: 0;
}
Also wrap link image with div which has class="flex-fill", it makes grow the link images.
Look into the snippet, I;ve added special class to row, and set different height to link images to illustrate the idea.
UPDATE. Made link images center
Play with flexboxes. For example: add to div which wraps <a> class d-flex it will make this div with display: flex. And then you can add to this div classes justify-content-center and align-items-center, but I prefer in your case to add class m-auto to <a>, it gives margin: auto, which make element centralized with flex parent. Look into snippet.
.special .card-body {
flex-grow: 0;
}
.img_mock1 {
padding: 50px;
background-color: red;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet" />
<div class="row special">
<div class="col-lg-4 col-md-6 mb-4">
<div class="card h-100">
<div class="flex-fill d-flex">
<span class="img_mock1"></span>
</div>
<hr>
<div class="card-body">
<h6 class="card-title">
slt la mif
</h6>
<small class="text-muted">Puissance : 10 à 100W</small>
</div>
</div>
</div>
<div class="col-lg-4 col-md-6 mb-4">
<div class="card h-100">
<div class="flex-fill d-flex">
<a href="/led/catalogue/produit/1" style="height:300px;" class="m-auto">
<img src="" alt="">
</a>
</div>
<hr>
<div class="card-body">
<h6 class="card-title">
slt la mif
</h6>
<small class="text-muted">Puissance : 10 à 100W</small>
</div>
</div>
</div>
</div>
Use the following CSS
.card-img-top {
width: 100%;
height: 15vw;
object-fit: cover;
}
The object-fit: cover; enables zoom instead of image stretching.
Give fix height suppose 150px to the wrapper of image(anchor tag). Then for the image tag use max-width: 100%, height: auto, display: block
give the image div a fixed height, use the height preference of the largest image to put a fix height on the dive of the image, this will allow the all to show the same way.
So I'm writing a code where I need to evenly place cards next to each other with rows when using flex. However, I'm getting some spacing on the right side and can't work out a reason why is that happening. I tried inspecting the element, but it just shows the entire card extends to the right, but there is no real reason behind why it does that. I've scrolled through CSS code, and there's no additional width on the right.
<section id="jobs">
<!--Employing cards-->
<div class="container-fluid container-fluid-shorter bg-white">
<!--Assistant card-->
<div class="row">
<div class="col-md-6 col-lg-4 my-3">
<div class="card width-37">
<div class="card-body d-flex align-items-center justify-content-between">
<h6 class="card-title font-weight-lighter pb-3">Custom units</h6>
<p class="card-text">
<h4 class="text-grey font-weight-light text-capitalize pb-3 pt-3">home page hero</h4>
</div>
</div>
</div>
<div class="col-md-6 col-lg-4 my-3">
<div class="card width-37">
<div class="card-body d-flex align-items-center justify-content-between">
<h5 class="card-title font-weight-lighter pb-3">Vlastní jednotky</h5>
<p class="card-text">
<h4 class="text-grey font-weight-light text-capitalize pb-3 pt-3">home page hero</h4>
</div>
</div>
</div>
<div class="col-md-6 col-lg-4 my-3">
<div class="card width-37">
<div class="card-body d-flex align-items-center justify-content-between">
<h5 class="card-title font-weight-lighter pb-3">Vlastní jednotky</h5>
<p class="card-text">
<h4 class="text-grey font-weight-light text-capitalize pb-3 pt-3">home page hero</h4>
</div>
</div>
</div>
</div>
</div>
<!--End of employing cards section-->
</section>
Adjustments I've made to the CSS :
.width-37{
max-width: 37.5vh;
}
.card-body{
padding-left: 0; !important;
padding-right: 0; !important;
}
I'm trying to place all the items in the row where there is a small spacing between each item and all items will create rows as you set rows for different screen sizes large, medium, small. For some reason flex item is doing spacing on the right side of each item there is. It is 480 pixels wide and 180 height. I would like it to be 180 x 180 pixels so same height and width. Anyone got an idea on why is this happening?
.width-37{
max-width: 37.5vh;
}
This is causing the spacing on right side. Also, there should be no ; before !important
This is due to how block level elements are rendered and not a Flexbox specific issue. Block level elements always take up the full width of the containing element. If you set a width on a block level element, and it does not fill the containing element, the remaining space will be filled with margin.
Example
div {
min-height: 24px;
}
div:nth-child( 1 ) {
width: 100px;
background-color: rebeccapurple;
}
div:nth-child( 2 ) {
max-width: 200px;
background-color: gold;
}
div:nth-child( 3 ) {
width: 20vw;
background-color: silver;
}
<div></div>
<div></div>
<div></div>
The default flow of content is left to right and why the element is to the left. All the space to the right of each element is margin. This is what is happening inside of your Bootstrap column elements.
This is the why
*Rows are wrappers for columns. Each column has horizontal padding (called a gutter) for controlling the space between them. This padding is then counteracted on the rows with negative margins. This way, all the content in your columns is visually aligned down the left side.
Documentation here
In order to remove the padding on your gutter you can add the class no-gutters to your row.
Morning,
I am trying to put my bootstrap card element in a row by 3 cards, cards need to be of the same hight and width and have spacing in between them. For example if I have 7 card I will have 3 rows by three cards and the last row with one element will still be the same size as the card above it.
My code is:
<div class="container pt-2">
<div *ngFor="let g of carMultiArray">
<div class="row">
<div class="col-12">
<div class="card border-0 boxShadow no-padding col-lg-4 col-md-12 col-sm-12 col-xs-12" *ngFor="let t of g">
<a data-toggle="modal" href="'#'+ 'car'+t.Id" class="card-link" [attr.data-target]="'#'+ 'car'+t.Id" style="color:black; text-decoration: none;">
<img class="card-img-top rounded-0" src="{{t.MainImage}}">
</a>
<div class="card-body text-center">
<div class="my-arrow">
<img *ngIf="!t.Verified" src="../../icons/error.png">
<img *ngIf="t.Verified" src="../../icons/checked.png">
</div>
<h5 class="card-title">{{t.Title}} {{t.Kubatura}} {{t.BodyType}}</h5>
<h6 class="card-subtitle mb-2 text-muted">{{t.FuelType}} {{t.GearBox}} {{t.Horsepower}}
{{t.OdometerReading}}</h6>
<a [routerLink]="['/car', t.Id]" class="card-link">Daugiau</a>
<a class="card-link">{{t.City}}</a>
<a class="card-link">{{t.FirstRegistration}} </a>
</div>
</div>
</div>
</div>
</div>
</div>
My css (Though it does not influence the problem):
.boxShadow {
display: inline-block;
vertical-align: middle;
box-shadow: 0 0 8px rgba(0, 0, 0, 0.6);
}
.card-body {
position: relative;
}
.my-arrow {
position: absolute;
top: -10%;
right: 10%;
}
.card-img-top {
width: 100%;
height: 17vw;
object-fit: cover;
}
.card{
width: 90%;
}
.no-padding {
padding-left: 0;
padding-right: 0;
}
The problem that I am having is that with the current code the cards do not have any margin or padding in between them when in one row. As you may have seen I have removed all padding in class .no-padding as if there is any padding even by default the images inside the card get smaller however the cards itself do not and they still touch each other, removing padding brings the cards to look the same and the way they suppose to, however they have no space in between them, adding margin, any margin, pushes the 3 card to a new line.
If I put the elements in a card-group instead of putting it in rows and columns, the result is they have no space in between them, adding some breaks the grid again. Putting it in card-deck results the last card which is one in a row to take up the whole space of the last row, trying to set the width of the cards in a card-deck, for some reason when the elements have 33% or 30% have different width, for example the 3 cards above will have the same width however the single card bellow will still be a little bit wider.
Adding the cards to card-columns, will result in having the cards different hights, trying to make it the same will result in images in the cards not aligning with each other.
While adding everything like you see right now in the code, in a row and then in col-12 allows to handle everything and the way I want it, it removes spacing between cards and as I said if adding margin it pushes the last 3rd card to new line if adding padding image gets smaller then the card.
How would I achieve my wanted result?
Hope this makes sense, if not, please ask.
I think you should use .justify-content-between class from bootstrap4 and try remove your display: inline-block attr from .boxShadow
FOR BOOTSTRAP REFER THIS LINK..
W3 bootstrap 4 card deck
FOR WITHOUT BOOTSTRAP REFER THE CODE BELOW..
.parent{
text-align:center;
}
.padding_maker{
display:inline-block;
padding:10px;
}
.children{
display:inline-block;
background-color:black;
height:300px;
width:150px;
color:white;
}
<div class="parent">
<div class="padding_maker">
<div class="children">
<h3>Your Card</h3>
</div>
</div>
<div class="padding_maker">
<div class="children">
<h3>Your Card</h3>
</div>
</div>
<div class="padding_maker">
<div class="children">
<h3>Your Card</h3>
</div>
</div>
<div class="padding_maker">
<div class="children">
<h3>Your Card</h3>
</div>
</div>
<div class="padding_maker">
<div class="children">
<h3>Your Card</h3>
</div>
</div>
<div class="padding_maker">
<div class="children">
<h3>Your Card</h3>
</div>
</div>
<div class="padding_maker">
<div class="children">
<h3>Your Card</h3>
</div>
</div>
<div class="padding_maker">
<div class="children">
<h3>Your Card</h3>
</div>
</div>
<div class="padding_maker">
<div class="children">
<h3>Your Card</h3>
</div>
</div>
</div>
I'm reaching this sketch:
how I can push image towards bottom, then I can align content noramally. For some unknown reason for me, content reacting like a row, not a column
<div class="d-flex flex-wrap">
<div class="premises">
<div class="left-wrapper">
<img class="img-responsive" src="http://i.imgur.com/riJ1LKY.jpg" />
</div>
<div class="right-wrapper align-self-end">
<div class="title">
<p class="">Title text</p>
</div>
<div class="ordered-data d-inline-flex justify-content-between">
<p class="">**.**.**</p>
<p class="">**:** - **:**</p>
</div> <div class="destination d-inline-flex justify-content-start">
<p class="">Destination</p>
</div>
<div class="footer-options d-inline-flex justify-content-between">
<p class="">Submit</p>
<p class="">Cancel</p>
</div>
</div>
</div>
</div>
Fiddle
First off, your .premises should have flex-direction: row; (or remove it for default behaviour) to get closer to the result in your original image.
Then you should set a min-height: 0; to your left and right wrappers to counter flex's min-height: auto; behaviour, and remove the height: 100%; as the value isn't explicitly set in the parent. I also recommend setting vertical-align: bottom; to your image tag.
Here is an updated, working fiddle: https://jsfiddle.net/ybxbx55m/