0

I am having some trouble with the code below. What is supposed to happen is the image rests neatly inside the card with some padding around the edges. Instead, it flows out of the parent div.

Code:

<div class="card greeting">
    <h3>Good Morning, admin</h3>
    <p class = "greeting-text">Mornings are the start of new ideas.</p>
    <img src = "<?php echo ASSETS_PATH . 'images/park.png' ?>">
</div>
.card {
  border-radius: var(--border-radius);
  background-color: var(--page-background-color);
  box-shadow: var(--box-shadow);
  cursor: pointer;
  padding: 8px;
  margin: 13px 0;
  border: 2px solid transparent;
  transition: .3s;
  color: var(--font-color);
  object-fit: contain;
}

.greeting{
  background-repeat: no-repeat;
  background-position: right;
  background-size: 55px;
  padding:10px;
}

.greeting img{
  background-repeat: no-repeat;
  background-position: right;
  background-size: 55px;
  padding:10px;
}

.greeting .greeting-text{
    word-wrap: break-word;
    overflow:hidden;
}

What would be a simple solution for this? My goal is to have the image neatly inside the card.

I have tried object-fit:contain and other solutions but either I didn't do them correctly, or something else is wrong.

Dharman
  • 30,962
  • 25
  • 85
  • 135
PhoenixCMS
  • 11
  • 5

2 Answers2

0

Don't think too much, you are not giving image as a background image, so need to use background properties

.greeting img {
  max-width: 100%;
  height: auto;
}
Dharman
  • 30,962
  • 25
  • 85
  • 135
Manikanta Reddy
  • 849
  • 9
  • 23
0

I faced a similar situation. One of the effective method is to use

<div class="container"> 

this helped me out. https://www.w3schools.com/w3css/w3css_containers.asp Check out this article.

Dharman
  • 30,962
  • 25
  • 85
  • 135