Images exceeding size - html

I want to display images in my div. I display different images according to the condition (if moviePoster true).
I moviePoster I display it, but if it is false, I display a image that informed that the file is not found.
I don't know why but when I display these 2 types of image, the moviePoster image, exceeding the size of the dive.
This is a screen from the issue in my application
.list {
border: 1px solid grey;
display: flex;
margin: 30px;
height: 230px;
border-radius: 10px;
box-shadow: 1px 1px 12px #555;
}
.list-img {
// border: 5px solid red;
width: 20%;
}
img {
height: 100%;
width: 100%;
border-top-left-radius: 10px;
border-bottom-left-radius: 10px;
}
<div class="list">
<div class="list-img">
<div *ngIf="moviePoster; else notFound">
<img src="https://image.tmdb.org/t/p/w200/{{moviePoster}}" alt="...">
</div>
<ng-template #notFound>
<img src="../../assets/not_found.jpg" alt="...">
</ng-template>
</div>

img is a default display: inline, so height and width refers to inner content.
Anyway set image width and height usually stretches image, and that's orrible.
I suggest on using a div with the image setted as background, so use something like that:
html:
...
<div
*ngif="..."
class="thumbnail"
style="background-image: url(https://...{{ moviePoster }})"
></div>
...
css:
.thumbnail{
background-size: cover;
background-position: center;
}
You should apply this class also to #notFound.
One thing missing: thumbnail div must have height and width expressed
You can do that in multiple ways via css, depending on how have you structured the card box.
Hope it helps.

