html - 将悬停时的阴影效果添加到 DIV 框

标签 html css animation hover shadow

我目前正在尝试找出一种方法,以便在将鼠标悬停在我网站首页 (http://thefloodplains.com/) 上的每个单独框上时,该特定框会出现阴影动画。我希望它看起来与此页面上的内容非常相似:http://tobiasahlin.com/blog/how-to-animate-box-shadow/ .我已将此页面用作尝试设置悬停阴影效果的指南。

这是专门用于我网页上的 div 框的 CSS/HTML (http://thefloodplains.com/):

.col-md-4 {
    color:#00A5D1;
    height:300px;
}

.col-md-3 {
    color:#00A5D1;
    height:300px;
    box-shadow: 2 2px 3px rgba(0, 0, 0.1, 0.1);
    -webkit-transition: all 0.6s cubic-bezier(0.165, 0.84, 0.44, 1);
    transition: all 0.6s cubic-bezier(0.165, 0.84, 0.44, 1);
}

.col-md-4:hover {
    background-color: #FFE097;
}
.col-md-3:hover {
    -webkit-transform: scale(1.25, 1.25);
    transform: scale(1.25, 1.25);
    }

.col-md-4 h3 {
    position: relative;
    top: 40%;
    transform: translateY(-50%);
}

.col-md-4 {
    color:#00A5D1;
    height:300px;
    border: 1px solid #FF8B6F;
    position: relative;
}

.col-md-3 {
    height:300px;
    position: relative;
}

.col-md-4:after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  display: block;
  background: #FFE097;
  opacity: 0;
}

.col-md-3:after {
  content: "";
  position: absolute;
  z-index: -1;
  top: 0;
  right: 0;    
  left: 0;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
  opacity: 0;
  -webkit-transition: all 0.6s cubic-bezier(0.165, 0.84, 0.44, 1);
  transition: all 0.6s cubic-bezier(0.165, 0.84, 0.44, 1);
}

.col-md-4:hover:after {
  opacity: .5;
}

.col-md-3:hover:after {
  opacity: 1;
}

.col-md-4 h3 {
    position: relative;
    z-index: 1;
    top: 40%;
    transform: translateY(-50%);
}

“.col-md-3”类的任何内容都是我尝试添加悬停阴影效果的地方(与我已经设置当前悬停颜色效果的方式大致相同)。以下代码是我首页的其余 CSS/HTML:

<style>
    h3 {
        font-size:36px;
        font-style: bold;
        text-align:center;
        font-family:'Buernard', Garamond, "Buenard", "EB Garamond",'EB Garamond';
    }
    img {
        max-width: 100%;
        max-height: 100%;   
    }
    #div1 {
            background-image: url('AboutIcon.png');
            background-position: center center; //center the image in the div
            background-size: cover; //cover the entire div
            background-repeat: no-repeat;
            background-size: 100%;
    }
    #div2 {
            background-image: url('ArticlesIcon.png');
            background-position: center center; //center the image in the div
            background-size: contain; //cover the entire div
            background-repeat: no-repeat;
            background-size: 100%;
    }
    #div3 {
            background-image: url('CodingBrackets2.png');
            background-position: center center; //center the image in the div
            background-size: cover; //cover the entire div
            background-repeat: no-repeat;
            background-size: 100%;
    }
    #div4 {
            background-image: url('ContactIcon.png');
            background-position: center center; //center the image in the div
            background-size: contain; //cover the entire div
            background-repeat: no-repeat;
            background-size: 100%;
    }
    #div5 {
            background-image: url('FSMusicArt.png');
            background-position: center center; //center the image in the div
            background-size: cover; //cover the entire div
            background-repeat: no-repeat;
            background-size: 100%;
    }
    #div6 {
            background-image: url('AudioProduction4.png');
            background-position: center center; //center the image in the div
            background-size: cover; //cover the entire div
            background-repeat: no-repeat;
            background-size: 100%;
    }
    #div7 {
            background-image: url('Violin3.png');
            background-position: center center; //center the image in the div
            background-size: cover; //cover the entire div
            background-repeat: no-repeat;
            background-size: 100%;
    }
    #div8 {
            background-image: url('GalleryImage2.png');
            background-position: center center; //center the image in the div
            background-size: cover; //cover the entire div
            background-repeat: no-repeat;
            background-size: 100%;
    }
    #div9 {
            background-image: url('Handshake2.png');
            background-position: center center; //center the image in the div
            background-size: cover; //cover the entire div
            background-repeat: no-repeat;
            background-size: 100%;
    }
    div {
        background-image:url(../images/please-dont-use-spaces.jpg); //add the background image
        background-position: center center; //center the image in the div
        background-size: cover; //cover the entire div
    }
    </style>    
    </head>
    <body>
        <div class="container">
            <div class="row">
                <a href="About.html" title="About the site and Author"><div class="col-md-4" id='div1'>
                    <h3>About</h3>
                    </div></a>
                <a href="Articles.html" title="Original Articles and Content"><div class="col-md-4" id='div2'>
                    <h3>Articles</h3>
                </div>
                <a href="CodingCorner.html" title="Coding Corner - Code for a Variety of Projects"><div class="col-md-4" id="div3">
                    <h3>Coding Corner</h3>
                </div></a>
            </div>
            <div class="row">
                <a href="Contact-Social.html" title="Contact The Floodplains & The FloodShark"><div class="col-md-4" id="div4">
                  <h3>Contact & Social</h3>
                </div></a>
                <a href="TheFloodSharkMain.html" title="The FloodShark Music and Media"><div class="col-md-4" id="div5">
                    <h3>
                    The FloodShark
                    Music
                    </h3>
                </div></a>
                <a href="FloodplainProductions.html" title="Floodplain Productions - virtual record label"><div class="col-md-4" id="div6">
                    <h3>Floodplain Productions</h3>
                </div></a>
            </div>  
            <div class="row">   
                <a href="ClassicalCorner.html" title="Classical Corner - A nook dedicated to sharing and categorizing classical music"><div class="col-md-4" id="div7">
                    <h3>Classical Corner</h3>
                </div></a>
                <a href="Gallery.html" title="Images, Photographs, and Album Art"><div class="col-md-4" id="div8">
                    <h3>Gallery</h3>
                </div></a>
                <a href="Contribute-Support.html" title="Contribute to The Floodplains!"><div class="col-md-4" id="div9">
                    <h3>Contribute / Support</h3>
                </div></a>
            </div>  
        </div>  
    </body>

