How to put borders around text? A bit of coding for you.

Discussion in 'HTML & Website Design' started by Li Weng, Dec 2, 2008.

  1. #1
    <table border=1><tr><td> text here </td></tr></table>



    <div style="border:1 solid #000000;background-color:#999999;margin:10px;padding:10px;">
    text here
    </div>




    <center>
    <table width="50%" border="5" bordercolorlight="#cc6633" bordercolordark="#cc0000"
    cellspacing="9" cellpadding="3">
    <tr align="middle">
    <td>
    <font size="5" color="#990000">
    text here
    </font>
    </td>
    </tr>
    </table>
    </center>




    Large Red Dashed Border Code
    <table width="357" height="267" align="center" style='border: 8px dashed red;'>
    <tr>
    <td align="center" valign="top"><div align="center">
    text here
    </div></td>
    </tr>
    </table>
    <div align="center">


    <div style="width:400px;text-align:left;padding:5px;background-color:#ffffc1;border:2px dotted black;font-size:12px;">text here</div>
    <p>&nbsp;</p>
    <p><br />


    <div style="border:1px solid gold;padding:10px;">
    <p>text here</p>
    </div>

    6 different options by the way.
     
    Li Weng, Dec 2, 2008 IP
  2. hdude1734

    hdude1734 Peon

    Messages:
    82
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Good information, I am sure the web-n00bs will appreciate this thread.
     
    hdude1734, Dec 2, 2008 IP
  3. yawez.com

    yawez.com Peon

    Messages:
    187
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hey that's awesome! Thanks for sharing the information.
     
    yawez.com, Dec 2, 2008 IP
  4. elias_sorensen

    elias_sorensen Well-Known Member

    Messages:
    852
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    110
    #4
    Lol... The elements you use are block elements, so it will put a break before and after the element, you cannot use it if you only want some of the text in a sentence to have a border around it.

    Like:
    "Lorem ipsum dolor sit amet".
    With your methods, you can't e.g. have a border around "dolor sit", because it will be parsed as:
    "Lorem ipsum
    dolor sit
    amet"

    Because of the breaks (divs and tables are block elements. It can not be but on the side of other content. Only with float:left/right, but you wouldn't do that).

    The ONLY way to do this a proper way, is to use an inline element. The different between inline elements and block elements, is that inline's won't break the page.
    You can of course use display:inline, but the EASIEST way, is to put the bordered text inside a <span> element.


    Like:
    
    <style type="text/css">
    .border {
    /* Your border style. e.g. */
    border: 1px dotted red;
    padding: 3;
    }
    </style>
    Lorem ipsum <span class="border">dolor sit</span> amet.
    
    HTML:

    My code will create an output like:

    [​IMG]

    Li Weng's code will output:
    [​IMG]
     
    elias_sorensen, Dec 2, 2008 IP
    chikarin likes this.
  5. Li Weng

    Li Weng Peon

    Messages:
    361
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Hey good information. Thanks!
     
    Li Weng, Dec 3, 2008 IP
  6. fragin_bastich

    fragin_bastich Guest

    Messages:
    65
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Nice clarification, let me add

    Inline element for placing a border around a single line of text...

    block level element <div> for bordering a block of text/etc such as the large red dashed table or box used above (just avoid the table though)
     
    fragin_bastich, Dec 3, 2008 IP