<i id='E8EWZ'><tr id='E8EWZ'><dt id='E8EWZ'><q id='E8EWZ'><span id='E8EWZ'><b id='E8EWZ'><form id='E8EWZ'><ins id='E8EWZ'></ins><ul id='E8EWZ'></ul><sub id='E8EWZ'></sub></form><legend id='E8EWZ'></legend><bdo id='E8EWZ'><pre id='E8EWZ'><center id='E8EWZ'></center></pre></bdo></b><th id='E8EWZ'></th></span></q></dt></tr></i><div id='E8EWZ'><tfoot id='E8EWZ'></tfoot><dl id='E8EWZ'><fieldset id='E8EWZ'></fieldset></dl></div>
<legend id='E8EWZ'><style id='E8EWZ'><dir id='E8EWZ'><q id='E8EWZ'></q></dir></style></legend>

  1. <small id='E8EWZ'></small><noframes id='E8EWZ'>

    <tfoot id='E8EWZ'></tfoot>

      • <bdo id='E8EWZ'></bdo><ul id='E8EWZ'></ul>
    1. (CSS) 如何在 &lt;img&gt; 上定位文本(带背景颜色)没有绝对定位的标签

      时间:2023-11-30
    2. <small id='ncnlX'></small><noframes id='ncnlX'>

                <tbody id='ncnlX'></tbody>
              <legend id='ncnlX'><style id='ncnlX'><dir id='ncnlX'><q id='ncnlX'></q></dir></style></legend>
              <tfoot id='ncnlX'></tfoot>
                <bdo id='ncnlX'></bdo><ul id='ncnlX'></ul>
                <i id='ncnlX'><tr id='ncnlX'><dt id='ncnlX'><q id='ncnlX'><span id='ncnlX'><b id='ncnlX'><form id='ncnlX'><ins id='ncnlX'></ins><ul id='ncnlX'></ul><sub id='ncnlX'></sub></form><legend id='ncnlX'></legend><bdo id='ncnlX'><pre id='ncnlX'><center id='ncnlX'></center></pre></bdo></b><th id='ncnlX'></th></span></q></dt></tr></i><div id='ncnlX'><tfoot id='ncnlX'></tfoot><dl id='ncnlX'><fieldset id='ncnlX'></fieldset></dl></div>
                本文介绍了(CSS) 如何在 &lt;img&gt; 上定位文本(带背景颜色)没有绝对定位的标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                正如标题所说

                我的代码是这样的:

                <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="http://dummyimage.com/230x180/f0f/fff" />
                    <div>some text with line oneeee, line twoooooooo ooooooo , line three</div>
                </div>
                

                这篇关于(CSS) 如何在 &lt;img&gt; 上定位文本(带背景颜色)没有绝对定位的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:为什么负 z-index 会消除非静态定位元素的悬停功能? 下一篇::active 与 :hover 不同时的样式按钮

                相关文章

              • <i id='tAQzX'><tr id='tAQzX'><dt id='tAQzX'><q id='tAQzX'><span id='tAQzX'><b id='tAQzX'><form id='tAQzX'><ins id='tAQzX'></ins><ul id='tAQzX'></ul><sub id='tAQzX'></sub></form><legend id='tAQzX'></legend><bdo id='tAQzX'><pre id='tAQzX'><center id='tAQzX'></center></pre></bdo></b><th id='tAQzX'></th></span></q></dt></tr></i><div id='tAQzX'><tfoot id='tAQzX'></tfoot><dl id='tAQzX'><fieldset id='tAQzX'></fieldset></dl></div>

              • <small id='tAQzX'></small><noframes id='tAQzX'>

              • <legend id='tAQzX'><style id='tAQzX'><dir id='tAQzX'><q id='tAQzX'></q></dir></style></legend>

                    <bdo id='tAQzX'></bdo><ul id='tAQzX'></ul>

                  <tfoot id='tAQzX'></tfoot>