简体   繁体   English

css3动画同时出现在两个项目上

[英]css3 animation on two items in the same time

I have a wrapper div that is absolute positioned on the side of my page. 我的包装器div绝对位于页面的一侧。 It contains an unordered list of items. 它包含项目的无序列表。 HTML: HTML:

<div id="wrapper">
    <ul class="menu">
        <li>item 1</li>
        <li>item 2</li>
    </ul>
</div>

Wrapper CSS: 包装CSS:

#wrapper {  
    /*width: 218px;*/
    margin: 0px auto;
    background-color: #cccccc;
    overflow:hidden;
    position: absolute;
    top:  100px;
    left: 0;
    z-index: 999;
    width: 31px;
}

The reduced width of the wrapper is 31px; 包装器减少的宽度为31px; The full size is 218px; 全尺寸为218像素; On each of the list items I have set: 在我设置的每个列表项上:

.menu > li{
    width: 31px;
    overflow: hidden;
    -webkit-transition: width 1s; /* For Safari 3.1 to 6.0 */
    transition: width 1s;
}
.menu > li:hover{
    width:218px;
}

So that when I hover that <li> it reveals all of its content. 这样,当我将鼠标悬停在<li>它便会显示其所有内容。 Obviously it works when wrapper's width is 218px but this way it will go over the page and "hide" some elements on it. 显然,当包装器的宽度为218px时,它可以工作,但是这样,它将遍历页面并“隐藏”页面上的某些元素。 I have set the same transition also on the wrapper on hover and it works. 我还在悬停时的包装器上设置了相同的过渡,并且它可以正常工作。 Is there another way to do it in a more robust way? 还有另一种更健壮的方法吗? This seems to me more an hack than a proper way to do it! 在我看来,这似乎是一种技巧,而不是正确的方法!

You could set overflow on the #wrapper to visible instead of hidden. 您可以将#wrapper上的溢出设置为可见而不是隐藏。 That way, when the li expands when you hover over it, you will be able to see its content - without increasing the size of the wrapper itself. 这样,当li悬停在它上面时,它展开时,您将能够看到它的内容,而无需增加包装器自身的大小。

I think it is better to use chrome browser.It has a feature that very useful to web developers. 我认为最好使用chrome浏览器,它具有对Web开发人员非常有用的功能。

First of all 首先

Open your web page in chrome. 在Chrome中打开您的网页。

Right click (the portion that you want to make changes) and select Inspect element[Ctrl+Shift+i] in windows platform. 右键单击(要进行更改的部分),然后在Windows平台中选择“检查元素[Ctrl + Shift + i]”。

Then u can see like this.. 然后你可以看到这样

编辑过的网页

1 I mentioned here is code section and 2 is css section. 我在这里提到的1是代码部分,2是css部分。

The selected part is highligted in main screen (left side , in my case) 所选部分在主屏幕中处于高亮状态(在我的情况下为左侧)

You can find and select the hidden div. 您可以找到并选择隐藏的div。

Then make necessary changes to css section that suits your web page and you can see the changes at the real time. 然后,对适合您网页的css部分进行必要的更改,您可以实时查看更改。

[ !! [ !! Please note that this is only for checking and viewing ,so if u make necessary changes,Please copy the edited code and paste it to your original source code also create a backup of your source code before make any changes ] 请注意,这仅用于检查和查看,因此,如果您进行必要的更改,请复制编辑后的代码并将其粘贴到原始源代码中,并在进行任何更改之前创建源代码的备份 ]

Regds..sir 先生..先生

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

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