html - div 和 image 向左浮动
问题描述
我尝试用图像旁边的“testtext”浮动 div,但它不起作用。
我想我犯了一个简单的错误,但我找不到原因:-)
<div class="module-boxs">
<div style="display:inline-flex;"">
<img class="float-left" src="logo.jpg">
</div>
<div style="display:inline-flex;">
<h4>Modulename</h4>
<h5>Web Dewloper</h5>
</div>
</div>
解决方案
您可以使用display: flex
但flex
在 IE10 等较旧的浏览器中不受支持。您必须编辑您的 HTML 结构,这样会更容易。这里有一个例子:
.module-name {
margin-bottom: 15px;
padding-top: 15px;
}
.module-name:after {
content: '';
display: table;
clear: both;
}
.module-name img.logo {
width: 25%;
float: left;
}
.module-name .text{
width: 75%;
float: left;
padding-left: 10px;
}
.module-name .text h4 {
display: block;
vertical-align: top;
margin: 0;
font-size: 20px;
}
.module-name .text h5 {
display: block;
vertical-align: top;
margin: 0;
font-size: 16px;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<div class="col-md-4 col-sm-4 col-xs-12 module-box">
<div class="module-boxs">
<div class="module-name">
<img class="logo" src="https://getbootstrap.com/docs/4.1/assets/brand/bootstrap-solid.svg">
<div class="text">
<h4>Modulename</h4>
<h5>Web Dewloper</h5>
</div>
</div>
<p>Lorem ipsum dolor sit amet, consectetur sed do eiusmod tempor incididunt.</p>
<button class="btn">text</button>
</div>
</div>
推荐阅读
- javascript - Reactjs 变量在 useEffect 之后返回未定义
- python - 如何显示图像并在 1.5 秒后将其杀死?
- vue.js - Vue 3:将 Options API 组件转换为 Composition API(将容器设置为元素 - this.$el vs ref?)
- blockchain - 为什么我的以太坊智能合约交易在 X 笔交易后没有显示?
- c++ - 这个递归案例有什么问题?
- vapor-fluent - 如何使用 Vapor 添加约束?
- python - Python 调度器说明
- git - 接受主分支名称和主分支名称的 git 别名?
- javascript - Javascript竞争条件多个承诺连接字符串
- c++ - 如何将编辑控件的内容与文件中的文本进行比较?