(CSS) How position text (with background color) over lt;imggt; tag without absolute positioning((CSS) 如何在 lt;imggt; 上定位文本(带背景颜色)没有绝对定位的标签)
问题描述
正如标题所说
我的代码是这样的:
<div class=container> <img/> <div>some text with line one, line two , line three </div> </div>
容器应该有 overflow:hidden 并且我的文本会超过一行,所以我只需要我的一小部分文本出现在容器的底部,所以当用户悬停时,会出现全文.
the container should have overflow:hidden and my text would be in more than one line , so I need only a small part of my text to appear at the bottom of container, so when user hovers, the full text appears.
我想在没有绝对定位的情况下将文本定位在 img 上.我尝试了负边距,但那里的文本不会有 BG 颜色.还尝试了相对位置.=> 在 IE 上效果很好,但不是偶然的.
I want to position text over img WITHOUT absolute positioning. I tried negative margins, but text wouldn't have BG color there. Also tried Relative pos. => works great but not on chance on IE.
这是我想要的图片
推荐答案
我认为没有理由不使用 position: absolute
.
I see no reason not to use position: absolute
.
参见: http://jsfiddle.net/NeaR4/
CSS:
.container {
border: 2px dashed #444;
float: left;
position: relative
}
.container img {
display: block
}
.container > div {
position: absolute;
left: 0;
bottom: 0;
right: 0;
height: 14px;
background: #000;
background: rgba(0,0,0,0.7);
color: #fff;
overflow: hidden;
font: bold 14px Arial, sans-serif;
padding: 5px;
}
.container:hover > div {
height: auto
}
HTML:
<div class="container">
<img src="aHR0cDovL2R1bW15aW1hZ2UuY29tLzIzMHgxODAvZjBmL2ZmZg==" />
<div>some text with line oneeee, line twoooooooo ooooooo , line three</div>
</div>
这篇关于(CSS) 如何在 <img> 上定位文本(带背景颜色)没有绝对定位的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:(CSS) 如何在 <img> 上定位文本(带背景颜色)没有绝对定位的标签


- 是否可以将标志传递给 Gulp 以使其以不同的方式 2022-01-01
- 如何调试 CSS/Javascript 悬停问题 2022-01-01
- 从原点悬停时触发 translateY() 2022-01-01
- 如何显示带有换行符的文本标签? 2022-01-01
- 为什么悬停在委托事件处理程序中不起作用? 2022-01-01
- 在不使用循环的情况下查找数字数组中的一项 2022-01-01
- 使用 iframe URL 的 jQuery UI 对话框 2022-01-01
- 为什么我的页面无法在 Github 上加载? 2022-01-01
- 如何向 ipc 渲染器发送添加回调 2022-01-01
- 我不能使用 json 使用 react 向我的 web api 发出 Post 请求 2022-01-01