Is there a vr (vertical rule) in html?

后端 未结 28 2160
花落未央
花落未央 2020-12-02 11:37

I know there is a hr (horizontal rule) in html, but I don\'t believe there is a vr (vertical rule). Am I wrong and if not, why isn\'t there a vertical rule?

28条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-02 12:09

    HTML5 custom elements (or pure CSS)

    1. javascript

    Register your element.

    var vr = document.registerElement('v-r'); // vertical rule please, yes!
    

    *The - is mandatory in all custom elements.

    2. css

    v-r {
        height: 100%;
        width: 1px;
        border-left: 1px solid gray;
        /*display: inline-block;*/    
        /*margin: 0 auto;*/
    }
    

    *You might need to fiddle a bit with display:inline-block|inline because inline won't expand to containing element's height. Use the margin to center the line within a container.

    3. instantiate

    js: document.body.appendChild(new vr());
    or
    HTML: 
    

    *Unfortunately you can't create custom self-closing tags.

    usage

     

    THISWORKS

    example: http://html5.qry.me/vertical-rule


    Don't want to mess with javascript?

    Simply apply this CSS class to your designated element.

    css

    .vr {
        height: 100%;
        width: 1px;
        border-left: 1px solid gray;
        /*display: inline-block;*/    
        /*margin: 0 auto;*/
    }
    

    *See notes above.

    link to original answer on SO.

提交回复
热议问题