Can Bootstrap 4 Cards Have Tiled Background Images - html

I am trying to get a card to have a tiled background image. To get a single image background I use:
<div class="card img-fluid">
<img class="card-img-top" src="images/backcard-brushedmetal.jpg">
<div class="card-img-overlay">
<div class="card-body text-justify">
<h3 class="articleh3">xxxDescriptionxxx</h3>
<p>
<img src="images/xxxImagexxx.jpg" alt="xxxDescriptionxxx" height="100" width="80" style="margin-right: 10px;float: left" />
xxxSomeTextHerexxx
</p>
</div>
</div>
</div>
My problem is that I use cards of different sizes and right now my image size is governing the size of my card; I guess I want it the other way round (the card to govern the size of the displayed background). So I wondered if it was possible to tile a background image so it just fills the background and then it shouldn't matter what size the card or image is.
For all I know, this may not even be possible and if not, that's fine, I'll look for another way to do something like :)
Anyway, thanks for any advice :)
James

If the only purpose of using img element is as a background - use background-image CSS property which sets background image on an element.
Edit per comments:
Obviously the float part cause some "problems" on the given markup, BUT there is something more out there... Can't figure myself why this not working - so i remove BS4 (added 2 examples):
.card.img-fluid {
background: url(http://www.rocksquad.co.uk/images/backcard-brushedmetal.jpg) no-repeat;
background-position: center;
background-size: cover;
}
<div class="card img-fluid">
<div class="card-img-overlay">
<div class="card-body text-justify">
<h3 class="articleh3">xxxDescriptionxxx</h3>
<p>
<img src="http://www.rocksquad.co.uk/images/backcard-brushedmetal.jpg" alt="xxxDescriptionxxx" height="100" width="80" style="margin-right: 10px;" />
xxxSomeTextHerexxx<br>xxxSomeTextHerexxx
</p>
</div>
</div>
</div>
<hr>
<div class="card img-fluid">
<div class="card-img-overlay">
<div class="card-body text-justify">
<h3 class="articleh3">xxxDescriptionxxx</h3>
<p>
<img src="http://www.rocksquad.co.uk/images/backcard-brushedmetal.jpg" alt="xxxDescriptionxxx" height="100" width="80" style="margin-right: 10px;" />
xxxSomeTextHerexxx<br>xxxSomeTextHerexxx<br> xxxSomeTextHerexxx<br>xxxSomeTextHerexxx<br> xxxSomeTextHerexxx<br>xxxSomeTextHerexxx<br> xxxSomeTextHerexxx<br>
</p>
</div>
</div>
</div>
This question need some "bootstrap 4 expert" to answer on - clearly this is not me (:
Old (not working) answer:
In your case, since you want the image would cover the element, you can do something like that:
<style>
.card.img-fluid {
background: url(images/backcard-brushedmetal.jpg) no-repeat;
background-position: center;
background-size: cover;
}
</style>
<div class="card img-fluid">
<div class="card-img-overlay">
<div class="card-body text-justify">
<h3 class="articleh3">xxxDescriptionxxx</h3>
<p>
<img src="images/xxxImagexxx.jpg" alt="xxxDescriptionxxx" height="100" width="80" style="margin-right: 10px;float: left" />
xxxSomeTextHerexxx
</p>
</div>
</div>
</div>

Related

How to stop bootstrap resizing top card image too large whilst keeping consistent with differing image files?

Hi I am having some trouble with bootstrap image sizing.
If I pass in a images with smaller dimensions it is "blowing them up" to fit the card and they can become blurry.
Here is the html in question:
{% for item in book_list %}
The Arsonist
Lorem Ipsum...
More Info
{% endfor %}
~~~
Now what is happening is when I render this I end up with this:
And whilst it might be difficult to tell from the screenshots the card-img-top are much larger than the source image this is not what I want for two reasons:
I would like the cards to be smaller, making them smaller and adding some white space either side would work fine.
It is resizing the images too large and this can make the images look blurry, especially when the resolutions are small to begin with and then they are blown up.
Can anyone tell me how I can make the cards images smaller whilst still staying the same size as the other cards images (which will have similar but not identical resolutions)?
I am looking for something like this (image on top is what I currently have and the black box is my fullscreen). It doesn't have to be 5 cards in a row or the margins don't need to be that big it is to just give an idea of what I roughly want.
It shouldn't matter what the dimensions of the original image is it should display like that, so for example if I put in a 2000x3000 image it shouldn't take up more space on the screen than a 200x300.
What I have tried so far:
I have tried adding the custom CSS and playing around with the height
.card-img-top {
width: 100%;
height: 15vw;
object-fit: cover;
}
as well as trying the style attribute style="width: 100%;" which I figured might take the original image width as the width in the card and the height would follow, however in both cases it is still getting blown up. But nothing is working for me.
So to summarise my question again:
How can I stop my card top images "blowing up" regardless of the dimensions of the image?
I am new to this kind of thing and new to this site so let me know please if I need to do more!
Thank you.
The only thing that worked from me was changing class from "card-img-top" to "card-img"...
<img src="pic.jpg" class="card-img" style="width: 200px;">
This will do:
<div class="container-fluid">
<div class="row mb-5">
<div class="col py-1 d-flex align-items-stretch">
<div class="card m-3">
<img src="https://www.booktopia.com.au/blog/wp-content/uploads/2018/12/the-arsonist.jpg" class="card-img-top" style="width: 100%;" alt="image">
<div class="card-body">
<h5 class="card-title">The Arsonist</h5>
<p class="card-text">Lorem Ipsum...</p>
More Info
</div>
</div>
<div class="card m-3">
<img src="https://www.booktopia.com.au/blog/wp-content/uploads/2018/12/the-arsonist.jpg" class="card-img-top" style="width: 100%;" alt="image">
<div class="card-body">
<h5 class="card-title">The Arsonist</h5>
<p class="card-text">Lorem Ipsum...</p>
More Info
</div>
</div>
<div class="card m-3">
<img src="https://www.booktopia.com.au/blog/wp-content/uploads/2018/12/the-arsonist.jpg" class="card-img-top" style="width: 100%;" alt="image">
<div class="card-body">
<h5 class="card-title">The Arsonist</h5>
<p class="card-text">Lorem Ipsum...</p>
More Info
</div>
</div>
<div class="card m-3">
<img src="https://www.booktopia.com.au/blog/wp-content/uploads/2018/12/the-arsonist.jpg" class="card-img-top" style="width: 100%;" alt="image">
<div class="card-body">
<h5 class="card-title">The Arsonist</h5>
<p class="card-text">Lorem Ipsum...</p>
More Info
</div>
</div>
<div class="card m-3">
<img src="https://www.booktopia.com.au/blog/wp-content/uploads/2018/12/the-arsonist.jpg" class="card-img-top" style="width: 100%;" alt="image">
<div class="card-body">
<h5 class="card-title">The Arsonist</h5>
<p class="card-text">Lorem Ipsum...</p>
More Info
</div>
</div>
</div>
</div>
</div>
see:https://jsfiddle.net/sugandhnikhil/rx4p8zgc/1/

how to fit both text and image in a row using 2 col-md-6

<style>
.backgroundcolor1 {
background-color: #567892;
}
</style>
<section>
<div class="row" align="center">
<div class="col-md-12 backgroundcolor1">
<div class="col-md-6 col-sm-6">
<div class="col-md-10 col-lg-offset-1 ">
<br>
<img src="assets/images/SPA/Icons/facials.png" class="icons" alt=""><br>
<h3>FACIALS</h3>
<p align="justify">Have you ever treated to a facial?<br> Facial treatments feel good, offering soothing relaxation, according to Day Spas. Facial massage treatments increase circulation and the flow of blood, and they include a variety of cremes,
aromatherapy and oils that moisturize the skin, smell good, and relieve stress as well as encourage peace of mind and contentment</p>
</div>
</div>
<div class="col-md-6 col-sm-6 textbox">
<img src="assets/images/SPA/facial.jpg" style="height: 100%; width: 100%; object-fit: contain;opacity:0.9;padding:0;margin:0; " alt="">
<figcaption><br><br><br>
<h3>Facials</h3>
</figcaption>
[enter image description here][1]
</div>
</div>
</div>
</section>
I am getting proper image fitting to text.. after i start resizing my image start reducing and there will be gap like the below image. i don't want it to happen for all the devices. my entire site is in this manner only. i don't want that extra background showing at the right side of the image.can anybody help me to solve this problem.
you can create row inside col-md-6 and define column that you want like
<div class="col-md-6 col-sm-6 textbox">
<div class="row">
<div class="col-md-7 col-sm-6">
<img src="">
</div>
<div class="col-md-5 col-sm-6">
<p>Text goes here.....</p>
<p>ddescription goes here</p>
</div>
</div>
</div>
you can print text first and image in second and change col length with your need. I hope this is what you need if not please try to clarify your question.
Please check this
.backgroundcolor1 {
background-color: #567892;
}
.back_imag{position:absolute !important; background:url(http://via.placeholder.com/500x400) no-repeat; background-size:cover; background-position:center center; left:0px; top:0px; bottom:0px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"/>
<section class="container">
<div class="row" align="center">
<div class="col-xs-12 backgroundcolor1">
<div class="col-xs-6 col-sm-6">
<div class="col-md-10 col-lg-offset-1 ">
<br>
<img src="assets/images/SPA/Icons/facials.png" class="icons" alt=""><br>
<h3>FACIALS</h3>
<p align="justify">Have you ever treated to a facial?<br> Facial treatments feel good, offering soothing relaxation, according to Day Spas. Facial massage treatments increase circulation and the flow of blood, and they include a variety of cremes,
aromatherapy and oils that moisturize the skin, smell good, and relieve stress as well as encourage peace of mind and contentment</p>
</div>
</div>
<div class="col-xs-6 col-sm-6 textbox back_imag col-xs-offset-6">
<img src="" class="" alt="">
<figcaption><br><br><br>
<h3>Facials</h3>
</figcaption>
[enter image description here][1]
</div>
</div>
</div>
</section>

How to make links work with card-img-overlay in Bootstrap v4

I'm having an issue where any Bootstrap v4 cards using the card-img-overlay to display text over an image prevents links below that image from working.
These links do work:
<div class="card" style="border-color: #333;">
<img class="card-img-top" src="..." alt="Title image"/>
<div class="card-inverse">
<h1 class="text-stroke">Title</h1>
</div>
<div class="card-block">
Card link
<p class="card-text">Article Text</p>
</div>
<div class="card-footer">
<small class="text-muted">Date - Author</small>
</div>
</div>
These links do NOT work:
<div class="card" style="border-color: #333;">
<img class="card-img-top" src="..." alt="Title image"/>
<div class="card-img-overlay card-inverse">
<h1 class="text-stroke">Title</h1>
</div>
<div class="card-block">
Card link
<p class="card-text">Article Text</p>
</div>
<div class="card-footer">
<small class="text-muted">Date - Author</small>
</div>
</div>
I see there is an open issue regarding this for bootstrap v4, but can anyone help with a workaround that would preserve the same look?
The overlay is position: absolute which gives that element a z-index, and the rest of the content in the card is statically positioned, so none of it has a z-index. You can give the link a z-index by adding a non-static position, and since your card link comes after the overlay in the HTML, the stacking order will put the card link's stacking order on top of the overlay.
.card-link {
position: relative;
}
As mentioned by Michael Coker, adding the below to your css resolves this issue.
.card-link {
position: relative;
}

Text overflowing from Bootstrap 4 row

EDIT: As requested here is the jsfiddle
When the screen gets too small for the text to fit in the row, it just overlaps other rows, rather than extending the row height. Perhaps this is because I set row heights on every row as a percentage value, in order to lay out my html page with even spacing and vertical alignment. How do I correct this overlapping of text onto other rows? Should I be looking into somehow vertically aligning my rows without setting their height? Or can I keep it the way it is and add some kind of overflow property to each row to tell them to extend their height when necessary?
All relevant images and code:
screenshot of fullscreen (good - no problems yet)
screenshot of hovering over the middle row element on smaller screens (problems)
screenshot of hovering over the bottom row of smaller screens:
all my html for the page:
<div id="landing-page" class="text-uppercase">
<div class="row hidden-lg-up" style="height:20%;overflow-y:auto;">
<div class="col-xs-3 flex-xs-middle">
<img width="100" src="images/monster2.png" />
</div>
<div class="col-xs-3 offset-xs-6 flex-xs-middle">
<img class="pull-xs-right" width="100" src="images/monster4.png" />
</div>
</div>
<div class="row" style="height:95%;overflow-y:auto;">
<div class="col-xs-1 col-sm-2 col-md-3 hidden-md-down flex-xs-top flex-sm-middle">
<img width="80%" src="images/monster2.png" />
</div>
<div class="col-md-12 col-lg-6 flex-xs-middle ">
<div id="motto-text" style="text-align: center;">
<h5 class="text-muted display-6">the vegan repository</h5>
<h1 class="display-3">
find vegan stuff* near you.
</h1>
<a id="try-now-button" class="with-border clickable" href="#search-filter-page">
<h5 class="text-center medium-text">try now</h5>
</a>
</div>
</div>
<div class="col-xs-1 col-sm-2 col-md-3 hidden-md-down flex-xs-top flex-sm-middle">
<img class="pull-xs-right" width="80%" src="images/monster4.png" />
</div>
</div>
<div class="row" style="height:5%;overflow-y:auto;">
<h4 class="display-6 flex-xs-bottom">
*Stuff like restaurants, meat alternatives, dairy alternatives, and much more!
</h4>
</div>
</div>
all my css for the page:
div#landing-page {
background-color: #696969;
height: 100%;
padding: 110px 40px 0px 40px;
overflow-y: auto;
min-height:470px;
}
EDIT: As requested here is the jsfiddle
Alright. Now the question is clear. The problem was easy to fix.
The problem is in the following div. You have specified it to have col-md-12 but you didn't force it when the screen is xs
<div class="col-md-12 col-lg-6 flex-xs-middle ">
<div id="motto-text" style="text-align: center;">
<h5 class="text-muted display-6">the vegan repository</h5>
<h1 class="display-3">
find vegan stuff* near you.
</h1>
<a id="try-now-button" class="with-border clickable" href="#search-filter-page">
<h5 class="text-center medium-text">try now</h5>
</a>
</div>
</div>
so the simplest thing is to add col-xs-12 class to prevent overlapping
See example

HTML/CSS making 3 images in line responsive and well designed

Im trying to make these images to be displayed nicely inline and change its position/size depending on the screen size. This is my HTML code:
<div class="row tryRow white">
<div class="col-xs-4 portfolio-item leftPic">
<div class="imgWrap">
<img class="img-responsive" src="~/img/FMA.png" />
<p class="imgDescription">
Some text in here </p>
</div>
</div>
<div class="col-xs-4 portfolio-item centerPic">
<div class="imgWrap">
<img class="img-responsive" src="~/img/SFK.png" />
<p class="imgDescription">
Some text in here
</p>
</div>
</div>
<div class="col-xs-4 portfolio-item rightPic">
<div class="imgWrap">
<img class="img-responsive" src="~/img/CTG.png" />
<p class="imgDescription">
Some text in here </p>
</div>
</div>
</div>
These images display some text below them when they are hovered on.
This is CSS of one of the images:
.leftPic {
opacity:0.5;
border-radius:4px;
max-width: 33%;
width:auto;
}
As you can see I am trying to set the max width to 33% as I have 3 images per line, but the margins are not correct and to be honest there is a large problem with this.
Problem: To make them shrink, re-position depending on the browser while keeping the relatively sharp look.
i tried with this one:
.tryRow{ display: inline-block;}
Hmmm... I would approach it in a different way setting background-image instead of using html <img>. As you expect nice responsive behavior and your images are quite small have a look at this:
<div class="row">
<div class="col-md-4">
<div class="image image-1">Some text</div>
</div>
<div class="col-md-4">
<div class="image image-2">Some text</div>
</div>
<div class="col-md-4">
<div class="image image-3">Some text</div>
</div>
</div>
.image {
background-position: center center;
background-repeat: no-repeat;
-webkit-background-size: cover;
background-size: cover;
// height: control it with media queries
}
.image-1 {
background-image: url(path/to/image-1.jpg);
}
.image-2 {
background-image: url(path/to/image-2.jpg);
}
.image-3 {
background-image: url(path/to/image-3.jpg);
}
This approach will also give you more flexibility styling those boxes content.