473,786 Members | 2,380 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

HaLo2FrEeEk
404 Contributor
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 2545
Death Slaught
1,137 Top Contributor
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 Recognized Expert Expert
If you don't mind declaring HTML5, putting a block element inside an anchor is allowed.
Oct 26 '10 #3
HaLo2FrEeEk
404 Contributor
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 Top Contributor
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 Recognized Expert Expert
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 Top Contributor
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 Recognized Expert Top Contributor
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
4710
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 Object. And every time I click the button first I put : dialog = null dialog = new dialog() What is purpose to put dialog = null when all its objects are stay non-null?
7
4686
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: block for the link adds a bit of whitespace between the list items. NS7.1 does not do this. Why the whitespace (about 5px)? Is it possible to get IE and NS looking
6
1516
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 exist in Opera. Only in Mozilla and IE?? Does anybody know how I can remove the extra space between the images???
5
1517
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 contents some number of pixels to the right. Other than putting a blank <script> block into each web page, or putting SCRIPT at the bottom of the BODY, any other way to work around this? Thanks
6
3314
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 explain, I can highlight any text on an HTML page by dragging, but if I just click I get no ibeam cursor (obviously because I am not supposed to be able to edit). Is there anyway to get one to sit there and blink where-ever I click on the page. Thanks...
18
2171
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
1527
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
2695
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 line hight for a column. For example, if i fed the script an an essay, it would format the text like a newspaper on the screen. Text processing is very new to me, any ideas on how I could achieve a multi-columned text formatter. Are there any...
1
2498
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, but with the default publishing to the Event Log. We have an error handler Intranet_Exception_Processing.Vb in the app's Component folder with the ExceptionManager.Publish(ex) call. Here is the code generating the error: ExceptionManager.VB...
0
9492
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10360
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10163
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10108
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9960
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8988
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6744
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4064
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.