开发者

Why div can't occupy the desired width space?

开发者 https://www.devze.com 2023-01-27 14:42 出处:网络
I found if I specify div with only width CSS attribute, the div will not occupy the width I claimed, see:

I found if I specify div with only width CSS attribute, the div will not occupy the width I claimed, see:

                <div style="width: 300px;">    
                </div>

It will never occupy 300px space.

Is it possible that I want开发者_C百科 an empty DIV occupies 300px width?


You either need to add content or set a height. Otherwise an empty div will not appear because its height is determined by its contents.


See Example


You need to specify something or a space to achieve that:

<div style="width:300px; border:1px solid black;">&nbsp;</div>

The border was given to show width but you can remove it.


height must be specified in order to make it visible.

0

精彩评论

暂无评论...
验证码 换一张
取 消