How to absolutely position the baseline of text in HTML

后端 未结 4 1886
别跟我提以往
别跟我提以往 2021-01-17 19:23

I\'m puzzled by the following problem. I wish to (absolutely) position the baseline of some piece of HTML text at a certain y-coordinate, while the text should be starting a

4条回答
  •  时光说笑
    2021-01-17 20:10

    Try this :

    HTML :

    css=powerful

    CSS :

        BODY
    {
        position: absolute;
        margin: 0px;
    }
    #text
    {
        position: relative;
        margin-top:-0.938em;
        left:0px;
        font-family: helvetica, arial;
        font-size: 80px;
    
        /*You can remove this*/
        background: yellow;
        opacity: 0.5;
    
    }
    #text-holder
    {
        position: absolute;
        height: 200px;
        left: 200px;
    }
    
    #text-holder-position {
        position: relative;
        height: 200px;
        width: 200px;
        background: green;
    }
    
    #heightJudger {
        position:absolute;
        height:200px; width:200px;
        background:red;
        top:0; left:0;
    }
    

    if you want to change the position, change the "height" and the "left" parameters of the #text-holder This way you will be able to control your basepoint position. I put the height judger and some color so you can see if it's what you exepct.

    EDIT : Changed the #text margin unit to em. JSFiddle

提交回复
热议问题