html - 在 css 中使用 float 属性时,背景渐变被删除
问题描述
在 div 标签上使用 float 属性时,设置为背景的渐变被删除。最后一个 css 属性,即 div.image 中的 float 属性会移除背景。
这是HTML代码
<div class="content">
<div class="info">
<h2>Enter details</h2>
<h3>Username</h3>
<input type="text" name="username">
<h3>Password</h3>
<input type="text" name="password">
</div>
<div class="image"><img class="image" src="C:\Users\Desktop\New folder\Picture\light-trails-8.jpg"></div>
</div>
这是css代码
div.content{
background: linear-gradient(to right,#0080ff 50% , lightblue);
margin:0px;
padding:0px;
margin-top: 3px;
}
img.image{
width:250px;
height: 250px;
}
div.info{
float:left;
}
/***** After applying this style ****/
div.image{
float:right;
}
这是设计网页的截图
解决方案
里面的孩子div.content
是漂浮的。添加这个来修复:
div.content {
background: linear-gradient(to right,#0080ff 50% , lightblue);
margin:0px;
padding:0px;
margin-top: 3px;
/* Add this */
overflow:hidden;
width: 100%;
}
推荐阅读
- string - Jython 或 python 2.7 比传统字符串连接更好的字符串连接方法
- java - Windows 和 Linux 中不同的日期时间格式
- reactjs - ReactJS:通过 3 个组件传递数据
- c# - 在另一个线程中创建 WPF 命令
- r - 如何将线型添加到具有多条不同颜色的线并集中在一个键上的图形中?
- direct-line-botframework - 如何处理 DIRECT_LINE/POST_ACTIVITY_REJECTED
- composer-php - Symfony 5 应用程序中 EasyAdmin 的安装错误
- junit5 - Serenity 与 Junit 5 兼容吗?
- javascript - 数组中的循环返回错误的数组数
- node.js - 如何在 MongoDB Aggregate 中查找内部查找?