简体   繁体   English

我想通过将文本悬停在div内的文本上来更改div的高度

[英]I want to change the div height by hovering on the text INSIDE the div

I have a outer div named Title which has style="width=100%" and inner div named more 我有一个名为Title的外部div,其style="width=100%" ,内部div的命名为more

So I want to change height of outer div by hovering on inner div(smoothly.. using transition) 所以我想通过将鼠标悬停在内部div上来平滑更改外部div的高度(使用过渡平滑..)

Is it possible using css?? 是否可以使用CSS?

I want something like 我想要类似的东西

transition: height .4s;
-moz-transition: height .4s; 
-webkit-transition: height .4s; 
-o-transition: height .4s;  
-ms-transition: height .4s;

my title css code 我的标题CSS代码

#title{
    display:inline-block;
    background-color:#000;
    position:absolute;
    top:20px;
    left:20px;
    right:20px;
    margin:0px;
    padding:0px;
    height:42px;
    min-width:800px;
}

My more css code 我的更多CSS代码

#more{
    padding-left:10px;
    color:#999;
    text-decoration:underline;
    font-size:10px;
}

All the below code are not working 以下所有代码均无效

  • name:hover #title{height:200px}
  • name:hover + #title{height:200px}
  • name:hover ~ #title{height:200px}
  • name:hover > #title{height:200px}

can i do it through JavaScript??? 我可以通过JavaScript做到吗???

You cannot target an ancestor element in css without using the Subject Identifier which is introduced in CSS Selectors Level 4 Draft which is supported by none of the browsers at the moment. 如果不使用CSS选择器第4级草稿中引入的主题标识符 ,则无法在css中定位祖先元素,目前尚无浏览器支持该主题标识符

In farther future you can write (the exclamation mark is a temporary solution): 在更远的将来,您可以写(感叹号是一个临时解决方案):

!#Title name:hover{
    /* css stuff */
}

You can however do one of the following things: 但是,您可以执行以下操作之一:

Declare display:table on your #title div and animate the #more div like in this example . 本例 display:table ,在#title div上声明display:table并为#more div设置动画。 Works at least in chrome;) 至少在Chrome中有效;)

Or you just use javascript (or perhaps jQuery), apply an eventhandler and either modify the height of #title directly or apply a class holding the transition effect. 或者,您只使用javascript(或者可能是jQuery),应用事件处理程序并直接修改#title的高度或应用具有过渡效果的类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM