Home > Web Front-end > CSS Tutorial > How to Replicate Stack Overflow\'s Floating Popup Messages in Your Website?

How to Replicate Stack Overflow\'s Floating Popup Messages in Your Website?

DDD
Release: 2024-10-30 07:22:02
Original
613 people have browsed it

How to Replicate Stack Overflow's Floating Popup Messages in Your Website?

Replicating Stack Overflow's Popup Messages

To replicate the popup messages seen on Stack Overflow when not logged in or when attempting to vote, consider this approach:

Markup:

<div id='message' style="display: none;">
    <span>Hey, This is my Message.</span>
    <a href="#" class="close-notify">X</a>
</div>
Copy after login

CSS:

#message {
    font-family:Arial,Helvetica,sans-serif;
    position:fixed;
    top:0px;
    left:0px;
    width:100%;
    z-index:105;
    text-align:center;
    font-weight:bold;
    font-size:100%;
    color:white;
    padding:10px 0px 10px 0px;
    background-color:#8E1609;
}

#message span {
    text-align: center;
    width: 95%;
    float:left;
}

.close-notify {
    white-space: nowrap;
    float:right;
    margin-right:10px;
    color:#fff;
    text-decoration:none;
    border:2px #fff solid;
    padding-left:3px;
    padding-right:3px
}

.close-notify a {
    color: #fff;
}
Copy after login

JavaScript:

$(document).ready(function() {
    $("#message").fadeIn("slow");
    $("#message a.close-notify").click(function() {
        $("#message").fadeOut("slow");
        return false;
    });
});
Copy after login

This code displays a floating message at the top of the page with a customizable message. A close button is also included for dismissal. Note that the specific CSS and JavaScript applied may vary depending on the context in which you use this solution.

The above is the detailed content of How to Replicate Stack Overflow\'s Floating Popup Messages in Your Website?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template