i think this is what you want :
if the image is null then the default background will show.
UPDATE: i have made it more dynamic
.list {
display: flex;
flex-direction: column;
}
.list-item {
height: 150px;
overflow: hidden;
border-radius: 10px;
box-shadow: 0 0 3px 2px rgba(0,0,0,.5);
}
.list-item + .list-item {
margin-top: 10px;
}
.list-img {
width: 200px;
height: 150px;
transition: background .5s ease;
background-size: cover;
background-repeat: no-repeat;
background-position: center center;
background-image: url(https://www.tourismselangor.my/wp-content/themes/Directory/images/noimage.jpg);
}
<div class="list">
<div class="list-item">
<div class="list-img" style="background-image: url(https://picsum.photos/200)"></div>
</div>
<div class="list-item">
<div class="list-img"></div>
</div>
<div class="list-item">
<div class="list-img" style="background-image: url(https://picsum.photos/200)"></div>
</div>
</div>

Related

image background opacity with no affecting borders

How to set background with opacity without affecting border line opacity? Solutions I found does not help.
<div class="selected">
<img
src="../assets/img/image-product-1-thumbnail.jpg"
alt="product-1-thumbnail"
/>
</div>
img {
width: 100%;
max-width: 5rem;
height: auto;
border-radius: 10%;
}
.selected {
background-color: red;
img {
border: 2px solid red;
}
}
let thumbnailImages = document.querySelectorAll('.thumbnail');
thumbnailImages.forEach(image => {
image.addEventListener("mouseover", ()=> {
image.classList.add('blur')
image.parentElement.style.outline = "2px solid hsl(26, 100%, 55%)";
image.parentElement.style.borderRadius = "12px";
})
image.addEventListener("mouseout", ()=> {
image.classList.remove('blur')
image.parentElement.style.outline = "";
})
});
.left-section-bottom{
display: flex;
width: 80%;
margin: 32px auto;
gap: 40px;
}
.left-section-bottom img{
border-radius: 12px;
}
.thumbnail.blur{
opacity: 0.4;
cursor: pointer;
}
.thumbnail-div{
display: flex;
}
<div class="left-section-bottom">
<div class="thumbnail-div"><img class="thumbnail" src="images/image-product-1-thumbnail.jpg" alt=""></div>
<div class="thumbnail-div"><img class="thumbnail" src="images/image-product-1-thumbnail.jpg" alt=""></div>
<div class="thumbnail-div"><img class="thumbnail" src="images/image-product-1-thumbnail.jpg" alt=""></div>
<div class="thumbnail-div"><img class="thumbnail" src="images/image-product-1-thumbnail.jpg" alt=""></div>
</div>
I was looking for an answer to this same question, and finally figured it out. The original question is in regard to this challenge:
https://www.frontendmentor.io/challenges/ecommerce-product-page-UPsZ9MJp6
Since there are 4 images you have to loop through them one by one.
You have to use querySelectorAll, not querySelector.
Just loop through your thumbnail images with a forEach().
Wrap your images in a div (as Kingsly mentioned) so you can apply
border style to the div instead of your blurred images.
This code should work if you add your images.
You should put the image in a div container with the size you want. Add the border and border-radius to the div, add opacity to the img element.
IMAGE CREDIT: https://www.pexels.com/#belle-co-99483
.img-container {
width: 200px;
height: 150px;
border: 2px solid red;
border-radius: 10%;
overflow: hidden;
}
img {
width: 100%;
height: 100%;
opacity: .7;
}
.selected {
//background-color: red;
}
img {
}
<div class="selected">
<div class="img-container">
<img
src="https://images.pexels.com/photos/1000445/pexels-photo-1000445.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940"
alt="product-1-thumbnail"
/>
</div>
</div>

How to remove the background image border when on hover?

I have a card with an image header. When on hover of the card, I'd like to change the non-image part background color. Code as follows:
.card {
box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);
transition: 0.3s;
width: 40%;
height: 500px;
}
.card-image {
display: block;
position: relative;
}
.card:hover {
background-color: grey;
}
img {
display: block;
width: 100%;
height: 200px;
background-size: cover;
}
.container {
padding: 0 16px;
}
<div class="card">
<div class="card-image">
<img style="background-image: url(https://www.w3schools.com/howto/img_avatar.png);">
</div>
<div class="container">
<h4><b>John Doe</b></h4>
<p>Architect & Engineer</p>
</div>
</div>
I use a background image as the image here because I need the background-size: cover effect, but as hovering on the card, you can see a border being added to the image due to it's actually a background image, I wonder how I can get rid of the border?
EDIT: the border isn't that obvious:
You are using background-image attribute, you should use the style on a <div> tag instead (or any other tag you with display:block), since this is an a background image not an image, I think this is caused by default browser behavior for not providing src attribute, which would be considered as 404 error for the image, not sure if this is the case here, here is a working snippet:
.card {
box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);
transition: 0.3s;
width: 40%;
height: 500px;
}
.card-image {
display: block;
position: relative;
}
.card:hover {
background-color: grey;
}
.img {
display: block;
width: 100%;
height: 200px;
background-size: cover;
background-image: url(https://www.w3schools.com/howto/img_avatar.png);
}
.container {
padding: 0 16px;
}
<div class="card">
<div class="card-image">
<div class="img"></div>
</div>
<div class="container">
<h4><b>John Doe</b></h4>
<p>Architect & Engineer</p>
</div>
</div>
The problem is that you're using the img HTML element with a background-image CSS declaration. Two possible solutions:
1) Keep the img element, add a src attribute, and use the object-fit declaration.
HTML:
<div class="card-image">
<img src="https://www.w3schools.com/howto/img_avatar.png">
</div>
CSS:
img {
display: block;
width: 100%;
height: 200px;
object-fit: cover;
}
2) Remove the img element (and declaration) and apply the background-image declaration to the .card-image element.
HTML:
<div class="card-image"></div>
CSS:
.card-image {
background-image: url("https://www.w3schools.com/howto/img_avatar.png");
background-size: cover;
height: 200px;
}

Make an image come out of a div with background-image

