html - 在 div 中移动 2 个元素
问题描述
h1
div中有一个可点击的图像,称为#search-bar
(不幸的是,我不知道在哪里添加相关图像.. 道歉)我想像我一样将它们分开。我想知道是否有任何更简单和更简洁的解决方案来缩短 CSS 代码。谢谢。
#search-bar {
background: #C75000;
margin: 20px 90px 20px 75px;
padding: 1rem;
color:white;
}
#search-bar a, h1{
display:inline-block;
/* transform: translateX(50%); */
border: 5px solid black;
position: relative;
left: 200px;
}
#search-bar h1{
left:50px;
}
#search-bar a{
left:400px;
}
<div id="search-bar">
<h1>Can I use?</h1>
<a href="https://www.amazon.com/">
<img alt="cog" src="cog-trans.png" width="30" height="30">
</a>
</div>
解决方案
使用 flexbox 设置样式(示例)
#search-bar {
display: flex;
justify-content: space-around;
align-items: center;
background: #c75000;
margin: 20px 90px 20px 75px;
padding: 1rem;
color: white;
}
推荐阅读
- python - 用于在一系列数字上检查勒让德猜想的 Python 代码
- arrays - 如何生成包含在numpy数组中的随机字符串对
- twitter4j - Twitter4J 搜索 API 是否支持 Twitter Premium 或 Enterprise API 搜索端点
- html - 拖放后如何使用可拖动和可调整大小?
- javascript - Bootstrap datetimepicker 中的周视图
- javascript - vue.js 重定向到另一个页面(与原始页面相同的代码)然后数据库访问 404 错误
- python - 如何将 RSTP 与 OpenCV 连接?
- python - 如何使用python检测数组对
- android - Chrome 自定义选项卡中是否有任何等效的 webViewClient
- reactjs - 不会崩溃但会导致 300% CPU 的无限循环