0

I have a div which has a background image property. The want the div to take at-least 240px width but should fit the screen if space is available. I want to maintain the ratio so i have set the height property to auto but still i get a cropped image in some cases. I am not an expert in css and any help would be appreciated. thanks.

<div class = "event">
  <div class="event-image"></div>
  <a href = "#learnmore" class = "learn-more">Corporate Event</a>
</div> 

.event {
  border: 1px solid grey;
  border-radius: 4px;
  min-width: 240px;
  min-height: 400px;
  width: 100%;
  height: auto;
}

.event-image {
  background: url('event.jpg');
  background-repeat: no-repeat;
  background-size: cover;
  min-width: 240px;
  min-height: 200px;
  width: 100%;
  height: auto;
  margin-bottom: 20px;
}

this image is displayed half in height

on mobile it should be like this too

lag
  • 520
  • 2
  • 10
  • 26

0 Answers0