Is necessary to show an empty
?

后端 未结 7 1699
天涯浪人
天涯浪人 2021-01-17 10:25

I\'d like to show a div that has a background-color with the height and width set to 100% but no content. Is it possible to do that without putting a   inside?

7条回答
  •  囚心锁ツ
    2021-01-17 10:51

    IMHO you should include the nbsp for otherwise empty DIVs if you want them to actually render into something.

    On a "theoretical" note .. the browser is not supposed to show anything if there is no content. The entire point of nbsp is to indicate empty space. This is both common sense and (I believe) the standard.

    On a practical side .. are you have three choices. One is to leave nbsp off, knowing that you will get unpredictable results. This is likely the easiest to code. Another is to always include nbsp, either by always putting nbsp at the end of the div or testing for empty and adding nbsp if it is empty. The third it to test for the browser and insert nbsp when needed.

提交回复
热议问题