I need some help, I need to code this image:
This is what I have so far:
I tried adding a margin-top, padding-top, tried all combinations of position relative and absolute, I just need some ideias on how to do it.
This is how my code is structured:
<div class="background-oficina">
<div class="container">
<div class="col-xs-12 text-center">
<img class="logo" src="logo.png" alt="Oficina de Redação">
</div>
</div>
</div>
This is the css for the two classes that I'm using:
.background-oficina {
background: #fff url("bg-texture.png");
}
.logo {
padding-top: 50px;
margin: 0 auto;
}
You could use an additional absolutely positioned element to which you assign the repeated background pattern and which you put behind the original element by using z-index: -1:
html, body {
margin: 0;
}
.background-oficina {
position: relative;
border: 1px solid #333;
border-bottom: none;
}
.bg-container {
position: absolute;
z-index: -1;
left: 0;
top;
width: 100%;
height: 120px; /* or whatever height is desired */
background: url("http://placehold.it/20x15/cff");
}
.text-center {
text-align: center;
}
.logo {
padding-top: 50px;
margin: 0 auto;
}
<div class="background-oficina">
<div class="bg-container"></div>
<div class="container">
<div class="col-xs-12 text-center">
<img class="logo" src="http://placehold.it/200x150/fb7" alt="Oficina de Redação">
</div>
</div>
</div>
Your trying this, you can set default height and width to parent div that consist of that logo then using position:absolute you can push that out of parent div, but don't add overflow:hidden to parent div or else it hides your image or element that you are trying to push outside parent div as hidden.
.background-oficina {
background: #fff url("https://via.placeholder.com/800x100/000") no-repeat;
box-shadow: inset 0 0 0 1000px rgba(255, 255, 255, 0.2);
background-size: 100% 100%;
width: 100%;
height: 100px;
position: relative; /*Add this*/
}
.logo {
padding-top: 50px;
margin: 0px auto;
position: absolute; /*Add this*/
bottom: -20px; /*Add this*/
}
<div class="background-oficina padding margin-bottom">
<div class="container">
<div class="col-xs-12 text-center margin-bottom">
<img class="logo" src="https://via.placeholder.com/50/ff2" alt="Oficina de Redação">
</div>
</div>
</div>

Can I position an element at the bottom right corner of a flexible image with pure CSS?

