as of now I did all my reports in LaTex and only recently I started to use HTML (for many reasons). What I am looking for is the HTML solution for a text formatting. The problem is the following: in a list of N bullets each bullets should be formatted in this way:
bullet#1 [text-of-length1] <- space -> [text-of-length2]
bullet#2 [text-of-length3] <- space -> [text-of-length4]
the 4 lengths could be different, but I want the text [length2] and [4] (the 2nd text part in each bullet), to start at the same point in space.
In LaTex this is solved imposing a certain size of a box that contains the first part of the text, thus pushing the second part of the bullet to start only after this box.
I tried to write each text in a table cell and partially works, but now the text is not aligned to the bullet (as if the cell is aligned but the text is slightly off-set up, the vspace = "bottom" did not help).
<ul style="list-style-type:square">
<li><table style="display:inline"><tr><td width="100">test</td><td>test</td>
</tr></table></li>
<li><table style="display:inline"><tr><td width="100">test2</td>
<td>test2</td></tr></table></li>
</ul>
Any idea?
Thanks in advance.
Try setting the style vertical-align: baseline; to table cells. This will align the table cell contents with bullet.
td {
padding: 1;
vertical-align: baseline;
}
<style type="text/css">
td {
padding: 1;
vertical-align: baseline;
}
</style>
<ul style="list-style-type:square">
<li>
<table style="display:inline">
<tr>
<td width="100">test test test test<br/>test</td>
<td>test</td>
</tr>
</table>
</li>
<li>
<table style="display:inline">
<tr>
<td width="100">test2</td>
<td>test2</td>
</tr>
</table>
</li>
</ul>
Related
In my css I use:
body {
font-weight: 300;
direction: rtl;
margin: 0;
}
Also in html I use:
<body dir="rtl">
I have a table bootstrap table like this:
<table align="center" class="table table-striped table-responsive-sm table-bordered">
<tbody>
<tr>
<td style="width: 25%">کد عضویت</td>
<td>426075</td>
</tr>
<tr>
<td>نام</td>
<td>سوسن</td>
</tr>
</tbody>
</table>
But all my writings are still left aligned instead of right aligned, regardless I used rtl. A full source codepen and page view is at: https://codepen.io/joehark/pen/yLLeyoG
What mistake I did and how to right aligned my table writings? Do I still need class="text-justify" within each <td>? If yes, what is the purpose of that rtl setting at all?
The direction:rtl is not enough since it affect the align of block elements:
The property sets the base text direction of block-level elements and
the direction of embeddings created by the unicode-bidi property. It
also sets the default alignment of text, block-level elements, and the
direction that cells flow within a table row.
Unlike the dir attribute in HTML, the direction property is not
inherited from table columns into table cells, since CSS inheritance
follows the document tree, and table cells are inside of rows but not
inside of columns.
MDN
Use: td {text-align: right; direction: rtl;} in order to set right align text on table's td.
I have a table with multiple columns. In one of the column rows I want to add 2 elements which will be next to each other. One text element and one icon. The icon has a fixed with, the text element needs to be dynamic and has to be truncated with ... when the column cannot stretch anymore.
This is the HTML:
<table>
<tr>
<td>
</td>
<td>
<span>Truncated text goes here</span>
<i class="icn sprite icn-name></i>
</td>
<td>
</td>
</tr>
</table>
How do I do this? Using display: table; will make the HTML all buggy.
As said in comments, if you allow text and image to stay in adiacent cells, you can try the following.
<table>
<tr>
<td>Truncated text goes here</td>
<td><img src="imageURL" /></td>
</tr>
</table>
You can use vertical-align:top; in td style to align text on the top of the cell. And then you can use the following to set image width.
td>img {
vertical-align:top;
display:inline-block;
width:80px;
}
Fiddle
UPDATE
If you don't want to add extra cells to your table, you can create an internal div inside the cell, display it with display:table; property, and then display both span and img with display:table-cell; property.
Fiddle
I added the <i> element in front of the <span> element and gave the <i> element a float: right; and the <span> element the truncate styles.
Works fine now!
I am looking for some html help. How would I go about moving a text block centrally within a cell but also keeping their alignment left intact. I do not wish the text to be displayed all centered as I am going to be using an unordered list. I simply want the block of text to be moved in to the center of the cell.
Example of current scenario:
http://jsfiddle.net/AygnN/
<table id="sub-content" style="width: 100%;">
<tbody>
<tr>
<th>Departments</th>
<th>KPI Types</th>
<th>Bonus</th>
</tr>
<tr>
<td>
<ul>
<li>dfgsdgfdfg</li>
</ul>
</td>
<td>
<ul>
<li>sdfgsdfgsdfg</li>
</ul>
</td>
<td>
<ul>
<li>sdgsdfgsdffgsdgf</li>
</ul>
</td>
</tr>
</tbody>
</table>
If you have the <h1> tags as column headers, you should use actual table headers (<th> tags). Now, in the CSS you can say:
th { text-align:center; }
EDIT:
#sub-content td{ padding:0px 60px; }
and all table headers will be centered while all lists in the table will be aligned to the left.
This method is much more standard.
JSFiddle
You can put the text in a div and host the div inside the table cell. The text will follow the css style specified in div where as the div itself will be in center of the cell.
The example you have given does same kind of things. It rather divides the cell in multiple cells and put the text in the middle one.
When you create a basic HTML table everything seems to stay in center of the table. I don't want this how can i stop this from happening?
I wish to use a 2 column html table one for column for a sidebar one for content. Because i have so much content the sidebar text (which is little) gos to the middle of column.
How do i align the text to stay to the top left of the columns?
In the <td> element that contains the lefthand sidebar, try specifying a style that aligns text to the top:
<td style="vertical-align: top">(Sidebar HTML code here)</td>
You can control the alignment of columns directly in your markup by using:
<td style="text-align: left; vertical-align: top;"></td>
or even just
<td align="left"></td>
This will work fine for a 2-column table, but Piccolomomo has the better plan if you are going to use it a lot. This might help you further if you need it:
http://www.w3schools.com/html/html_tables.asp
You can use CSS to change text aligning inside your table:
td {
text-align: left;
vertical-align: top;
}
For aligning text in table you have to use css.Without css or any style sheet you can't make them align.So you can use inline css or external css for that.
<style type="text/css">
table td{
text-align:left;
vertical-align:top;
}
</style>
<table>
<tr valign="top">
<td align="left">
Side Bar
</td>
<td>
Content
</td>
</tr>
</table>
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.