I have a table in the below format
<tr >
<td>
<span class="boldText">OfficeType</span>
</td>
<td>
<p class="mb0">BDA REGISTRATION INVESTIGATION & CORRECTIONS</p>
</td>
</tr>
.mb0 {
margin-bottom: 0px;
}
The expectation is the text OfficeType and BDA REGISTRATION INVESTIGATION & CORRECTIONS should appear in the same line with extra text to wrap to the next line.The text wraps to the next line but the OfficeType and BDA REGISTRATION are not aligned in the same line.Can you please help me in this,what am I doing wrong here?
Add valign=top to TD elements
<tr>
<td valign=top>
<span class="boldText">OfficeType</span>
</td>
<td valign=top>
<p class="mb0">BDA REGISTRATION INVESTIGATION & CORRECTIONS</p>
</td>
</tr>
Unlike p tag, span does not have a css attribute of
"display:block"
so you can add it to p tags style to have equal line height
If you press F12 and take a look at the box model you'll see that p comes with a default top margin but span doesn't.
The simplest way to deal with this is to be consistent with your use of p and span tags across all cells.
Related
I have added a <h4> tag in a <td> element and rotated 90 degrees,
so that both the <td> and <h4> are rotated.
Issue:
If my <h4> content is bigger or contains a space it comes in a new line.
How I can fix this? I need to put all the content in a single line in the <td>.
nowrap Attribute is what you need.
<table>
<tr>
<th>Poem</th>
<th>Poem</th>
</tr>
<tr>
<td nowrap><h4>Never increase, beyond what is necessary</h4></td>
<td>Never increase, beyond what is necessary, the number of entities required to explain anything</td>
</tr>
</table>
I am trying to use table element to align text to print to A4 page using the plain HTML i got perfect alignment which prints perfectly in a paper but when printing another name td is resized and i lose paper alignment as i have tapleted paper with fields like name already printed so i need right aligment so it would print in the same section on the paper.
any solution for this?
<table width = 100% border =1>
<tr>
<td> </td>
<td> </td>
<td align = "right"><my><?php echo $name;?></my></td>
<td> </td>
<td> </td>
<td> </td>
<td align = "center"><my><?php echo $rollno;?></my></td>
<td> </td>
<td> </td>
</tr></table>
You can set table-layout: fixed property for table element and width: ? (where ? stands for the width value you want to provide) for your td element.
By the way, html attribute value should be always enclosed with quotes, for example: border="1".
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'm trying to write some HTML/CSS to display a certain row with some of the elements left-aligned and some of them in the center. This was my HTML code:
<tr class="mainInfo" id="header">
<td> Item </td>
<td> Color </td>
<td> Size </td>
<div class="mid">
<td> Subtotal </td>
<td> Tax </td>
<td> Total </td>
</div>
</tr>
And this is my CSS code:
.mid {
text-align: center;
}
.mainInfo {
font: bold 13px Tahoma;
}
#header {
background-color: #68891;
color: white;
}
But the last three elements are not moving to the center, and I really don't understand why not. I tried putting class="mid" in the <td> tags and that worked, but doesn't that defeat the purpose of DRY?
Fiddle Demo
You cannot put a div instead of td element.
You should validate your HTML code with w3 validator.
If you'll do so you'll see you get this error message:
document type does not allow element "DIV" here; missing one of "TH", "TD" start-tag
Maybe you can do it this way:
<table>
<tr class="mainInfo" id="header">
<td> Item </td>
<td> Color </td>
<td> Size </td>
<td class="center">Subtotal</td>
<td class="center">Tax</td>
<td class="center">Total</td>
</tr>
</table>
JSFiddle example
No, you should not put divs inside tr's or tables.
And you should not use tr's or td's without table-element.
<table>
<tr>
<td>hello world</td>
<!-- This is bare minimum to use tables properly -->
</tr>
</table>
You can insert whatever(not tr or td, but could start new table) you want inside TD-elements though.
It's possible to use other elements to replace these standard ones with css display-property set to table-row etc., but you should stick to conventional tags.
Use colspan/rowspan to span over multiple table columns or rows.
CSS classes are designed to be used as often you need/want to. Only IDs should appear once per page.
Of course you should always keep the DRY concept in mind but in your case it's totally fine. It wouldn't if you would set your .mid class to every <td> because in that case you could just set the properties directly to the <td> element.
middle is not a valid value for text-align, so I'm going to assume, in your CSS, that's meant to be vertical-align. If so, it's because vertical-align will only apply to table cells, not divs - that would explain why it is only being successfully applied to your tds.
Additionally, you shouldn't really put a div inside a table (and shouldn't put a td inside of that) but that's not related to your problem.
Assign one class for left alignment and other for center like so...
.left {
text-align:left;
}
.center {
text-align:center;
}
Asign class to TD elements
<tr class="mainInfo" id="header">
<td class='left'> Item </td>
<td class='center'> Color </td>
</tr>
I am trying to place a hyperlink vertically so it's to the middle of the height of a textbox but it's not working for me.
Here's the jsfiddle example. I want to do this without using Javascript, works in IE6+, the two elements need to be in the same td column, without using hard coded pixels, and the hyperlink to be right next to the right edge of the textbox (like it's shown in the example, just move it upward to the middle of the yellow box).
As long are the textarea and a elements are inline elements, they will share their base line. If you float the elements, you can set the line height of the a element to match the height of the textarea:
textarea { float :left; }
a { float: left; line-height: 6em; }
Demo: http://jsfiddle.net/Guffa/aLtXA/6/
Well, if you are willing to nest tables, this will work:
<table>
<tr style="vertical-align:top">
<td>
<table>
<tr style="width: 500px;">
<td>
<textarea cols="45" rows="5"></textarea>
</td>
<td style="background-color:yellow; vertical-align:middle">
Edit
</td>
</tr>
</table>
</td>
<td>
second cell
</td>
</tr>
</table>
but I hate this level of nested hell. It leads to madness and grey hair.
I hope someone will post a nicer answer.
Is it possible perhaps with the twitter bootstrap?
Here you go: http://jsfiddle.net/aLtXA/16/
I put vertical-align:middle on the TEXTBOX and anchor. As well, I removed the vertical-align from the table cell.