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

html-css010

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>

在js中加个if判断就行,不过这个座标还是基于window。

js代码:<script language="javascript">

function tips(id,str){

var l=document.getElementById(id).offsetLeft+150

var t=document.getElementById(id).offsetTop

if(document.getElementById(id).id=='password'){

t+=23

}

document.getElementById("tips").innerHTML="提示:"+str

document.getElementById("tips").style.left=l+"px"

document.getElementById("tips").style.top=t+"px"

document.getElementById("tips").style.display=""

}

function outtips(){

document.getElementById("tips").style.display='none'

}

</script>

效果:

使用CSS制作小三角形实际就是通过控制块元素的边框来实现的。

例如:

<style>

.triangle-up {

    width: 0

    height: 0

    border-left: 50px solid transparent

    border-right: 50px solid transparent

    border-bottom: 100px solid red

}

.triangle-down {

    width: 0

    height: 0

    border-left: 50px solid transparent

    border-right: 50px solid transparent

    border-top: 100px solid red

}

.triangle-left {

    width: 0

    height: 0

    border-top: 50px solid transparent

    border-right: 100px solid red

    border-bottom: 50px solid transparent

}

.triangle-right {

    width: 0

    height: 0

    border-top: 50px solid transparent

    border-left: 100px solid red

    border-bottom: 50px solid transparent

}

</style>

<div class='triangle-down'></div> <!--向下三角形-->

<div class='triangle-up'></div> <!--向上三角形-->

<div class='triangle-left'></div> <!--向左三角形-->

<div class='triangle-right'></div> <!--向右三角形-->

原理就是设置块元素的三条边透明掉(tranparent)