Hey I just have a simple Card Bootstrap 4 component.
<div class="card">
<div class="card-header">This is my header</div>
<div class="card-block">This is my block</div>
<div class="card-footer">This is my footer</div>
</div>
What I wanted to accomplish was to have the header and footer with a opacity of 1 but the block with a opacity of .4. I tried to use rbga in the background-color style with no luck
.card-block { background-color: rgba(245, 245, 245, 0.4); }
Bootstrap Opacity Classes – Custom CSS Bootstrap Snippets Library / Utilities Examples Currently, Bootstrap 4 does not have any opacity utility classes. You can add this to a custom stylesheet to quickly add the ability to write.opacity- (0-5) to change the opacity of an element.
The opacity property specifies the opacity/transparency of an element. The opacity property can take a value from 0.0 - 1.0. The lower value, the more transparent: The opacity property is often used together with the :hover selector to change the opacity on mouse-over: The first CSS block is similar to the code in Example 1.
The opacity property sets the opacity level for an element. The opacity level describes the transparency level, where 1 is not transparent at all, .5 is 50% visible, and 0 is completely transparent. Set the opacity of an element using .opacity- {value} utilities.
Cards. A card in Bootstrap 4 is a bordered box with some padding around its content. It includes options for headers, footers, content, colors, etc. ... Add the .stretched-link class to a link inside the card, and it will make the whole card clickable and hoverable (the card will act as a link): John Doe.
have you tried using opacity
.special-card {
/* create a custom class so you
do not run into specificity issues
against bootstraps styles
which tends to work better than using !important
(future you will thank you later)*/
background-color: rgba(245, 245, 245, 1);
opacity: .4;
}
<div class="card">
<div class="card-header">This is my header</div>
<div class="card-block special-card">This is my block</div>
<div class="card-footer">This is my footer</div>
</div>
please, try this:
<div class="card-transparent">
<div class="card-header">This is my header</div>
<div class="card-block special-card" style="background-color: rgba(245, 245, 245, 0.4); ">This is my block</div>
<div class="card-footer">This is my footer</div>
</div>
Turns out the bootstrap class .card was overriding the background opacity css style I was trying to set on .card-block regardless of whether I put !important keyword or not.
I was able to fix this by adding the background style to the card and just changing the individual opacities of the .card-header and .card-footer to 1.
.card { background-color: rgba(245, 245, 245, 0.4); }
.card-header, .card-footer { opacity: 1}
Try this approach
HTML
<div class="card text-white bg-success mb-3 mt-4" style= "">
<div class="card-header">Пользователь</div>
<div class="card-body special-card" style="">
<h5 class="card-title">Primary 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>
</div>
</div>
<div class="card text-white bg-primary mb-3" style=" ">
<div class="card-header">Привязанный профиль персонала</div>
<div class="card-body special-card">
<h5 class="card-title">Secondary 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>
</div>
</div>
<div class="card text-white bg-danger mb-3" style=" ">
<div class="card-header">Права доступа профиля персонала</div>
<div class="card-body special-card">
<h5 class="card-title">Success 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>
</div>
</div>
CSS
.special-card {
background-color: rgba(245, 245, 245, 0.4) !important;
}
Your css looks ok. I think the issue is your bootstrap file is overriding your code. Try this to override the code although I wont suggest using !important
.card-block { background-color: rgba(245, 245, 245, 0.4) !important; }
Refer to this link for the overriding. Its called specificity
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With