javascript - 将两个 div 与右侧的图像居中对齐
问题描述
需要始终将箭头图像居中向右。目前文本居中,但当它是两行时,imagediv 不居中。
<div id="holding" style="margin:auto; position:relative; overflow: hidden; max-width: 666px; border-top: 1px solid #EBEBEB;">
<div class="job teamCleanString ' locationCleanString ' commitmentCleanString '">'
<div style="float:left;">
<a class="job-title" style="color:#FF4F5D;" href="' link '" ">' title '</a></div>'
<div id="imagediv " style=" right:5px;float:right;position:absolute; ">
<a href=" ' link ' ""><img border="0" alt="W3Schools" src="https://uploads-ssl.webflow.com/5b3b89dea339e60649183848/5b3bc02bedb57a5c5b6b9a38_small-grey-arrow.svg" width="25" height="25"></a>
</div>
</div>
<div style="clear:both; font-size:1px;"></div>
</div>
我尝试在 imagediv 上使用以下内容,但有时文本是两行而不是一行,因此会导致问题:
position:absolute;top:50%;
但它没有用。它应该看起来像这样,我认为解决方案很容易,但我很挣扎。请帮忙。
解决方案
我会在你的 CSS 中设置 display:flex 和 align-items:center ,如下所示:
job {
display: flex;
align-items:center;
}
<div id="holding" style="margin:auto; position:relative; overflow: hidden; max-width: 666px; border-top: 1px solid #EBEBEB;">
<div class="job teamCleanString locationCleanString commitmentCleanString ">
<div style="float:left;">
<a class="job-title" style="color:#FF4F5D;" href=' link '> title 1 </a></div>
<div id="imagediv " style=" right:5px;float:right;position:absolute; ">
<a href=" ' link ' "">
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18"><path d="M7.5 4.5L6.44 5.56 9.88 9l-3.44 3.44L7.5 13.5 12 9z"/></svg>
</a>
</div>
</div>
<div style="clear:both; font-size:1px;"></div>
</div>
<div id="holding" style="margin:auto; position:relative; overflow: hidden; max-width: 666px; border-top: 1px solid #EBEBEB;">
<div class="job teamCleanString locationCleanString commitmentCleanString ">
<div style="float:left;">
<a class="job-title" style="color:#FF4F5D;" href=' link '> title 2</br>with two lines </a></div>
<div id="imagediv " style=" right:5px;float:right;position:absolute; ">
<a href=" ' link ' "">
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18"><path d="M7.5 4.5L6.44 5.56 9.88 9l-3.44 3.44L7.5 13.5 12 9z"/></svg>
</a>
</div>
</div>
<div style="clear:both; font-size:1px;"></div>
</div>
<div id="holding" style="margin:auto; position:relative; overflow: hidden; max-width: 666px; border-top: 1px solid #EBEBEB;">
<div class="job teamCleanString locationCleanString commitmentCleanString ">
<div style="float:left;">
<a class="job-title" style="color:#FF4F5D;" href=' link '> title 3 </a></div>
<div id="imagediv " style=" right:5px;float:right;position:absolute; ">
<a href=" ' link ' "">
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18"><path d="M7.5 4.5L6.44 5.56 9.88 9l-3.44 3.44L7.5 13.5 12 9z"/></svg>
</a>
</div>
</div>
<div style="clear:both; font-size:1px;"></div>
</div>
JSFIDDLE:
推荐阅读
- python - Keras:将模型对象作为参数传递给损失函数
- java - 如何重写此代码以使用 Stream 和功能 API?
- angular - 无法播放 Angular 2 本地项目中可用的视频
- php - 如何在本地主机中修复 vtiger 7.1.0 中的电子邮件传出服务器
- sqlite - 为什么它使用 sqlite 重复插入?
- graphlab - 无法在 windows8 上安装 graphlab create
- localhost - 我的第一个 NUXT.js 应用程序拒绝在 localhost:3000 上运行
- security - “安全”站点的网络架构
- javascript - ASPxListBox EnableSelectAll 被定义为不是函数
- node.js - 在 forEach 循环中获取 Mongo 数据库值