账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    CSS3实现右上角卡片通知提示
    49
    0
    <!doctype html>
    <html>
    <head>
        <style>
            .container {
                position: fixed;
                top: 45px;
                right: 4px;
                height: 0;
                text-align: right;
                overflow: visible;
            }
            .card {
                display: inline-block;
                max-width: 200px;
                line-height: 24px;
                padding: 8px 12px;
                margin-bottom: 4px;
                color: #FFFFFF;
                text-align: left;
                background-color: #F68C1E;
            }
        </style>
    </head>
    <body>
        <div class="container">
            <div class="card"><span>宽度不一</span></div><br>
            <div class="card"><span>有色区域为真实大小</span></div><br>
            <div class="card"><span>结构简单</span></div>
        </div>
    </body>
    </html>

    目前这个就是想要的效果,但是要用<br>来换行,试过

    .card::after {
        content: "\A";
        white-space: pre;
    }

    但对inline-block的元素没有效果,用inline-block是为了让div适应内容大小而不是铺满父div宽度。
    有没有大神可以帮忙实现结构简单的去掉<br>同样的效果,感激不尽。
    预览代码:http://runjs.cn/detail/kjprizbv

    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 少女的秘密 普通会员 1楼

      在CSS3中,我们可以使用position: absolutez-indexdisplay属性来实现右上角卡片通知提示。以下是一个简单的示例:

      HTML部分:

      ```html

      你的通知

      ```

      CSS部分:

      ```css .card { position: absolute; z-index: 1; top: 50%; left: 50%; transform: translate(-50%, -50%); }

      .card-content { display: flex; justify-content: space-between; align-items: center; }

      .card-navigation { display: flex; justify-content: space-between; align-items: center; }

      .card-navigation a { color: #fff; text-decoration: none; padding: 10px 20px; border-radius: 5px; cursor: pointer; }

      .card-navigation a:hover { background-color: #333; } ```

      在这个例子中,我们首先定义了一个卡片类,然后在CSS中设置了它的定位、Z-index和display属性。然后,我们设置了卡片的内容、导航和通知按钮的样式。

      注意,这个例子中的通知按钮只能点击一次,如果你想让它可以点击多次,你可能需要使用JavaScript或者其他前端技术来处理。

    • 金橙橙。- 普通会员 2楼

      在CSS3中,我们可以使用position: absolutez-indexdisplay属性来实现右上角卡片通知提示。以下是一个简单的示例:

      HTML部分:

      ```html

      你的通知

      ```

      CSS部分:

      ```css .card { position: absolute; z-index: 1; top: 50%; left: 50%; transform: translate(-50%, -50%); }

      .card-content { display: flex; justify-content: space-between; align-items: center; }

      .card-navigation { display: flex; justify-content: space-between; align-items: center; }

      .card-navigation a { color: #fff; text-decoration: none; padding: 10px 20px; border-radius: 5px; cursor: pointer; }

      .card-navigation a:hover { background-color: #333; } ```

      在这个例子中,我们首先定义了一个卡片类,然后在CSS中设置了它的定位、Z-index和display属性。然后,我们设置了卡片的内容、导航和通知按钮的样式。

      注意,这个例子中的通知按钮只能点击一次,如果你想让它可以点击多次,你可能需要使用JavaScript或者其他前端技术来处理。

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部