-3

I'm trying to make an HTML card following this, but I want the layout to be as the following image:

enter image description here

I still want the card effects (shadow border, hovering), and I'd like it to always keep the images at the same width.

This is my code:

<style>
.card {
  /* Add shadows to create the "card" effect */
  box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);
  transition: 0.3s;
  padding: 2px 16px;
}

/* On mouse-over, add a deeper shadow */
.card:hover {
  box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2);
}

/* Add some padding inside the card container */
.container {
  padding: 4px 4px;
}
</style>


<div class="card">
  <h1> TITLE </h1>
  <img src="img_avatar.png" alt="Avatar" style="float:left;width:45%">
  <div class="container" style="float:right;width:45%">
    <h4><b>John Doe</b></h4>
    <p>Architect & Engineer</p>
  </div>
</div>

But the result is not great: the image goes outside the card (you can see it here). How can I fix it?

Thank you very much!

Federico Taschin
  • 2,027
  • 3
  • 15
  • 28
  • Please show a working example of your code – Sfili_81 Jul 20 '20 at 09:18
  • I attempted to code it for quite a long time, but since every modification I tried was breaking the card I didn't put the code. However, the reference I linked already contained a working example of the code, which I believe needs little modifications to behave as I would like to, I just cannot make it work. In any case, I now added the code of my best attempt – Federico Taschin Jul 20 '20 at 09:35

1 Answers1

2

I hope it will be helpful...

<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.card {
  box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);
  transition: 0.3s;
  width: 40%;
}
p{
    margin-left:  3em;
    padding-top: 1em;
    margin-top: 1em;
}
.part2{
    display: grid;
    grid-template-columns: 1fr 1fr;
    margin: 1em;
    padding: 1em;
}
h4{
    margin: 1em;
}

.card:hover {
  box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2);
}
b {
  padding: 2px 16px;
}
</style>
</head>
<body>
<div class="card">
    <p>Architect & Engineer</p> 
    <div class="part2"><img src="1.jpg" alt="Avatar" style="width:100%">
  
    <h4>John Doe</h4> 
    </div>
</div>

</body>
</html> 

I changed some stuff in both HTML/CSS, so I will answer any question, good luck!

Latecoder
  • 79
  • 5