What elements allow link?
I want to wrap a link around a table,
<a href="123.php" class="grap" >
<table border="1" style="width:600px; height:600px;">
<tbody>
<tr>
<td align="center" style="border:1px solid red"><img src="thumb-pic-1.jpg" alt="123"/></td>
</tr>
</tbody>
</table>
</a>
But it is not a correct html as in http://validator.w3.org/
I can put the link in a form like this,
<form action="123.php" class="grap" >
<table border="1" style="width:600px; height:600px;">
<tbody>
<tr>
<td align="center" style="border:1px solid red"><img src="thumb-pic-1.jpg" alt="123"/></td>
</tr>
</tbody>
</table>
</form>
But the link or the table is not meant to be a form form submission...
I wonder if there are anyway to wrap a table in a link?
EDIT:
Sorry forgot the mention that I need to grab the link url like this,
$('.grap').click(function(){
alert($(this).attr('action'));
return false;
});
<a> is an Inline-Element and <table> is a block element. Block elements are not allowed in inline elements in xhtml. But what about a click listener on the table, or an div around the table? The effect should be the same.
This might be also interesting for you:
Is it wrong to change a block element to inline with CSS if it contains another block element?
Browsers let you wrap a table inside a link. The practical problems with it relate to rendering (browsers may or may not underline the text content and draw borders around images inside a link), not with basic functionality. It’s not valid as per HTML 4.01 for example, but so what?
In your example, the table contains just one cell that contains just one image. You could instead use just an img element and style it suitably. In a more complicated case, a table might be useful. Then you should probably set color and text-decoration for it in CSS and border for any img contained in it, so that you get the rendering you prefer and not the varying browser default rendering for a situation like this.
You can not wrap a block level element (such as a table) in an inline element (such as an anchor). You could, however, use display: block; to make the anchor block level.
You could also use Javascript event handlers to link the table. For instance, you could have this snippet of code in your head tag that assigns an onclick event to the table.
Where, idOfYourSpecifiedTable is the id attribute of your table (ie <table id='idOfYourSpecifiedTable'>),
<script type="text/javascript">
document.getElementById('idOfYourSpecifiedTable').onclick = function() {window.location.href='123.php'};
</script>
or in jQuery
<script type="text/javascript">
$(function() {
$('#idOfYourSpecifiedTable').click(function() {window.location.href='123.php';});
});
</script>
Furthermore, you could even use #idOfYourSpecifiedTable {cursor: pointer;} to make the cursor a pointer (hand) when a client hovers over it.
However, this method has its weaknesses. Notably, a search engine robot will likely not detect your table as linked to another page of your site.
Related
I have code like this
<tr>
<td>
<img id="one" src="abc.jpg">
</td>
<td>
<img id="two" src="xyz.jpg">
</td>
<td>
<img id="three" src="def.jpg">
</td>
</tr>
Initially I want to display all the three images
But when I hover on image one image two and three should be hidden
how to do that?
Give your <tr> a class. Then hide the images when the row is hovered, but show the image that is being hovered:
.imgRow:hover img {
opacity: 0;
}
.imgRow:hover img:hover {
opacity: 1;
}
jsfiddle.net/J7wHq
Demo with a nice transition effect and some old IE support: jsfiddle.net/J7wHq/2
It is my understand that what you are trying to do is not possible with just CSS
http://jsfiddle.net/87zh6/
#id1:hover + #id2
{
//Whatever you put here will modify #id2 when #id1 is hovered.
}
However you can only modify the element directly following #id1. If #id2 is not the next element in code it will not work.
This is why in the jsfiddle i provided it will hide the second image but not the third.
I would suggest using a form of Javascript to accomplish the task.
As far as I know this isn't possible with just CSS. I recommend using jQuery. It is super easy to learn and it will really make your life easier. I suggest using the W3 Tutorials.
As for your problem, you'll need to give id's to each <td> element and use jQuery's .hover() method:
$("#one").hover(function() {
$("#two, #three").toggle();
});
That will hide/show images two and three when you move the mouse over image one. If you want to just hide the images (and not toggle) you can use:
$("#two, #three").hide();
Working JSFiddle: http://jsfiddle.net/7gUL4/
Yes use jquery:
<script src=" <!-- you can put jqueries code URL in hear go to code.jquery.com copy paste url --> ">
</script> <!-- that loads jquery's stuff -->
<script>
$("#one").hover(function(){
$("img').hide();
});
<!-- repeat for others -->
</script>
I have recently started to make some User Interfaces for Websites. What i am currently using something called Bootstrap, which is easy to start with and looks good. But the idea behind does not seem too efficient, since we are making our jsp code (the content) dependent on the css elements like this:
<tr class="row col-m-7">
<td class="column"> ...
<a class="btn btn-xs btn-success"> .. </a>
</td>
<td class="column"> ... </td>
</tr>
Recently the Bootstrap has introduced a newer version (v3), and i had to change many class attributes until the jsp gets a stable look. I would like to keep the code in separate layers for content and presentation like this, so i can easily switch my UI framework without loosing any content:
Content (simple html or jstl):
<tr>
<td>...
<td>...
</tr>
Presentation:
.. somehow achieving giving a good look to the table above .. (how ???)
How can i separate content and presentation layers on JSPs?
UPDATE
A new standard is being developed, called Web Components, which will enable developers to create custom html elements which hide the implementation of styling and inner html markup. For example, a modal widget could be declared by the following syntax:
<bootstrap-modal>
<h1>Hello World!</h1>
</bootstrap-modal>
Behind the scenes, the developer has specified the actual html markup used to render the widget, that implementation is tied to the custom component.
Here are a few tutorials to get you started:
http://www.html5rocks.com/en/tutorials/webcomponents/shadowdom/#toc-separation
http://css-tricks.com/modular-future-web-components/
https://hacks.mozilla.org/2013/08/introducing-brick-minimal-markup-web-components-for-faster-app-development/
If all <a> elements were to look the same, then you could write one css class and all <a> elements would have the same styling:
a {
color:blue;
}
Some websites, for whatever reason, possibly even concerning the value of the href attribute; will want different colors and styling for different <a> elements. The only way to achieve that is with the class attribute which refers to a css class from a stylesheet:
a.red {
color:red;
}
<a class="red" href="red.html"/>
This means that if you want unique styling for same element names, you will always need to write code which links together the presentation element and the styling.
I have a form within a table which is within another form. My problem is that the embedded form tag is not appearing - the input and iframe appears, but the form tags do not appear. The table and outer form appear. What's wrong?
<form>
<table id=\"mytableid\">
<tr class=\"form_row\">
<td align=\"right\">
Upload Photo:
</td>
<td align=\"left\">
<form action=\"/myuploadpath\" method=\"post\" enctype=\"multipart/form-data\" target=\"upload_target\" id=\"photo_url_upload_form\" name=\"venue_photo_url_upload_form\">
<input type=\"file\" name=\"photo_url\" id=\"photo_url\" size=\"40\" />
<iframe id=\"upload_target\" name=\"upload_target\" src=\"#\" style=\"width:0;height:0;border:0px solid #fff;\"></iframe>
</form>
</td>
</tr>
</table>
</form>
Putting a form inside another form is not valid HTML. When this happens each browser will do different things with the markup. Some ignore parts, some break, etc. Either way you shouldn't do this.
Edit
If you are using tables for layout purposes, you technically shouldn't be. They are only meant for tabular data. You should use divs/spans and CSS to create the look you want on your site. A great place to learn about this stuff is W3C Schools.
I assume you're using something like Firebug or the Chrome DOM Inspector to look at your DOM tree and you can't see the inner <form>. These tools inspect the DOM itself, not the HTML source. That is, they show you what the browser has interpreted from your HTML. The problem in this case is that nesting a <form> within another <form> is invalid, and hence the browser has ignored it and continued parsing the rest of the document.
Obviously, the fix is to ditch that outer form since it's not doing anything. If you have it there for styling purposes, perhaps use a <div> with a class.
I declared an iFrame in my html, and the source is my XQuery file. In my XQuery, I defined a <div>, within which I also declared a button named "convert".
My XQuery file basically looks like this (this is the source for the iFrame)
return
<div id="content">
<table>
....
<tbody>
{
...
<td>
<a id="{$t/#id}"
rel="nofollow"
target="_new"
name="{util:document-name($t)}:{util:node-id($t)}"
href=
"http://localhost:8080/exist/rest/db/motorola/xquery/toDita.xql?xml={
util:document-name($t)
}&xsl=mot2dita.xsl">
<input type="submit" value="convert"/>
</a>
</td>
...
}
</tbody>
</table>
</div>
As you can see, in a td, I declared a button called "convert", and the "href" gives the link. Right now this button works perfectly in Firefox and Chrome(opening a new window to do the task), but in IE, after clicking it, it just doesn't do anything.
I wonder if this is a browser issue or my XQuery script has problems. Thanks in advance for helping out.
<input> tags are not valid inside <a> tags. The XHTML code is therefore not valid, which will account for the inconsistent behaviour - some browsers are better at compensating for odd cases like this than others.
Recommend you remove the <input> entirely and use CSS to style your <a> tag to look like a button, if it's just the look of a button that you're after.
Unless you're inside a form, it's not going to submit anything...definitely not an A tag.
I prefer to do these with Jquery UI's button feature. It gets the desired behavior you're looking for, is progressively enhanced and tested to handle the full gamut of browsers, and can be done use a href links, button elements, or input type=submit elements. Plus, styling looks great and is instantaneous.
Here's a quick tut: http://www.filamentgroup.com/lab/styling_buttons_and_toolbars_with_the_jquery_ui_css_framework/
Is there a coding standard for HTML? Please suggest links that have the coding styles for HTML.
For example:
<table>
<tr>
<td>
Data
</td>
</tr>
</table>
Here's a few standards to add to your list.
1. Indentation
You seem to have the right idea on this already. The main purpose of indentation should be to make it clear where a tag is opened and closed. Consider this example.
<div><p>Hello World</p><div><p>Hello World</p></div>
This looks okay until you indent it properly and spot the error:
<div>
<p>Hello World</p>
<div>
<p>Hello World</p>
</div>
The original div wasn't closed. Ooops! This is why indentation can be a great time saver.
2. Tags and Attributes
It is generally accepted now that all tags and attributes should be lower case. We dispensed with ALL CAPS tags a long time ago in HTML and also with camelCasing for things like onMouseOver and onClick, which are now all lower case. All attribute values should be surrounded with double-quotes. For example:
<div id="content">Hello</div>
Not
<div id=content>Hello</div>
<DIV ID="content">Hello</DIV>
3. Semantic mark-up only
Don't use any tags to infer style or to control style. For example...
<font>
<b>
Or attributes like...
<table border="2">
Also, don't use things like h1 tags just to get a bigger font.
Try to think of what the tag means, "h1" is a top level heading, "p" is a paragraph, "table" denotes data laid out in a tabular format. Never use a tag for a different purpose to what is intended and try to know what tags are available. For example, using lists instead of manually laying out lists of things.
Don't use tables for layout. (I have emphasised this important point using the semantic "em" tag).
Don't use too many div tags to solve a problem! (div-itus!)
Firstly choose your doctype and then validate your html against the W3C validator for formatting errors
Other things to consider off the top of the head are
Proper indentation
Resisting the temptation to add too much markup i.e. keep the markup simple
Structure your html semantically so that if you switched off style sheets the document would still make sense and be in the right order
Avoid deprecated tags e.g. <font>
Choosing generic class names e.g. mainHeader instead of largeRedHeader
Use classes for repeating elements and ids for elements that appear once
Use classes and ids on parent elements only and style child elements using css e.g. #intro > p instead of #intro .paragraph
HTML Tidy provides a pretty reasoble style, which it will also help you enforce.
Did you mean indentation style? Here is the de facto indentation style:
<table>
<tr>
<td>One line of text - no indent.</td>
<td>
<p>
Multiple lines of text. <br />
With line breaks - indent.<br />
Inline: <b>no indent</b>
</p>
</td>
</tr>
</table>
However, the style above takes too much spaces, for some indentation styles, HTML, HEAD and BODY are not indented.
<html>
<head>
<title>Title</title>
</head>
<body>
<div>
<h1>Title</h1>
<p>Hello, world! The content begins here.</p>
</div>
</body>
</html>
Personally I follow the xhtml standards (all open tags get a closed tag, case sensitivity and so on). It makes it easier to follow the code and to format things automatically. I also generally indent everything 1 from their parents:
<table summary="example table">
<tr>
<td>
Data
</td>
</tr>
</table>
I also tend to try and include all of the required attributes for accessibility, I figure it is a nice thing to do.