Apply a space character before a table in HTML - html

I have a table with two rows and one column which is surrounded by P tag.
After P I have inserted some " " for applying some space to the table from the start of the line, but these spaces don't get applied to the table and the table was shown from the start of the line.
table {float: left; background: green;}
<p>
<strong>
<span style="font-family:b titr">
<table>
<tr>
<td>
<textarea id='MainSign' name='MainSign' style='background-color:transparent; width: 150px; height: 150px; border: none'></textarea>
</td>
</tr>
<tr>
<td>
<br />شیطون<br />مدیریت کل
</td>
</tr>
</table>
</span>
</strong>
</p>

The <table> tag creates a newline when it is used. So all your spaces are created above the table. The best way to make it possible is use inline CSS code:
<table style="margin-left: 2cm;">
There isn't any need of making the table within a <p> tag.

I guess that you want to move your table away from the left border. You can do this easily with CSS, without adding .
Check this fiddle Fiddle.
I changed the background color to red for easy to understand. Then I gave a id for the table. As id='MainSign' with CSS and then I changed the margin-left:
#mainTable{
margin-left: 100px;
}
You can use any value instead of "100px;".

Table can't be inside a paragraph (paragraph is closed when table begins).
Use float to indent table by spaces in a paragraph. And you can remove span and strong too; they are empty and closed when table begins.
p {float: left; background: red; margin: 0;}
table {float: left; background: green;}
http://jsfiddle.net/5439pj0p/
Note:
HTML, which is rendered by the browser from your code, is:
<p>
<strong>
<span></span>
</strong>
</p>
<table>...</table>
<strong></strong>
<p></p>
Here is a fiddle where you can see that there are really two strong elements (yellow, size of 10x10 pixels).
http://jsfiddle.net/5439pj0p/1/

Related

How to put spaces between text in html?

How do you to put spaces between text in html? For example,
<p>a b c</p>
What do you put to have space between b and c?
Try using white-space with value pre.
pre Sequences of whitespace are preserved. Lines are only broken at newline characters in the source and at <br> elements.
p {
white-space: pre;
}
<p>a b c</p>
Use a monospaced font if you need each black space to take exactly one character width.
p {
white-space: pre;
font-family: monospace;
}
<p>a b c</p>
You can try to put between them. Like this:
<p>a b c</p>
There are several ways.
Pre Tag
One is to use the <pre> tag, which will render content with the whitespace intact.
Space Entities
Another is to add space entities, like (non-breaking space). Keep in mind with this approach, there are several space entities, and this particular entity does not word-wrap, which may not be the behavior you wanted. renders a normal space, which the browser should not collapse, and which will word-break as expected.
Here is a list of different Unicode spaces you can use.
CSS
Also, you usually should not use HTML entities to create space between text which is not part of one uniform sentence. This is because in this case, the better solution is to use margin or padding to separate the two, and keep each in its own element.
As another answer mentions, CSS letter-spacing is also an option if the spacing is consistent but larger than normal.
Here's an example of all these approaches (the CSS is not important here):
th, td {
border: 1px solid black;
padding: 3px;
}
th {
background-color: darkgrey;
color: white;
}
table {
border-collapse: collapse;
}
body {
font-family: sans-serif;
}
<table>
<thead>
<tr>
<th colspan="2">HTML Spacing</th>
</tr>
<tr>
<th>Method</th>
<th>Result</th>
</tr>
</thead>
<tbody>
<tr>
<td>Normal</td><td><p>a b c</p></td>
</tr>
<tr>
<td>Pre Tag</td><td><pre>a b c</pre></td>
</tr>
<tr>
<td>Margin Left</td><td><span>a </span><span>b</span><span style="margin-left: 3.5em;">c</span></td>
</tr>
<tr>
<td>Non-breaking Space</td><td><p>a b c</p></td>
</tr>
<tr>
<td>Em Space</td><td><p>a b       c</p></td>
</tr>
<tr>
<td>Letter-Spacing</td><td><span>a </span><span style="letter-spacing: 3.5em;">bc</span></td>
</tr>
</tbody>
</table>
Use . This will not breaks line too.
Use the CSS property word-spacing to set space between words. You can also use <span> and apply margin or padding.
So:
span { margin-left:1em }
<p>a b <span>c</span></p>
As others have said, you can add a space with :
But also add tabs with :   and  

Less margin-top/top

I'm developing a website for a company right now. I've done a table and now they say that the td must be also a link. The problem is that one td has three lines and the three lines must be the same link tag. I used a paragraph tag inside the link to change the line height, because they want the three lines with less line space, but it leaves a top space that must be removed. I've tried changing the margin-top, padding-top, td height... Nothing seems to work. If someone can help me I'll appreciate it.
Thank you.
Here's my code:
<table>
<tr>
<th>COMUNITAT</th>
<td>Bé comú</td>
<td>Glocalitat</td>
<td>Cercle</td>
<td>Lideratge</td>
<td>Comunicació</td>
<td>Famílies</td>
</tr>
<tr>
<th>EDUACIÓ</th>
<td>Aprenentatge</td>
<td>Qualitat</td>
<td>Idiomes</td>
<td>Personalització</td>
<td>Llenguatges</td>
<td>Creativitat</td>
</tr>
<tr>
<th>CARÀCTER</th>
<td>Identitat</td>
<td>Espiritualitat</td>
<td>Fet religiós</td>
<td>Equitat</td>
<td>Passió</td>
<td>Rol educador</td>
</tr>
<tr style='border:none !important; vertical-align: top;'>
<th>ENTORN</th>
<td>
<a href="#">
<p>Escola<br/>Universitat<br/>Empresa</p>
</a>
</td>
<td>Oberts</td>
<td>Tecnologia</td>
<td>Arquitectura</td>
<td>Oferta</td>
<td>Transformadors</td>
</tr>
</table>
And here's my actual CSS:
table a p {
font-size: 100%;
text-align: left;
line-height: 1;
}
Edit: This is how it looks currently.

How to combine JSP fragments into seamless table regardless of ordering

I have multiple JSPs that each contain one or more tables.
fragment1.jsp:
<table class="foo">
<tr>
<td>stuff</td> <td>stuff2</td>
</tr>
</table>
fragment2.jsp
<table class="foo">
<tr>
<td>more stuff</td> <td>more stuff2</td>
</tr>
</table>
<table class="bar">
<tr>
<td>whatever</td>
</tr>
</table>
They are used by wrappers in different configurations:
wrapper1.jsp
<s:include value="fragment1.jsp" />
<s:include value="fragment2.jsp" />
wrapper2.jsp
<s:include value="fragment2.jsp" />
If fragment2.jsp comes after fragment1.jsp, I want these two tables to have no margin between them and appear as one table. However, if either one is alone, I want them to be formatted normally as "foo" tables are styled.
Is there a way to indicate this styling preference in some way such that the two "foo" tables will appear as a single table when adjacent, but otherwise style themselves normally?
I am somewhat new to Struts/JSP and dealing with some kludged legacy code, so please help me understand if this problem would be better solved through another approach.
It is actually possible with CSS only, without JavaScript and without changing the HTML.
A full screen demo is worth a thousand words...
Basically, you need to use border-collapse: collapse; and specify the following settings:
When the table is alone, all the borders and margins normally set:
table {
border-collapse : collapse;
border : 4px solid black;
margin-top : 20px;
margin-bottom : 20px;
}
When the table is adjacent to one or more other tables:
If it's not the first, remove margin-top and border-top:
table + table {
margin-top : 0;
border-top : none;
}
If it's not the last: remove margin-bottom and border-bottom:
table:not(:last-child) {
border-bottom : none;
margin-bottom : 0;
}
Also ensure to avoid setting a border on the last <tr> of each table:
tr:not(:last-child) {
border: 1px solid silver;
}
It's better to use javascript and jquery for doing such works. So I think this can be helpful:
$(document).ready(function(){
var secondTable = $(".bar").html();
$(".foo").append(secondTable);
});
Note, you need to include jquery library if you have not included it already.
There's no need to use tables if you don't use tabular data. You can always use div or span tags.
<div class="foo">
<span>more stuff</span> <span>more stuff2</span>
</div>
<div class="bar">
<span>whatever</span>
</div>
The CSS selector table.foo + table.foo will select every element of table.foo that appears after another element of the same type.
You can use it to remove the margin from all following table.foo elements:
table.foo + table.foo {
margin-top: 0px;
margin-bottom: 0px;
}
If it should apply to the second element only, use table.foo:nth-child(2) instead.

tables and spacing

I have created a couple of tables. now i need both tables to be next to each other and not one table on top of each other. how can i position the second table next to the first one (to the right) but with sufficient space in between?
this is some code of my second table:
<table>
<h3>Personaldaten</h3>
<tr>
<td>Externe Referenz:</td>
<td colspan="2">
<input class="LargeText" type="text" style="width: 150%">
</td>
</tr>
<tr>
<td>Titel:</td>
<td colspan="2">
<input class="LargeText" type="text" style="width: 150%">
</td>
</tr>
above are 2 entities from the first table, how do i proceed like this?
Try to use a wrapper around the tables and use float:left;
//margin: top right bottom left
<div style="width:500px; margin: 30px 0px 0px 320px">
<table style="width:240px; float:left; margin-right:20px;">
</table>
<table style="width:240px; float:left;">
</table>
</div>
get rid of your absolute positioning if you don't really need it and use CSS like
table{
float:left;
margin:0px 5px;
}
You have two choices really.
If you're happy creating your layout with tables, then put both of your tables within another table. i.e.
<table>
<tr>
<td>
<table>{ table 1 stuff }</table>
</td>
<td>
<table>{table 2 stuff }</table>
</td>
</tr>
</table>
Or you can start looking into 'float'ing your elements.
You can create a new table with 1 row and 2 columns and place your first table inside the first column and your second table inside the second column.That way both tables can be displayed side by side
If it were me, I would surround your tables in a div layer, specifying the width and height of the div layer to force the tables next to each other.
For example:
<div id="tablecontainer">
<table id="lefttable"></table>
<table id="righttable"></table>
</div>
And in the CSS:
table
{
margin: 5px;
}
#lefttable
{
float: left;
}
Obviously, this code isn't going to be exactly what OP wants, but you get the idea.
Either use float: left or display: inline-block.
#1:
table {
margin: 10px;
float: left
}
#2:
table {
margin: 10px;
display: inline-block
}
See http://shaquin.tk/experiments/tables2.html and http://shaquin.tk/experiments/tables3.html.
First, fix the syntax and styling. A table element cannot have an h3 child. Either put the h3 inside a cell (which is inside a tr), or turn it to a caption. Don’t set a width of 150%, as this would make the a cell occupy 150% of the width of the available space. The width of an input field set is best set in characters, using the size attribute in HTML.
Then you can float the tables in CSS as suggested in other answers, or by using align=left in table tags. To create horizontal spacing between the tables, you can set e.g. margin-right on the first table.
Note that for usability and accessibility, forms should normally be presented so that there is one input item with its label on one line, so that filling out the form proceeds vertically in a simple manner. So you might be solving the wrong problem.

Html table how to make all columns same height

I want to display 4 or 5 boxes(vary) which occupy's 100% of the page width, so it will span start to end of page. and want height just to fit contents.
I am trying to use table for that so it will assign width for each box and fill up whole row.
Problem with code below is all divs in td are centered and does not have same height. tried all i can think of but it doesn't work. tried vertical alignment, height to 100% .....
How can i have all div in td with same height?
Also if there is another way to doing same please let me know. I am html dummy so may not using the right thing.
<table style="width: 100%; text-align:justify;">
<tr>
<td>
<div style="margin-right:15px; background-color:Gray">
Some text here
</div>
</td>
<td>
<div style="margin-right: 15px; background-color:Gray">
column 2 text here
</div>
</td>
<td>
<div style="margin-right: 15px; background-color:Gray">
Column 3 text here
</div>
</td>
<td>
<div style="background-color:Gray">
Last column text here
</div>
</td>
</tr>
</table>
Like I've told plenty of other people, you shouldn't be using divisions inside table cells.
This will achieve the exact same effect, without the divisions:
<table style="width: 100%; text-align: justify;">
<tr>
<td style="margin-right: 15px; background-color: gray;">
Some text here
</td>
<td style="margin-right: 15px; background-color: gray;">
column 2 text here
</td>
<td style="margin-right: 15px; background-color: gray;">
Column 3 text here
</td>
<td style="background-color: gray;">
Last column text here
</td>
</tr>
</table>
If you get rid of the divs and apply your styles and content directly to the table cells you will get the effect you want.
In case there is no special purpose of using div tag inside td. I would just do it without div. add style to td tag.
Mamu, I would suggest that you do not use inline style elements. Instead of styling your table tags it would be far more efficient, and better to add the the following between your <head> tags:
<style type="text/css">
table {width:100%; text-align:justify;}
table td {margin-right:15px; background-color:gray;}
</style>
Using only those two lines of code you can apply the same elements consistently across your entire website. If you only wanted to apply them to some elements, you could create classes by adding a "." to a name of your choice:
<style type="text/css">
.MyTable {width:100%; text-align:justify;}
.MyTable td {margin-right:15px; background-color:gray;}
</style>
And add the following to your HTML:
<table class="MyTable">
Note that class names are case sensitive. But this reusable code is far more efficient.
Furthermore, I would urge to consider the use of tables only if you are presenting tabular data. Tables load slower and are not SEO friendly. It would not be semantically correct to use them for layout. You should separate content from presentation whenever possible, and if it is layout you are after I would suggest using divs and other elements instead.