【问题标题】:Hovering on div changes the alignment of the text in it悬停在 div 上会更改其中文本的对齐方式
【发布时间】:2018-01-04 22:54:53
【问题描述】:

我想要的是,当我将鼠标悬停在 div 上时,图像应该变得可见。 这是我的 html 及其样式

.icon {
  cursor: pointer;
  display: none;
}

.text:hover .icon {
  display: inline;
  float: right;
}
<div class="text">
  sometext
  <img class="icon" title="Open" src="somepath"></img>
</div>

问题是当悬停完成时,div 中显示的文本不是居中对齐的。文字相对于图像向上移动。

【问题讨论】:

  • 删除浮动:右 - 仅在悬停时设置或将其移动到 .icon 类。图像对齐可能是罪魁祸首,您可能希望将其包装成一个包装 div,并在一个绝对定位且始终可见的可见 div 中为图像使用一些绝对定位(因此它会消耗图像在它时将持有的空间可见)

标签: html css


【解决方案1】:

将你的 css 更改为:

.text:hover .icon
{
  display:inline;
  right:0px;
  position:absolute;
}

【讨论】:

    猜你喜欢
    • 2016-02-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多