首页 > 其他分享 >好看的CSS效果

好看的CSS效果

时间:2022-10-25 22:24:09浏览次数:44  
标签:效果 transform ul menuToggle CSS input position border 好看

好看的效果

1.复选框:
思路是使用复选框并进行隐藏,然后自己写一个div,并且用:before来放进div复选框这,不少地方采用绝对定位,在:checked时更改对应颜色。

    <div class="container">
      <h2>To it</h2>
      <ul>
        <li>
          <input type="radio" id="f-option" name="selector" />
          <label for="f-option">Pizza</label>
          <div class="check"></div>
        </li>

        <li>
          <input type="radio" id="s-option" name="selector" />
          <label for="s-option">Bacon</label>
          <div class="check">
            <div class="inside"></div>
          </div>
        </li>

        <li>
          <input type="radio" id="t-option" name="selector" />
          <label for="t-option">Cats</label>
          <div class="check">
            <div class="inside"></div>
          </div>
        </li>
      </ul>
    </div>
body,html{
    height: 100%;
    background: #222222;
    font-family: 'lato', sans-serif;
}
.container{
    display: block;
    position: relative;
    margin: 40px auto;
    height: auto;
    width: 500px;
    padding: 20px;
}

h2{
    color: #AAAAAA;
}

.container ul{
    list-style: none;
    margin: 0;
    padding: 0;
    overflow:auto;
}

ul li{
    color:#AAAAAA;
    display: block;
    position: relative;
    float: left;
    width: 100%;
    height: 100px;
    border-bottom: 1px solid #333;
}
ul li input[type=radio]{
    position: absolute;
    visibility: hidden;
}
ul li label{
    display: block;
    position: relative;
    font-weight: 300;
    font-size: 1.35em;
    padding: 25px 25px 25px 80px;
    margin: 10px auto;
    height: 30px;
    z-index: 9;
    cursor: pointer;
    transition: all 0.25s linear;
}

ul li:hover label{
    color: #fff;
}
ul li .check{
    display: block;
    position:absolute;
    border: 5px solid #AAAAAA;
    border-radius: 100%;
    height: 25px;
    width: 25px;
    top: 30px;
    left: 20px;
    z-index: 5;
    transition: border .25s linear;
    -webkit-animation: border .25s linear;
}

ul li:hover .check{
    border: 5px solid #fff;
}
ul li .check::before{
    display: block;
    position:absolute;
    content: '';
    border-radius: 100%;
    height: 15px;
    width: 15px;
    top: 5px;
    left: 5px;
    margin: auto;
    transition: all 0.25s linear;
}
input[type=radio]:checked ~ .check{
    border:5px solid #0DFF92
}
input[type=radio]:checked ~.check::before{
    background: #0DFF92;
}
input[type=radio]:checked ~ label{
    color: #0DFF92;
}

对应效果:
链接

2.菜单栏:使用复选框,设置为透明,使用三条span实现图案,然后三个span可以通过transform来定义旋转角度以及设置变换原点,然后使用选择器三条杆的选择方向不同.

<nav role="navigation">
  <div id="menuToggle">
    <input type="checkbox"/>
    <span></span>
    <span></span>
    <span></span>
    <ul id="menu">
      <a href="#"><li>Home</li></a>
      <a href="#"><li>About</li></a>
      <a href="#"><li>Info</li></a>
    </ul>
  </div>
