htm+css字的右上角用于提示的红点怎么实现

html-css08

htm+css字的右上角用于提示的红点怎么实现,第1张

实现代码如下:

<div class="wrap">

<div class="img"></div>

<div class="notice">1</div>

</div>

<div class="wrap">

<div class="img"></div>

<div class="notice">12</div>

</div>

<div class="wrap">

<div class="img"></div>

<div class="notice">13</div>

</div>

<style>

.wrap {

width:50px

margin-bottom:10px

position:relative

}

.img {

width:50px

height:50px

border:1px solid #000

}

.notice {

width:20px

height:20px

line-height:20px

font-size:10px

color:#fff

text-align:center

background-color:#f00

border-radius:50%

position:absolute

right:-10px

top:-10px

}

</style>

扩展资料:

注意事项

主要用到position定位,CSS position属性用于指定一个元素在文档中的定位方式。top、right、bottom、left 属性则决定了该元素的最终位置。

static是position的默认值。

<!DOCTYPE html>

<html lang="en">

<head>   

<meta charset="UTF-8">   

<title>CSS-position-static</title>   

<link rel="stylesheet" href="https://cdn.bootcss.com/normalize/8.0.0/normalize.css">

  <style>

      .container{

         background-color: #868686

           width: 100%

           height: 300px

       }

       .content{

           background-color: yellow

           width: 100px

          height: 100px

           position: static

           left: 10px/* 这个left没有起作用 */

       }

   </style>

</head>

<body>

  <div class="container">

       <div class="content"> 

       </div>

   </div>

</body>

</html>

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8" />

<title></title>

<style type="text/css">

.redcircle {undefined

position: absolute

margin: 52px 45px

width: 12px

height: 12px

background: #FF0000

border-radius: 50%

border: 1px solid #FF6347

}

.greencircle {undefined

position: absolute

margin: 52px 45px

width: 12px

height: 12px

background: #228B22

border-radius: 50%

border: 1px solid #3CB371

}

</html>

其实我就想实现未点击按钮时,文字右上方有小圆点,点击后消失的效果

但是不想用浮动、定位,结果百度搜了一圈,大家都是用浮动、定位解决,

记录两种更好的解决方案:

1.使用sup标签

2.使用css属性vertical-align