热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

CSS:在方框的右侧旋转投影。-CSS:Rotateddropshadowonrightsideofbox

Ihaveafixed,100%heightmenuontheleftandIneedtocreateashadoweffectonitsrightside

I have a fixed, 100% height menu on the left and I need to create a shadow effect on its right side that would disappear after while.

我有一个固定的,100%的高度菜单在左边,我需要在它的右边创建一个阴影效果,一会就会消失。

See the figure that illustrates this.

请参见说明这一点的图。

enter image description here

How to create this effect?

如何产生这种效果?

Here is a fiddle: http://jsfiddle.net/52VtD/7787/

这里有一个小提琴:http://jsfiddle.net/52VtD/7787/

HTML:

HTML:


CSS:

CSS:

#main-menu {
    width: 320px;
    height: 100%;
    top: 0;
    z-index: 1000;
    position: fixed;
    background-color: #b4bac1;
}

2 个解决方案

#1


9  

You can achieve this with CSS3: box-shadow and transform.

可以通过CSS3: box-shadow和transform来实现这一点。

In the example below the box-shadow is applied to a pseudo element of .menuContainer which sits underneath the .menu element and is rotated by using CSS3s rotate() transform property.

在下面的例子中不必是应用于一个伪元素.menuContainer坐落在.menu元素和使用css3旋转旋转1°()变换性质。

html,body {  /* This is only here to allow the menu to stretch to 100% */
    height: 100%;
    margin: 0;
}
.menuContainer {
    position: relative;    
    height: 100%;
    width: 100px;
}
.menuContainer::after {
    content: "";
    position: absolute;   
    z-index: 1; 
    top: -10px;
    bottom: 0;
    left: -7px;
    background: rgba(0,0,0,0.3);
    box-shadow: 10px 0 10px 0 rgba(0,0,0,0.3);
    width: 100px;    
    transform: rotate(1deg);
}
.menu {
    background: #f00;
    height: 100%;
    width: 100px;
    position: relative;
    z-index: 2;
}

JSFiddle

#2


1  

You could fake it with a pseudo-element rather than using a box-shadow as follows

您可以使用伪元素来伪造它,而不是像下面这样使用框形阴影

JSfiddle Demo

JSfiddle演示

CSS

CSS

#main-menu {
    width: 50px;
    height: 100%;
    top: 0;
    z-index: 1000;
    position: fixed;
    background-color: pink;
}

#main-menu:after {
    content:"";
    position: absolute;
    top:0;
    left:100%;
    height:100%;
    width:5%;
    background: linear-gradient(to bottom, rgba(0,0,0,0.15) 0%,rgba(0,0,0,0) 100%);
}

推荐阅读
author-avatar
手哥2502852243
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有