473,383 Members | 1,834 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,383 software developers and data experts.

putting a block-level element inside an inline element (<div> inside <a>)

HaLo2FrEeEk
404 256MB
I'm trying to use the W3C Markup Validator to validate my HTML and I'm getting some errors:

Expand|Select|Wrap|Line Numbers
  1. document type does not allow element "div" here; missing one of "button", "map", "object", "ins", "del", "noscript" start-tag 
  2. …   <li ><a href="/" title=""><div>Home</div></a></li>
Apparently I'm not allowed to put a block-level element, like div or table, inside an inline element, like span, or a. I tried moving the div tags to the outside of the link tag, but then it breaks my navigation links. It's supposed to look like this:



When I move the div outside the link tag it looks like this:



What can I do to fix this? I want the site to validate, but I want it to look good too.
Oct 26 '10 #1
7 2521
Death Slaught
1,137 1GB
Change the div to a span and give it all of the stylings you gave the div. Make sure to give it a set width and height and then add the style

Expand|Select|Wrap|Line Numbers
  1. display: block;

Thanks, Death
Oct 26 '10 #2
drhowarddrfine
7,435 Expert 4TB
If you don't mind declaring HTML5, putting a block element inside an anchor is allowed.
Oct 26 '10 #3
HaLo2FrEeEk
404 256MB
I'd rather not declare HTML5, I think I'll do Death's suggestions, I just didn't think a span would work for this since a span is also an inline element. I didn't think I could set things like width and height.
Oct 27 '10 #4
Death Slaught
1,137 1GB
You can give just about anything a width and height through CSS. Adding display: block is the trick. It makes the span display like a block element even though it's an inline element.


Regards, Death
Oct 27 '10 #5
drhowarddrfine
7,435 Expert 4TB
The difference is one of semantics more than anything else. span and div are both generic containers but span is considered inline while div is considered block level.

You can, however, declare the span inline-block where you can set the height/width but I've lost track of the problem here.
Oct 27 '10 #6
Death Slaught
1,137 1GB
He's wanting his navigation menu to appear the same without using a div inside of his anchors/list, so the validator won't fuss.
Oct 27 '10 #7
JKing
1,206 Expert 1GB
What is it you are setting in the div that you can't set on the a tag itself?
Oct 27 '10 #8

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

Similar topics

4
by: Dado | last post by:
I lost the point: What is purpose of putting objects to null: If I make a class, JFrame for example, with button which start connection dialog, which is class with connection and statement...
7
by: Jeff Thies | last post by:
I'm trying to do a nav list using list items. Roughly this is putting links styled display: block and with a background color. In IE5 (windows, haven't tried Mac yet), adding the display:...
6
by: Banaan666 | last post by:
Hi, I hope somebody can help me. Please look at the following page to see what's it about. http://www.tilburg.nl/development/_moz-ul-li-img-margin-problem.htm The problem doesn't seem to...
5
by: Steve | last post by:
I just noticed, in IE6, when navagating from one page to another with the same basic layout (centered top graphic, for example), that a page with a <script> block in the <head> shifts the HTML...
6
by: dedejavu | last post by:
Hi all you JS experts, Is there any way to put a blinking ibeam cursor in middle of td text - the same way it would blink if I clicked in the middle of the text in a text input? To further...
18
by: John Salerno | last post by:
I'm still tyring to figure out what "Pythonic" means, and I have a feeling the answer to my question may fall into that category. Are block comments somehow unpythonic?
9
by: Menny | last post by:
Hi, I'm looking for a way to determine if the 'Dispose()' function at the end of a 'using' block, was called due to an exception. Can anyone help?
7
by: Leon | last post by:
Hi, I'm creating a python script that can take a string and print it to the screen as a simple multi-columned block of mono-spaced, unhyphenated text based on a specified character width and...
1
by: =?Utf-8?B?QnJldHQgT3NzbWFu?= | last post by:
I'm trying to set up a custome e-mail publisher for a web app using the Microsoft Exception Management Application Block for .NET sample app. Our app already uses the Exception Management Block,...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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...

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.