Word-wrap in an HTML table

后端 未结 25 3016
温柔的废话
温柔的废话 2020-11-22 02:45

I\'ve been using word-wrap: break-word to wrap text in divs and spans. However, it doesn\'t seem to work in table cells. I have a tabl

25条回答
  •  醉酒成梦
    2020-11-22 03:19

    I found a solution that seems to work in Firefox, Google Chrome and Internet Explorer 7-9. For doing a two-column table layout with long text on the one side. I searched all over for similar problem, and what worked in one browser broke the other, or adding more tags to a table just seems like bad coding.

    I did NOT use a table for this. DL DT DD to the rescue. At least for fixing a two-column layout, that is basically a glossary/dictionary/word-meaning setup.

    And some generic styling.

        dl {
            margin-bottom:50px;
        }
    
        dl dt {
            background:#ccc;
            color:#fff;
            float:left;
            font-weight:bold;
            margin-right:10px;
            padding:5px;
            width:100px;
        }
    
        dl dd {
            margin:2px 0;
            padding:5px 0;
            word-wrap:break-word;
            margin-left:120px;
        }
    test1
    Fusce ultricies mi nec orci tempor sit amet
    test2
    Fusce ultricies
    longest
    Loremipsumdolorsitametconsecteturadipingemipsumdolorsitametconsecteturaelit.Nulla laoreet ante et turpis vulputate condimentum. In in elit nisl. Fusce ultricies mi nec orci tempor sit amet luctus dui convallis. Fusce viverra rutrum ipsum, in sagittis eros elementum eget. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per.

    Using floating word-wrap and margin left, I got exactly what I needed. Just thought I'd share this with others, maybe it will help someone else with a two-column definition style layout, with trouble getting the words to wrap.

    I tried using word-wrap in the table cell, but it only worked in Internet Explorer 9, (and Firefox and Google Chrome of course) mainly trying to fix the broken Internet Explorer browser here.

提交回复
热议问题