</nav>
body{
    margin: 0;
    padding: 0;
    background: #232323;
    color: #cdcdcd;
    font-family: "Avenir Next","Avenir",sans-serif;
}
#menuToggle{
    display: block;
    position: relative;
    top:50px;
    left: 50px;
    z-index: 1;
    user-select: none;
}
#menuToggle a{
    text-decoration: none;
    color: #232323;
    transition: color 0.3s ease;
}
#menuToggle a:hover{
    color: tomato;
}
#menuToggle input{
    display: block;
    width: 40px;
    height: 32px;
    position: absolute;
    top:-7px;
    left: -5px;
    cursor: pointer;
    opacity: 0;
    z-index:2;
}
#menuToggle span
{
display: block;
width: 33px;
height: 4px;
margin-bottom: 5px;
position: relative;
background:#cdcdcd;
border-radius: 3px;
z-index:1;
transform-origin: 4px 0px;
transition: transform 0.5s cubic-bezier(0.77,0.2,0.05,1.0),background 0.5s cubic-bezier(0.77,0.2,0.05,1.0),opacity 0.55s ease;
}
#menuToggle span:first-child
{
    transform-origin: 0% 0%;
}
#menuToggle span:nth-last-child(2)
{
    transform-origin: 0% 100%;
}
#menuToggle input:checked ~ span
{
    opacity: 1;
    transform: rotate(45deg) translate(-2px,-1px);
    background: #232323;
}
#menuToggle input:checked ~ span:nth-last-child(3)
{
    opacity: 0;
    transform: rotate(0deg) scale(0.2,0.2);
}
#menuToggle input:checked ~ span:nth-last-child(2)
{
    transform: rotate(-45deg) translate(0,-1px);
}
#menu
{
    position:absolute;
    width: 300px;
    margin: -100px 0 0 -50px;
    padding: 50px;
    padding-top: 125px;
    background: #ededed;
    list-style-type: none;
    -webkit-font-smoothing:antialiased;
    transform-origin: 0% 0%;
    transform: translate(-100%,0);
    transition: transform 0.5s cubic-bezier(0.77,0.2,0.05,1.0);
}
#menu li
{
    padding: 10px 0;
    font-size: 22px;
}
#menuToggle input:checked ~ ul
{
transform: none;
}

连接

标签:效果,transform,ul,menuToggle,CSS,input,position,border,好看
From: https://www.cnblogs.com/mengyiqwq/p/16826579.html

相关文章

  • CSS
    CSS简介CSS是一门语言,用于控制网页表现CSS:层叠样式表W3C CSS导入方式CSS导入HTML有三种方式内联样式:在标签内部使用style属性,属性值是css属性键值对<divstyle=......
  • APP自动化效果测试工具
    1.背景项目测试过程中经常需要在手机端体验语音产品的识别效果和稳定性,识别效果与手机硬件强相关无法抛开硬件影响。因此开发了一套基于uiautomator2+pythonUI自动化工具,......
  • 美颜滤镜SDK有什么效果?美颜SDK可以自主开发吗?
    当下,短视频和直播平台在互联网娱乐APP类中保持着极高的人气,特别是在年轻群体中,甚至已经成了人手必备。如今的年轻人喜欢追求新鲜事物,审美能力也有所提高,对自己外表比较严格,......
  • Solidworks 2020总是显示3D效果,不能消失平面效果
    打开SolidWorks2020装配体后,通过快捷方式Space正视于前视基准面或者其他基准面后,总是显示3D效果,不能显示2D效果,就像轴测图一样,如下:解决办法:在设计树上的“前视基准面”......
  • vite+ts+scss 设置多个scss公共样式不起作用
    preprocessorOptions:{scss:{additionalData:`@use"./src/assets/scss/style.scss"as*;@use"./src/assets/scss/index.scss"as*;@use"./src/assets/scss/......
  • css命名
    BEM是一种CSS命名规范。BEM代表“块(block),元素(element),修饰符(modifier)”。好处:摆脱特异性的困扰修复继承问题停止担心命名在选择器中,由以下三种符号来表示扩展的关系:......
  • vite+vue3使用tailwindcss
    vite+vue3使用1.通过npm安装Tailwindnpminstall-Dtailwindcss@latestpostcss@latestautoprefixer@latest2.创建您的配置文件npxtailwindcssinit这将会在......
  • css-垂直居中
    前言水平居中可以简单使用以下两种方式:margin:0auto;text-align:center;故重点讨论垂直居中1.(一行文字)设置行高等于父元素高度line-height:200px;//设置行高等于......
  • CSS盒子模型与定位
    盒子模型与定位元素简单分三大类:块级元素,内联元素(行级),内联块级元素块级元素:元素宽度在不设置的情况下,是它本身父容器的100%常见的块级元素有:<div>,<p>,<h1>~<......
  • CSS `@font-face` & font-family All In One
    CSS@font-face&font-familyAllInOne@font-face&font-family@font-face{font-family:"OpenSans";src:url("/fonts/OpenSans-Regular-webfont.woff2")......