【问题标题】:HTML card with title, image on left and text on the right带有标题、左侧图像和右侧文本的 HTML 卡
【发布时间】:2020-11-09 12:25:30
【问题描述】:

我正在尝试在this 之后制作 HTML 卡,但我希望布局如下图所示:

我仍然想要卡片效果(阴影边框、悬停),并且我希望它始终保持图像的宽度相同。

这是我的代码:

<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>

但结果不是很好:图像超出了卡片(您可以看到它here)。我该如何解决?

非常感谢!

【问题讨论】:

  • 请展示您的代码的工作示例
  • 希望您至少尝试自己编写代码。我建议你做一些additional research,无论是通过谷歌还是通过搜索,尝试一下。如果您仍然遇到问题,请返回您的代码并解释您尝试过的操作。
  • 我尝试了很长时间的代码,但是由于我尝试的每一次修改都破坏了卡片,所以我没有输入代码。但是,我链接的参考已经包含了一个代码的工作示例,我相信它需要很少的修改就可以按照我的意愿运行,我只是无法让它工作。无论如何,我现在添加了我最好的尝试的代码

标签: html css image card


【解决方案1】:

希望对你有帮助……

<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> 

我更改了 HTML/CSS 中的一些内容,所以我会回答任何问题,祝你好运!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-02-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-03
    • 1970-01-01
    • 2018-08-14
    • 2016-07-11
    相关资源
    最近更新 更多