【问题标题】:How to change background image on hover and text color CSS MVC 5如何更改悬停时的背景图像和文本颜色 CSS MVC 5
【发布时间】:2020-06-07 08:00:30
【问题描述】:

这是我的 div,

<div >
                    <div class="thumbnail text-center">
                        <a href="@Url.Action("Index", "Employees")">
                            <img src="~/AppFiles/Images/Tile.png" class="img-fluid img-thumbnail border border-success">
                            <div class="caption">
                                <p>@Resource.Employee</p>
                                <p>@ViewBag.EmpCount</p>
                            </div>
                        </a>
                    </div>
                </div>

当我将鼠标悬停在 div 上时,我想将 imgsrc 更改为 '~/AppFiles/Images/HoverTile.png',而在 class="caption" 中,我希望将文本的颜色更改为 white

希望您的建议

【问题讨论】:

    标签: javascript css asp.net-mvc hover mousehover


    【解决方案1】:

    添加到您的 css 文件中:

    .thumbnail:hover {
     // Write everything you want to happen after hover
    
    
    }
    

    “字幕”类也是如此

     .caption:hover {
     color:white;
     }
    

    如果你想用 javascript 来做这件事并改变 src:

    <img id="my-img" src="http://dummyimage.com/100x100/000/fff" 
    onmouseover="hover(this);" onmouseout="unhover(this);" />
    
    function hover(element) {
    element.setAttribute('src', 'http://dummyimage.com/100x100/eb00eb/fff');
    }
    
    function unhover(element) {
    element.setAttribute('src', 'http://dummyimage.com/100x100/000/fff');
    }
    

    【讨论】:

    • 这似乎很有帮助,但我将如何更改缩略图悬停中的 img url 任何想法?
    • 如果要更改背景照片,可以添加到 thmbnail:hover 类中: background-image: url('YourPath')
    • 我想在 内更改
    • 你不能只用 html 和 css 来做。使用悬停的唯一方法是我告诉你的方式
    • 你可以用 javascript 来做,我会编辑我的答案。如果我的回答有用,请注意标记它
    猜你喜欢
    • 1970-01-01
    • 2021-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-10
    相关资源
    最近更新 更多