Here is a code snippet from my page:
<input value="Search" type="submit" /><!-- whitespace
--><span class="vdivider"></span><!-- whitespace
--></form><!-- whitespace
--><form action="login_action.php" method="post"><!-- whitespace
--><?php
Those whitespace comments are to get rid of the whitespace on each side of the divider. Is this really the only way of doing this? There has to be a more elegant solution.
One option to consider - use a templating engine if you can. For example, in Smarty, there's a {strip} function that does exactly this:
{* the following will be all run into one line upon output *}
{strip}
<table border='0'>
<tr>
<td>
<a href="{$url}">
<font color="red">This is a test</font>
</a>
</td>
</tr>
</table>
{/strip}
Output:
<table border='0'><tr><td><a href="http://. snipped...</a></td></tr></table>
You can use the font-size:0 hack. Basically, you set font-size:0 on the parent element, and set the font-size explicitly on the children.
Live demo: http://jsfiddle.net/simevidas/mLZYW/1/
(Presentation without hack: http://jsfiddle.net/simevidas/mLZYW/)
White-space only shows when it is around or next to inline elements, so at least for the forms you don´t need it (if you haven´t set your forms to display:inline...).
Positioning or floating things almost always removes the unwanted white-spaces, so for example if your .vdivider is supposed to be a vertical divider / new line, you can just use display:block on the input before it and remove that element and the comments around it.
Whitespace between elements (including newlines and tabs) cause browsers to insert spaces where there should be none.
The most elegant method that I've seen used to get around this issue is putting the > on the next line, instead of on the same line. This way, it's still legal html, and you can still keep it pretty.
For example:
<input value="Search" type="submit" />
<span class="vdivider"></span>
</form><form action="login_action.php" method="post">
<?php>
would become:
<input value="Search" type="submit"
/><span class="vdivider"></span
></form><form action="login_action.php" method="post"
><?php>
Related
I want to keep the field and the icon (question mark) at the same line at any time, even if the width is reduced. (preferably using CSS)
I tried various options such as white-space: nowrap, putting them in the same <div/>, but no success.
EDIT
My HTML markup is similar to the following:
<ul data-role="listview" >
<li data-role="fieldcontain">
<div>
<label for="name">*Email</label>
<input type="text" name="name" id="name" />
<img src="help.png" title="title" alt="help"/>
</div>
</li>
</ul>
I am using HTML5 with jQuery Mobile.
white-space: nowrap has no effect on elements, it just tells the browser not to split plain text nodes.
To achieve what you want, you need to make the div wrapping everything wide enough to display everything in a single line. In the general case, this isn't simple to achieve without JavaScript because CSS has only rudimentary support for aligning several elements.
Solutions:
Make the div so wide that it will always be able to contain the three elements. This is hard because of the label and impossible if you want the input field to grow (= use all available space).
Give the div a right margin which is wide enough to contain the image and then position it absolutely in the empty space. Drawback: It will be hard to align the image vertically.
The solution that works perfectly but no one wants to hear: Use a table because table rows do what you want / need.
You could try several things actually. The most ugly version is the table. Its also the most easiest one.
it would look something like this.
<table>
<tr>
<td><label for="name">*Email</label></td>
<td><input type="text" name="name" id="name" /></td>
<td><img src="help.png" title="title" alt="help"/></td>
</tr>
</table>
Also you could try using the propperty inline-block in your css in the questionmark style propperties. It forces the questionmark to stay on the same line as previous element.
display: inline-block;
hope this helps you.
This isn't pretty, but what happens when you use a non-breaking space?
<input type="text" name="name" id="name"
/> <img src="help.png" title="title" alt="help"/>
Note that I moved the closing bracket to the next line to try to keep some sort of order to the code. Pretty ugly still though.
The benefit is that it is "semantic" in that you're instructing the browser that those two pieces of inline content belong together.
$<input id="" name="" value="V" type="radio"><img id="" src=".../image.gif" alt="" border="0"><input id="" name="" value="V" type="radio"><img id="" src=".../image.gif" alt="" border="0"><input id="" name="" value="V" type="radio"><img id="" src=".../image.gif" alt="" border="0">
$<div class="wrapper">
As you see here i have like 3 lines or more in a php file and when i open it with any browser it shows me 2 on the same line and the last one under'em so how to keep these three pics on the same line .. is this have a relation with the page size ? if bigger it will show them on the same line ? is this true ?
Thanks for reply :)
Apologies in advance if I'm misinterpreting what you're asking, but if you want to display the three images in one line, you can use CSS. In each of your image tags, you can add inline styling by adding the "style" attribute:
<img id="" src=".../image.gif" alt="" style="display: inline; border-width: 0px;" />
If you have text-level (inline) content like input elements, img elements, and text in HTML source, they will appear in the same line if the available width permits that and there is nothing that causes a line break (such as <br>).
For usability and accessibility, there should normally be one input item (an input element and associated label) on one line. This is best achieved using HTML tags that cause such rendering, such as wrapping the item in a div element.
But if you wish to put the content on one line, you can wrap it all inside a div element and set white-space: nowrap on it in CSS (or, somewhat more effectively, wrap it all inside the nonstandard but well-supported nobr element). This may then force horizontal scrollbars, if the content does not fit into the available width.
I'm just wondering what are you thinking about DIV-tag inside FORM-tag?
I need something like this:
<form>
<input type="text"/>
<div> some </div>
<div> another </div>
<input type="text" />
</form>
Is it general practice to use DIV inside FORM or I need something different?
It is totally fine .
The form will submit only its input type controls ( *also Textarea , Select , etc...).
You have nothing to worry about a div within a form.
It is completely acceptable to use a DIV inside a <form> tag.
If you look at the default CSS 2.1 stylesheet, div and p are both in the display: block category. Then looking at the HTML 4.01 specification for the form element, they include not only <p> tags, but <table> tags, so of course <div> would meet the same criteria. There is also a <legend> tag inside the form in the documentation.
For instance, the following passes HTML4 validation in strict mode:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Test</title>
</head>
<body>
<form id="test" action="test.php">
<div>
Test: <input name="blah" value="test" type="text">
</div>
</form>
</body>
</html>
You can use a <div> within a form - there is no problem there .... BUT if you are going to use the <div> as the label for the input dont ... label is a far better option :
<label for="myInput">My Label</label>
<input type="textbox" name="MyInput" value="" />
It is wrong to have <input> as a direct child of a <form>
And by the way <input /> may fail on some doctype
Check it with http://validator.w3.org/check
document type does not allow element "INPUT" here; missing one of "P", "H1", "H2", "H3", "H4", "H5", "H6", "PRE", "DIV", "ADDRESS" start-tag
<input type="text" />
The mentioned element is not allowed to appear in the context in which you've placed it; the other mentioned elements are the only ones that are both allowed there and can contain the element mentioned. This might mean that you need a containing element, or possibly that you've forgotten to close a previous element.
One possible cause for this message is that you have attempted to put a block-level element (such as "<p>" or "<table>") inside an inline element (such as "<a>", "<span>", or "<font>").
Your question doesn't address what you want to put in the DIV tags, which is probably why you've received some incomplete/wrong answers. The truth is that you can, as Royi said, put DIV tags inside of your forms. You don't want to do this for labels, for instance, but if you have a form with a bunch of checkboxes that you want to lay out into three columns, then by all means, use DIV tags (or SPAN, HEADER, etc.) to accomplish the look and feel you're trying to achieve.
Definition and Usage
The tag defines a division or a section in an HTML document.
The tag is used to group block-elements to format them with
styles.
http://www.w3schools.com/tags/tag_div.asp
Also DIV - MDN
The HTML element (or HTML Document Division Element) is the
generic container for flow content, which does not inherently
represent anything. It can be used to group elements for styling
purposes (using the class or id attributes), or because they share
attribute values, such as lang. It should be used only when no other
semantic element (such as or ) is appropriate.
You can use div inside form, if you are talking about using div instead of table, then google about Tableless web design
As the others have said, it's all good, you can do it just fine. For me personally, I try to keep a form of hierarchical structure with my elements with a div being the outer most parent element. I try to use only table p ul and span inside forms. Just makes it easier for me to keep track of parent/children relationships inside my webpages.
I noticed that whenever I would start the form tag inside a div the subsequent div siblings would not be part of the form when I inspect (chrome inspect) henceforth my form would never submit.
<div>
<form>
<input name='1st input'/>
</div>
<div>
<input name='2nd input'/>
</div>
<input type='submit'/>
</form>
I figured that if I put the form tag outside the DIVs it worked. The form tag should be placed at the start of the parent DIV. Like shown below.
<form>
<div>
<input name='1st input'/>
</div>
<div>
<input name='2nd input'/>
</div>
<input type='submit'/>
</form>
Absolutely not! It will render, but it will not validate. Use a label.
It is not correct. It is not accessible. You see it on some websites because some developers are just lazy. When I am hiring developers, this is one of the first things I check for in candidates work. Forms are nasty, but take the time and learn to do them properly
No, its not
<div> tags are always abused to create a web layout. Its symbolic purpose is to divide a section/portion in the page so that separate style can be added or applied to it. [w3schools Doc] [W3C]
It highly depends on what your some and another has.
HTML5, has more logical meaning tags, instead of having plain layout tags. The section, header, nav, aside everything have their own semantic meaning to it. And are used against <div>
This is PURE HTML. (no php or anything like that, if you want to know the background its a C# application with HTML in a web view).
All my HTML files are nicely formatted and correctly indented for maintainability and such.
Here is an excerpt:
<tr>
<td class="label">Clinic Times:</td>
<td><textarea name="familyPlanningClinicSessionsClinicTimes">Monday:
Tuesday:
Wednesday:
Thursday:
Friday:
Saturday:
Sunday:</textarea></td>
</tr>
The line breaks in the <textarea></textarea> element are there to get the line breaks on the page. However it also includes the indentation in the textarea element.
e.g.
The only way I can think to remove this issue is to remove the indentation. Its not the end of the world, but is there another way, to keep the nice formatting? Thanks.
You could use the
(it means new line in html) but maybe that's not a nice formatting, like you said...
The only way I can think to remove this issue is to remove the indentation. Its not the end of the world, but is there another way, to keep the nice formatting?
<tr>
<td class="label">Clinic Times:</td>
<td><textarea name="familyPlanningClinicSessionsClinicTimes">Monday:
Tuesday:
Wednesday:
Thursday:
Friday:
Saturday:
Sunday:</textarea></td>
</tr>
There isn't a pure HTML solution to your problem. Textareas always display any whitespace in their contents.
In a perfect world, you'd be able to take advantage of the CSS property white-space; unfortunately, it isn't applied to textareas either.
You can use <div> with contenteditable attribute:
<div contenteditable="true" style="width: 450px; height: 300px; white-space: pre-line;" name="familyPlanningClinicSessionsClinicTimes">Monday:
Tuesday:
Wednesday:
Thursday:
Friday:
Saturday:
Sunday:</div>
But in your case I think idea solution will be just using several ordinary text boxes, one for each day:
Monday: <input type="text" name="familyPlanningClinicSessionsClinicTimesMonday" /><br />
Tuesday: <input type="text" name="familyPlanningClinicSessionsClinicTimesTuesday" /><br />
...
Nope; a textarea will spit back whatever it actually has.
You could inject the value from JavaScript, but that seems like a lot of work for an isolated thing.
In C# if you want to send a new line to a textarea you can use Environment.NewLine
If you merely want a list of items, you can use
<ul>
<li>"Monday"</li>
<li>"Tuesday"</li>
...
</ul> Using <ul><li></li></ul> will start a preformatted list with <ul> starting the list and <li> starting each item on the list. This method does not require any java or css and will auto indent.
This works for me in angular:
ts:
log: string[] = [];
html:
<textarea row=5 col=50>{{ log.join("
") }}</textarea>
result:
in textarea each item of log is shown in a new line.
Try <br/> if it is good for you:
Monday:<br/>Tuesday:<br/>...
why the Markup Validator says it has error in the html code below?
Line 287, Column 80: attributes construct error
…ion" value="set=1&page=2" /><ul><li><a href="http://campusfaithhub.org/vie…
http://validator.w3.org/check?uri=http%3A%2F%2Fcampusfaithhub.org%2Ffood%2Ffood-should&charset=%28detect+automatically%29&doctype=Inline&ss=1&outline=1&group=0&No200=1&verbose=1&user-agent=W3C_Validator%2F1.1
<div id="pagination">
<!-- add this to fix IE whitespace bug. IE sees a space inside an empty div, and applies line-height to it. The div will then be expanded in IE6 (and older) to accommodate this space. There's your gap. Simplest solution is to make sure IE6 understands that the empty div really _is_ empty, by putting a comment inside it and make sure there's no line-break. -->
<input type="hidden" class="last-pagination" value="set=1&page=2" />
<ul>
<li>1</li>
<li>2</li>
</ul>
</div>
<!--pagination-->
I have a hidden input field to store some info. If I take it out, it still is validated with errors! I can't find anything else to fix - can u see what I have done incorrectly? thanks!
EDIT: after viewing the source of your actual page, I see this problem...
<input type="hidden" class="last-pagination" value="set=1&page=2" /><ul><li>1</li><li>2</li></ul></div>
Specifically: page=1"class="current
You need a space between the closing quote and opening attribute tag.