html - 请问css 中一个元素能做出这种选中效果么?
大家讲道理
大家讲道理 2017-04-17 11:42:30
[CSS3讨论组]

如果做不出,也可以两个元素,最好不要绝对定位

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

全部回复(2)
阿神

首先是不太可能只用一個元素,因為想要實現自定義的 radio 或是 checkbox 時,都得靠 labelfor 來實現,就是隱藏實際 input ,然後自定義 label 的樣式來實現,所以至少得兩個。

實現

<input name="radios" class="circle-radio" type="radio" id="radio1"/><label for="radio1"></label>

<input name="radios" class="circle-radio" type="radio" id="radio2"/><label for="radio2"></label>
.circle-radio {
  visibility: hidden;
}

.circle-radio + label {
  display: block;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid #00AAFF;
}

.circle-radio:checked + label {
  display: block;
  background: #00AAFF;
  box-shadow: inset 0px 0px 0px 6px white;
}
黄舟
    <p class="outer">
        <p class="inner"></p>
    </p>
.outer {
    width: 100px;
    height: 100px;
    margin: 0 auto;
    border: 3px solid blue;
    border-radius: 50px;
}
.inner {
    display: none;
    width: 50%;
    height: 50%;
    margin: 0 auto;
    margin-top: 25%;
    border-radius: 25px;
    background-color: blue;
}
p.outer:hover p.inner{
    display: block;
}

使用 border-radius 和 css 伪类选择器 :hover
预览

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号