How to insert spaces/tabs in text using HTML/CSS

后端 未结 18 2581
死守一世寂寞
死守一世寂寞 2020-11-28 01:20

Possible ways:

 ... 

or

style=\"white-space:pre\"

Anything else?

相关标签:
18条回答
  • 2020-11-28 02:12

    In cases wherein the width/height of the space is beyond   I usually use:

    For horizontal spacer:

    <span style="display:inline-block; width: YOURWIDTH;"></span>
    

    For vertical spacer:

    <span style="display:block; height: YOURHEIGHT;"></span>
    
    0 讨论(0)
  • 2020-11-28 02:12
    <p style="text-indent: 5em;">
    The first line of this paragraph will be indented about five characters, similar to a tabbed indent.
    </p>
    

    The first line of this paragraph will be indented about five characters, similar to a tabbed indent.

    See How to Use HTML and CSS to Create Tabs and Spacing for more information.

    0 讨论(0)
  • 2020-11-28 02:14

    I like to use this:

    In your CSS:

    .tab { 
           display:inline-block; 
           margin-left: 40px; 
    }
    

    In your HTML:

    <p>Some Text <span class="tab">Tabbed Text</span></p>
    
    0 讨论(0)
  • 2020-11-28 02:18

    Try &emsp;.

    As per the documentation at Special Characters:

    The character entities &ensp; and &emsp; denote an en space and an em space respectively, where an en space is half the point size and an em space is equal to the point size of the current font. For fixed pitch fonts, the user agent can treat the en space as being equivalent to A space character, and the em space as being equivalent to two space characters.

    0 讨论(0)
  • 2020-11-28 02:19

    Go a step further than @Ivar and style my own custom tag like so... For me 'tab' is easier to remember and type.

    tab {
        display: inline-block;
        margin-left: 40px;
    }
    

    And the HTML implementation...

    <p>Left side of the whitespace<tab>Right side of the whitespace</p>
    

    And my screenshot...

    0 讨论(0)
  • 2020-11-28 02:19

    This worked for me:

    In my CSS I have:

    tab0  { position:absolute;left:25px;  }
    tab1  { position:absolute;left:50px;  }
    tab2  { position:absolute;left:75px;  }
    tab3  { position:absolute;left:100px; }
    tab4  { position:absolute;left:125px; }
    tab5  { position:absolute;left:150px; }
    tab6  { position:absolute;left:175px; }
    tab7  { position:absolute;left:200px; }
    tab8  { position:absolute;left:225px; }
    tab9  { position:absolute;left:250px; }
    tab10 { position:absolute;left:275px; }
    

    Then in the HTML I just use my tabs:

    Dog Food <tab3> :$30
    Milk <tab3> :$3
    Pizza Kit <tab3> :$5
    Mt Dew <tab3> :$1.75
    
    0 讨论(0)
提交回复
热议问题