CSS: white-space: nowrap does not seems to work in IE

前端 未结 2 767
长情又很酷
长情又很酷 2020-12-18 21:52

Here is the jsfiddle of the below code. http://jsfiddle.net/ux4DD/. What I want is the name Harry Pham to be in one line, so I make the width very

相关标签:
2条回答
  • 2020-12-18 22:26

    For IE 6 and 7 you need to wrap your text with a <span> tag and give it a white-space property. Since you already have a <span> tag wrapped around your text and you have a class for it, just add the white-space property to your <span> class .linkColor.

    .linkColor{
        white-space:nowrap;
    }
    

    Check working example at http://jsfiddle.net/ux4DD/1/

    0 讨论(0)
  • 2020-12-18 22:35

    Hope this will be helpful:

    var buttons = document.getElementsByTagName('button');
     for(var j=0; j < buttons.length; j++) {
     var button = buttons[j];
     var textNode = button;
     while(textNode.children[0]) {
     textNode = textNode.children[0];
     }
     var text, words, numSplits;
     var spacing = 0;
            while(button.scrollWidth !== 0 && button.clientWidth !== 0 &&
                  button.scrollWidth > button.clientWidth) {
        if(!spacing) {
            text = textNode.innerHTML;
            words = text.split(' ');
            numSplits = Math.ceil(button.scrollWidth / button.clientWidth);
            spacing = Math.round((words.length)/numSplits);
        }
        for(var i = spacing; i < words.length; i+=spacing+1) {
            words.splice(i , 0, '<br />');
        }          
        textNode.innerHTML = words.join(' ');
        spacing--;
        words = text.split(' ');
    }
    }
    

    Ref: Word wrapping for button with specified width in ie7?

    0 讨论(0)
提交回复
热议问题