我尝试将“col-md-3”作为上述代码中的第二个类添加到 div,以及“col-md-4”,它控制颜色悬停效果。问题是,我认为这种方法行不通,但我不确定是什么方法。截至目前,我正在使用“col-md-4”颜色悬停效果 - 它正在工作 - 但让阴影效果同时工作是我尚未弄清楚的事情。

因此,目前 - 在悬停时 - 框会变成透明的橙色/黄色阴影。有没有办法让阴影动画和变色悬停同时工作?所以基本上我只需要将悬停动画添加到 http://thefloodplains.com/ 上已有的内容。 .

提前感谢您的宝贵时间。

最佳答案

为效果创建一个新类,即 hovernow 添加以下代码:

body {
  background-color: white;
}

.hovernow {
  background-color: red;
  width: 100px;
  height: 100px;
  margin: 10px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
  transition: box-shadow 0.3s ease-in-out;
}

.hovernow:hover {
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.8);
}
<div class="hovernow">

</div>

然后将此类 .hovernow 添加到您希望应用 hover 效果的 div。

关于html - 将悬停时的阴影效果添加到 DIV 框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50757671/

相关文章:

html - IE8 不显示带有 float 的 div

html - 如何修复 CSS 轮播?

animation - TabView 的 SwiftUI 动画选项卡

c# - Unity偏移循环总是从头开始?

html - DIV 中的居中文本

css - 如何在不单击的情况下在 React 中获取 event.target

javascript - 防止杀帧

html - 添加新文本元素后,有没有一种方法可以使 CSS 动画文本移动

javascript - HTML5 本地存储无法找到变量,即使 console.log 显示它

android - 网站在现代 Android 浏览器中以不同方式呈现是否很常见?