473,395 Members | 1,473 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Default Height value for empty <span> & <div> tags

6
Hi,

I would like to ask about the default value of Height for an empty <span> or <div> tag.

from this code:

CSS:
Expand|Select|Wrap|Line Numbers
  1. div.baselineRule{ background: url(SHipuha.jpg) repeat-x scroll left bottom transparent; display:inline-block; }
  2.  
HTML:
Expand|Select|Wrap|Line Numbers
  1. <div class="baselineRule" style="width:70px"></div>
  2.  

for the code above,I understand that the image wont be displayed if I don't add:
1. a height value for the CSS. like height="1px"
2. add a content on the div. <div>aaaaa</div>

Is the default height for <DIV> and <SPAN> really 0px?

I just want a clear explanation, about why you should set either of the solutions above for this to work.

Is there a W3C rule or something that would explain why this is happening? Could you please provide me a link?

Any help is greatly appreciated.

Thanks!
Nov 23 '11 #1

✓ answered by drhowarddrfine

Div and span elements are for structure and not presentation. They don't have any height or width by default for that reason and will collapse to zero with no content unless you set the height or width.

3 13337
drhowarddrfine
7,435 Expert 4TB
Div and span elements are for structure and not presentation. They don't have any height or width by default for that reason and will collapse to zero with no content unless you set the height or width.
Nov 23 '11 #2
aredz
6
Thank you so much for the provided link and explanation Mr. drhowarddrfine. I really appreciate it :)
Nov 23 '11 #3
The answer is not correct. The empty div can have height and width if you set. If not set, the width would be the width of its parent, and the height would be zero. For details, you can refer to https://myprogrammingnotes.com/defau...y-div-css.html
Oct 23 '18 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Philo | last post by:
How do I select all <div> tags except those which contain a <table> tag somewhere within them? Example XML: <********************** sample input ***********************> <txtSectionBody>...
23
by: Mikko Ohtamaa | last post by:
From XML specification: The representation of an empty element is either a start-tag immediately followed by an end-tag, or an empty-element tag. (This means that <foo></foo> is equal to...
129
by: Torbjørn Pettersen | last post by:
I've started cleaning up my HTML and implementing CSS. So far I've used FrontPage, but am switching over to DreamWeaver. Reading a bit on W3Schools.com and W3.org I see there are a lot of HTML...
8
by: slim | last post by:
hi again all, i am still working on the website as mentioned in earlier threads and have hit another snag... http://awash.demon.co.uk/index.php http://awash.demon.co.uk/vd.css the php is...
18
by: Timothy Casey | last post by:
Thanks in advance... =~= Timothy Casey South Australia worloq@iprimus.com.au Formerly: casey@smart.net.au
5
by: hibernate | last post by:
I'm somewhat new to javascript/DHTML, and this problem has been plaguing me. I have made an 'array' of <div> tags within my html document like so: <div id="menu"> menu1 </div> <div id="menu">...
2
by: Don Wash | last post by:
Hi There! I'm creating my website with ASP.NET + XHTML, which means I will strictly adhere the XHTML standards for my web page output. I use Panel or PlaceHolder WebControls to place...
6
by: lilOlMe | last post by:
Hi there! I'm having a problem with a <span> element's width. I have a span element within a div block: <div class="picker"> <span id="ctl00_cph_mainContent_TPKR_Tues_LBL_TitleForPicker"...
5
by: Brent | last post by:
Take this small HTML fragment: span.theClass{float:left;width:100px;cursor:pointer;cursor:hand;} ------------------------ <div> <span id="1" class="theClass">&nbsp;<span> <span id="2"...
1
by: Chinsu | last post by:
<html> <head> <style> #ex { width: 700px; background: red; float: left; } a, span { display: block;
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.