CSS circles without width or height? : Is this possible with pure CSS or not?

后端 未结 4 1390
清酒与你
清酒与你 2021-01-02 02:48

I can turn a div into a circle like this:

.circle {
 background-color: rgba(0, 0139, 0139, 0.5);
 height: 200px;
 width: 200px;
 -moz-border-radius:50%;
 -we         


        
4条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-02 03:17

    EDIT: I mistook your question. You'll need Javascript to assign the hight width to the highest value, as well as make sure your content is centered.

    Here's how in this JSFiddle: http://jsfiddle.net/rgthree/K4Kpw/

    This is a line This is yet another line! Last Line!

    CSS:

    .circle {
        position:relative;
        background-color: rgba(0, 0139, 0139, 0.5);
        padding:10px;
        -moz-border-radius:50%;
        -webkit-border-radius: 50%;
        border-radius:50%;
    }
    .circle > div{
        position:absolute;
        top:50%;
        left:50%;
    }
    

    JQuery:

    $('.circle > div').each(function(){
        var h, w, max;
        w = $(this).width();
        h = $(this).height();
        max = w > h ? w : h;
        $(this).css('margin-left', -parseInt(w/2,10));
        $(this).css('margin-top', -parseInt(h/2,10));
        $(this).parent().width(max);
        $(this).parent().height(max);
    });​
    

提交回复
热议问题