我需要一个facebook风格的通知,但在跨浏览器中获取一些看起来不错的东西似乎很棘手.例如,不同的浏览器对填充的处理方式似乎不同,导致出现外观怪异的通知.

确保通知良好显示的最佳跨浏览器方式是什么?虽然不反对使用javascript,但纯css当然更可取

在此处输入图像描述

推荐答案

实现这一目标的最佳方法是使用absolute positioning:

/* Create the blue navigation bar */
.navbar {
  background-color: #3b5998;
  font-size: 22px;
  padding: 5px 10px;
}

/* Define what each icon button should look like */
.button {
  color: white;
  display: inline-block; /* Inline elements with width and height. TL;DR they make the icon buttons stack from left-to-right instead of top-to-bottom */
  position: relative; /* All 'absolute'ly positioned elements are relative to this one */
  padding: 2px 5px; /* Add some padding so it looks nice */
}

/* Make the badge float in the top right corner of the button */
.button__badge {
  background-color: #fa3e3e;
  border-radius: 2px;
  color: white;
 
  padding: 1px 3px;
  font-size: 10px;
  
  position: absolute; /* Position the badge within the relatively positioned button */
  top: 0;
  right: 0;
}
<!-- Font Awesome is a great free icon font. -->
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet"/>

<div class="navbar">
  <div class="button">
    <i class="fa fa-globe"></i>
    <span class="button__badge">2</span>
  </div>
  <div class="button">
    <i class="fa fa-comments"></i>
    <span class="button__badge">4</span>
  </div>
</div>

Html相关问答推荐

如何找到FontAwese图标的Unicode值?

在Chrome中使用手写笔时,滚动条方向反转

根据按钮位置左/右对齐按钮

如何将内容元素放在侧边栏旁边?

在Vue 3中使用v-Bind将计算(computed)属性传递给css url()

为什么我得不到有错误的字段?迈克尔·哈特尔教程.7.3.3

如何用css在右侧创建多个半圆

rvest: Select 不包含链接的段落(<;p>;)

如何使 CSS 网格项目像 Flexbox 项目一样匹配父级的高度

为什么 `::before` 在使用内容 `url(svg)` 时会增加一些高度

jQuery 索引返回不正确的结果

排列卡片时遇到困难

如何创建淡出研磨背景

为什么
标签在 Edge 和 Firefox 中的编号会有两种不同的结果?

具有 css 高度的输入元素:100% 溢出父 div

为四开本网站主页添加背景图片

发光效果html动画

具有淡入/淡出效果的 CSS 选框

嵌套固定定位的 Div 滚动条渗透到前景中的 Div

动态使用时波浪号不转换为绝对路径