简体   繁体   中英

Is it possible to redefine white-space css property in child elements?

I use such html layout to render paragraph and list in one line:

<div style="white-space: nowrap;">
    <p><img src="somesrc" /></p>
    <ul>
       <li>message message message message message.</li>
       <li>message.</li>
       <li>message.</li>
    </ul></div>

But white-space: nowrap is applied to text inside li-elements. Is it possible to redefine white-space property in li-elements?

Of course you can set white-space: normal for them.

But I'd suggest you to use css:

.block{
    white-space: nowrap;
}
.block li{
    white-space: normal;
}

Also you can use the simpler note:

.block p{
    white-space: nowrap;
}

Note that in my example you should add class block to your root div.

white-space: normal|nowrap|pre|pre-line|pre-wrap|initial|inherit;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM