I have some HTML which basically has a div with text in it. I created a second div with absolute positioning and I want it to slide up (originally hidden below the main div) to give the effect of the div filling with new background color.

我有一些HTML,里面有一个带有文本的div。我创建了一个带有绝对定位的第二个div,并且我希望它向上滑动(最初隐藏在主div之下),以使div填充的效果具有新的背景颜色。

I got the div to slideup, but it always covers the original text. How do I keep it from doing that.

我把div设置为slideup,但它总是覆盖原始文本。我怎么阻止它这么做。

JSFiddle: http://jsfiddle.net/SmAHU/206/

JSFiddle:http://jsfiddle.net/SmAHU/206/

Code: HTML:

HTML:代码:

<div id="container">
    <div id="blue">Hey</div>
    <div id="green"></div> </div> <input type="button" value="up" id="button" />

CSS

CSS

#container    {position:relative; overflow:hidden; height:50px; width:50px; }
#blue         {height:50px; width:50px; background:#009; position:relative; top:0; left:0; color:white;}
#green        {height:50px; width:50px; background:#090; position:absolute; top:50px; left:0;}

Jquery

Jquery

$('#button').toggle(function() {
    $('#green').animate({
        top: 0
    }, 1000, function() {
        $('#button').val('down');
    });
}, function() {
    $('#green').animate({
        top: '50'
    }, 1000, function() {
        $('#button').val('up');
    });
});

1 个解决方案

#1


0

You could simply wrap a span element around the #blue element's text.

您可以简单地围绕#blue元素的文本包装一个span元素。

<div id="container">
    <div id="blue">
        <span>Text</span>
    </div>
    <div id="green"></div>
</div>

Then position the span element and increase the z-index:

然后定位跨度元素并增加z指数:

Updated Example

更新的例子

#blue > span {
    position: relative;
    z-index: 1;
}

更多相关文章

  1. 用无序列表键入文本脚本
  2. 通过属性名称获取HTML元素
  3. Jquery在两个元素之间更改文本
  4. 使用下一个div中的文本设置“下一个”按钮的文本
  5. HTML基础 img标签alt属性 当图片加载失败的时候显示为文本
  6. HTML哪些是块级元素,哪些是行内元素、
  7. 【WEB基础】HTML & CSS 基础入门(3)段落及文本
  8. 为什么v-align中的将文本放在图像下面
  9. 如何使用CSS消除元素的偏移?

随机推荐

  1. 【Android】Android内存溢出问题---用自
  2. android activity非全屏、透明
  3. Android studio 签名 报错:Could not down
  4. android 资源获取
  5. Android drawable 目录下 创建子目录问题
  6. android json相关
  7. android 将时间戳转为代表"距现在多久之
  8. Android实现手机振动设置的方法
  9. Android启动之BOOT_COMPLETED广播
  10. activity跳转闪现黑屏