2

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 an empty DIV occupies 300px width?

Crescent Fresh
  • 115,249
  • 25
  • 154
  • 140
Bin Chen
  • 61,507
  • 53
  • 142
  • 183
  • 1
    discussed already :http://stackoverflow.com/questions/4171286/how-to-make-a-div-no-content-also-have-a-width/4171384#4171384 – ArK Nov 29 '10 at 07:27
  • Is it possible that you want an empty DIV to occupy 300px? Probably, otherwise you wouldn't have asked :P – aefxx Nov 29 '10 at 07:27

3 Answers3

3

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.

prodigitalson
  • 60,050
  • 10
  • 100
  • 114
2

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.

Community
  • 1
  • 1
Sarfraz
  • 377,238
  • 77
  • 533
  • 578
0

height must be specified in order to make it visible.

Jogendra
  • 111
  • 4