如何在css3中轻松调整此图标的大小/响应速度?

时间:2013-08-13 04:17:44

标签: css3

我想在CSS3中制作以下图标,这样我的宽度和高度只能是“.circle”(或者其他一些包装元素,点我想在一个地方调整宽度和高度,甚至可以制作它这样它就可以自动适合任何容器,无论宽度和高度如何),而无需调整任何其他CSS3属性,使“A”排列在中心。

最好的方法是什么?如果您可以推荐更好的方法来执行以下操作,我们将非常感激。我所拥有的问题是将“.circle”的宽度和高度更改为更小会影响其他东西的定位,迫使我改变.circle2的属性和.letter的属性,直到事情排成一行。

CSS

.circle {
    width: 100px;
    height: 100px;
    background: blue;
    -moz-border-radius: 50px;
    -webkit-border-radius: 50px;
    border-radius: 50px;
    cursor:pointer;
}

    .circle2 {
        width:80%;
        height:80%;
        border-radius: 50px;
        position:relative;
        top:5%;
        left:5%;
        border: 5px solid #FFF;
    }

letter{
    position:relative;
    top:45%;
    left:30%;
    margin:auto;
    cursor:pointer;
    color: #fff;
    font-size: 60px;
    font-weight: bold;
    display: inline-block;
    line-height: 0px;

}
letter:before {
     content: "A"
}

HTML

<div class="circle">
    <div class="circle2">
        <a class="letter"></a>
    </div>
</div>

1 个答案:

答案 0 :(得分:1)

看一看。唯一棘手的是“A”字体大小。您可以使用http://fittextjs.com/之类的库来完全实现此目的。

http://jsfiddle.net/cSBw3/1/

代码如下并修改。

CSS3

.container {
    width: 100px;
    height: 100px;
    text-align: center;
}

.circle {
    width: 100%;
    height: 100%;
    background: blue;
    cursor:pointer;
    position: relative;
    -moz-border-radius: 50%;
    -webkit-border-radius: 50%;
    border-radius: 50%;
}

.circle:after {
    content:"";
    display: block;
    position: absolute;
    /* width: 80%; height: 80%; */
    top: 10%; bottom: 10%;
    left: 10%; right: 10%;
    border: 5px solid #FFF;
    -moz-border-radius: 50%;
    -webkit-border-radius: 50%;
    border-radius: 50%;
}

.letter {
    cursor:pointer;
    display: block;
}
.letter:before {
    content: "A";
    display: block;
    position: absolute;
    bottom: 19%;
    right: 19%;
    font-size: 3em;
    font-weight: bold;
    color: #fff;
}

HTML

<div class="container">
    <div class="circle"> 
        <a class="letter"></a>
    </div>
</div>