The overlay image in the example below is supposed to stay at the same location relative to the larger image independent of the size of the container.
I added 2 examples below of the "img_overlay" CSS module, one where it is inside a portrait test container (green), and another inside a green landscape container. It works fine for portrait, but not for landscape, because the "img_overlay__container" (red) extends to the whole width of the parent container instead of being limited to the width of the black image. If the red container would be as wide as the black image then everything would be OK.
I can make it work for landscape too with a simple inline-block, but then it breaks for portrait.
Mind that the image should be flexible, expanding and shrinking according to the available space, up to its natural size, so no fixed size solutions please. And the overlay image should retain its size ratio in relation to the black image (25% of the black image), so that it looks the same independent of screen size.
I should add that I am testing on Chrome Version 59.0.3071.115 (Official Build)
(64-bit)
Am I missing something or is it simply not possible with current CSS3?
Edit (14/07/2017): I made the containers resizable so its easier to test.
https://jsfiddle.net/rvmxpwq1/3/
$( ".test" ).resizable();
body {
margin-bottom: 100vh;
}
.img_overlay {
display: inline-flex;
max-height: 100%;
}
.img_overlay__container {
position: relative;
background-color: rgb(255, 0, 0);
}
.img_overlay__img {
border-radius: 50%;
max-height: 100%;
max-width: 100%;
}
.img_overlay__overlay {
border-radius: 50%;
max-width: 25%;
max-height: 25%;
position: absolute;
right: 0px;
bottom: 0px;
}
.test {
display: flex;
align-items: center;
justify-content: center;
background-color: rgb(0, 255, 0);
border: 3px solid rgb(0, 255, 0);
}
.test--1 {
width: 200px;
height: 300px;
}
.test--2 {
width: 300px;
height: 200px;
}
.test--3 {
width: 500px;
height: 500px;
}
<link href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
Portrait container (300x200): <strong>works</strong>, this is how it should always look at any container size.
<div class="test test--1">
<div class="img_overlay">
<div class="img_overlay__container">
<img class="img_overlay__img" src="https://dummyimage.com/400x400/000/ffffff.jpg&text=Image">
<img class="img_overlay__overlay" src="https://dummyimage.com/100x100/0000ff/ffffff.jpg&text=Overlay">
</div>
</div>
</div>
<br> Landscape container (200x300): <strong>does not work</strong>, because the overlay is not next to the image.
<div class="test test--2">
<div class="img_overlay">
<div class="img_overlay__container">
<img class="img_overlay__img" src="https://dummyimage.com/400x400/000/ffffff.jpg&text=Image">
<img class="img_overlay__overlay" src="https://dummyimage.com/100x100/0000ff/ffffff.jpg&text=Overlay">
</div>
</div>
</div>
<br> Large container (500x500): <strong>works</strong>, the images are not enlarged above their natural size.
<div class="test test--3">
<div class="img_overlay">
<div class="img_overlay__container">
<img class="img_overlay__img" src="https://dummyimage.com/400x400/000/ffffff.jpg&text=Image">
<img class="img_overlay__overlay" src="https://dummyimage.com/100x100/0000ff/ffffff.jpg&text=Overlay">
</div>
</div>
</div>
How about now?
here is a fiddle:
https://jsfiddle.net/f9e2gkpk/5/
.wrapper{
max-height: 100%;
max-width: 100%;
}
.img_overlay {
display: inline-flex;
max-height: 100%;
}
.img_overlay__container {
position: relative;
background-color: rgb(255, 0, 0)
}
.img_overlay__img {
border-radius: 50%;
max-height: 100vh;
max-width: 100%;
}
.img_overlay__overlay {
border-radius: 50%;
width: 25%;
position: absolute;
right: 0px;
bottom: 0px;
}
.test {
display: flex;
align-items: center;
justify-content: center;
background-color: rgb(0, 255, 0);
border: 3px solid rgb(0, 255, 0);
height: 100vh;
}
<div class="test test--2">
<div class="img_overlay">
<div class="img_overlay__container">
<div class="wrapper">
<img class="img_overlay__img" src="https://dummyimage.com/400x400/000/ffffff.jpg&text=Image">
<img class="img_overlay__overlay" src="https://dummyimage.com/100x100/0000ff/ffffff.jpg&text=Overlay">
</div>
</div>
</div>
</div>

Force empty div with background image to cover height of container div

I have a row with two columns. I would like the column containing the .product-image empty div with background image (on the right) to have the same height as the column containing the .product-text div with text (on the left). The background image should cover the entire area of the right column.
I've created a codepen here: http://codepen.io/anon/pen/VemgQb
HTML:
<div class="container-fluid subpage-product">
<div class="row">
<div class="col-lg-6 col-md-6 col-xs-12 product-text">
<div class="product-icon">
<img src="https://s-media-cache-ak0.pinimg.com/736x/5a/dc/89/5adc89f4a0752dfec5c2f9ba625bfac5.jpg">
</div>
<h2>Meow Meow Meow</h2>
<p>Pelt around the house and up and down stairs chasing phantoms shove bum in owner's face like camera lens stare at ceiling.</p>
</div>
<div class="col-lg-6 col-md-6 col-xs-12 no-padding product-img" id="horse-racing-bg-img-01">
</div>
</div>
CSS (LESS):
#horse-racing-bg-img-01 {
background: url(http://i.imgur.com/C9xULnI.jpg) no-repeat;
background-size: cover;
}
.subpage-product .row {
overflow: hidden;
.product-text {
padding: 70px 100px;
text-align:center;
background-color: #000;
color: #fff;
}
.product-img {
height: 100%;
}
.product-icon {
height: 80px;
width: 80px;
display: block;
margin: 0 auto 0;
border-radius: 50%;
border: 1px solid white;
background-color: #fff;
img {
height: 50px;
width: 50px;
margin: 15px 15px 0 13px;
}
}
}