html - 无法将图像放入 div 容器中
问题描述
我试图展示 div 容器内的图像,但无法在 div 标签内插入图像。
* {
margin:0;
padding:0;
background:#fff;
box-sizing:border-box;
}
body {
font-family: verdana;
}
section {
position:absolute;
top:50%;
left:50%;
transform:translate(-50%, -50%);
width:1200px;
height:400px;
background:#fff;
box-shadow: 0 10px 30px rgba(0,0,0,0.5);
display:flex;
}
.content {
width: 55%;
height:100%;
padding: 2% 3%;
text-align:justify;
line-height:1.5em;
font-size: 18px;
}
.image {
width:45%;
height:100%;
background:url('https://i.postimg.cc/2S7fjBxD/cyberpunk-mockup.jpg') ;
}
<section>
<div class="content">
<h1></h1>
</div>
<div class="image"></div>
</section>
我将附上下面的 codepen 链接以供输出参考:我希望图像适合 div 的右侧 (class="image")
解决方案
看看这个
* {
margin:0;
padding:0;
background:#fff;
box-sizing:border-box;
}
body {
font-family: verdana;
}
section {
position:absolute;
top:50%;
left:50%;
transform:translate(-50%, -50%);
width:1200px;
height:400px;
background:#fff;
box-shadow: 0 10px 30px rgba(0,0,0,0.5);
display:flex;
}
.content {
width: 55%;
height:100%;
padding: 2% 3%;
text-align:justify;
line-height:1.5em;
font-size: 18px;
}
.image {
width:45%;
height:100%;
background:url('https://i.postimg.cc/2S7fjBxD/cyberpunk-mockup.jpg') ;
background-size: cover;
background-repeat: no-repeat;
}
<section>
<div class="content">
<h1></h1>
</div>
<div class="image"></div>
</section>
我附上了 Codepen链接以查看示例。
推荐阅读
- mongodb - mongo facet group 3 输出结果
- html - 用于下划线的 Material UI CSS 动画
- actionscript-3 - 使用动作脚本 3 检测颜色
- python - ![远程拒绝] master -> master (pre-receive hook denied) 错误:未能将一些参考推送到“https://git.heroku.com/stark-dawn-54447.git”
- haskell - Haskell 检查嵌套数据
- android - 在Pagedlist Android中加载更多页面时需要回调
- python - 使用 pyomo 并行解决许多实例
- amazon-web-services - 通过站点到站点 VPN 从本地连接到 AWS s3
- python - 如何从 python 脚本中的单个 bibtex 输入字段获取可读的 unicode 字符串
- gist - 在 Medium 上使用 Github Gists 嵌入代码不起作用