Contenteditable Editing Only Plain Text - html

I have a table that contains contenteditable=true cells.
I wish to insert a button into those cells but the problem is that I can backspace those buttons away and I don't want that too happen.
Here is what I am doing:
<table><tr>
<td contenteditable=true>Text Here
<button>Don't delete me!</button>
</td>
I don't want to create two spans inside the cell, one editable and one not, because I cant figure out how to make it fill the entire cell.

You can separate the button into another <td>.
td {border: dashed 1px red}
<table>
<tr>
<td contenteditable="true">Text Here
<td contenteditable="false"><button>Don't delete me!</button></td>
<td contenteditable="true">After button Text Delete me
</td>
</tr>
</table>

Don't nest any elements inside an element with contenteditable unless you don't care about them being deleted. Nest a contenteditable element within the <td> or put the <button> outside of <td> and use position:relative or transform:translate over the <td>. This Snippet demonstrates three ways.
The second and third examples are fragile and can break easily, the first example is the best and most simplest.
SNIPPET
.ghost {
position: relative;
right: 150%;
top: 14px;
}
.extended {
position: relative;
right: 12%;
vertical-align: top;
}
.bg {
position: relative;
right: 170%;
z-index: 0;
width: 100%;
height: 100%;
}
.up {
position: relative;
right: 170%;
z-index: 1;
}
button {
display: block;
}
td {
min-width: 210px;
}
<table>
<tr>
<td>
<label contenteditable=true>Example 1</label>
<button>Don't delete me!</button>
</td>
<td class='extended' contenteditable=true>
Example 2
</td>
<td>
<button class='ghost'>Don't delete me!</button>
</td>
<td>
<div class='bg' contenteditable=true>Example 3</div>
<button class='up'>Don't delete me!</button>
</td>
</tr>
</table>

Related

Semantic way of stacking two characters in a ::before element?

I'm trying to add checklist symbols to the left edge of table cells. So far, this does work. When I'm trying to stack another char on top of the checklist symbol though, things get ugly.
I have found several ways to achieve the result I'm after, but none of them looks particularly good to me.
Does anyone have a better idea, preferably one that'd allow to concentrate on the semantics?
.checklist::before {
content: "◯ ";
}
.checklistabs::before {
content: "◯ ";
position: absolute;
}
.check::before {
content: " ✘";
position: absolute;
font-size: 130%
}
.checked {
position: absolute;
font-size: 130%
}
.checklisttext {
margin-left: 1.5em;
}
<table>
<tr>
<td class="checklist">
perfect as long as nothing needs to be overlaid
</td>
</tr>
<tr>
<td>
<b class="checked">✘</b>
◯ Seems to work best, but has explicit bullet symbol as part of the text.
</td>
</tr>
<tr>
<td>
<div class="checklistabs" />
<div class="check" /> If the bullet symbol goes into another absolutely positioned item, we need to make space at the beginning of the text. ::before would have been much more elegant.
</td>
</tr>
<tr>
<td class="checklist">
<div class="check" /> why does this introduce a linebreak?
</td>
</tr>
<tr>
<td class="checklistabs">
<div class="check" /> Saving on divs
</td>
</tr>
<tr>
<td>
<div class="checklistabs" />
<div class="check" />
<div class="checklisttext">So this works...</div>
</td>
</tr>
<tr>
<td class="checklist check">
Looks preferrable from a semantic point of view but does not work - see http://stackoverflow.com/questions/11998593/can-i-have-multiple-before-pseudo-elements-for-the-same-element
</td>
</tr>
</table>
If you position both the ::before and ::after absolutely and add a padding to the <td> element you can get the effect you want. It requires more CSS and some values heavily tied to your font-size. But if you change the px values to em it should scale well.
table {
width: 350px;
}
.checklist {
padding: 0 0 0 20px;
position: relative;
}
.checklist::before,
.checked::after {
position: absolute;
left: 0;
top: 0;
width: 17px;
text-align: center;
line-height: 20px;
}
.checklist::before {
content: "◯ ";
}
.checked::after {
content: " ✘";
font-size: 130%;
}
<table>
<tr>
<td class="checklist checked">
A little more CSS and positioning, but will work well if the text linebreaks.
</td>
</tr>
</table>
I would display the ◯ as an inline element, then place the ✘ over it using absolute positioning. Seems to work without any unnecessary markup.
.checklist:before {
content: "◯ ";
}
.checklist:after {
content: " ✘";
position: absolute;
left: .6em;
font-size: 1.3em;
top: .6em;
}
<table>
<tr>
<td class="checklist">
perfect as long as nothing needs to be overlaid perfect as long as nothing needs to be overlaid perfect as long as nothing needs to be overlaid perfect as long as nothing needs to be overlaid perfect as long as nothing needs to be overlaid
</td>
</tr>
</table>
why does this introduce a linebreak?
Because .check is a div with display: block; so it's contents will display on it's own line. Set it to display: inline-block; or apply float: left; to the .checklist:before element, and those elements will be on the same line.

How to make absolute textbox positioned in the middle of each row?

I have a simpe table table. There are hidden textbox inside each cells. When I double click the cell, the specific textbox on current cell should show up. The textbox position should be in front of the table, absolute position an in the center of each row. This is the td of my table:
<td class="live_column">
<input type="hidden" class="h_textbox" name="bidang_job" value="EDIT HERE" style="position:absolute; margin-left:auto; width:80%;" />
</td>
My current table show up like this:
I can make it happen by using margin-left:-x px.
For example:
In row 1, all the textbox position have margin-left:0px
In row 2, margin-left:-250px
In row 3, margin-left:-500px
I don't know if that's the proper way. By the way, here's the desired output:
The align attribute of is not supported in HTML5. Use CSS instead.
Specifies the alignment of an image input (only for type="image"). Only the "left" and "right" values of the align attribute work properly in all major browsers.
One way would be to position the textbox relative to the <tr>. Something like this:
table tr {
position: relative;
display: block;
}
td.live_column .h_textbox {
position: absolute;
/* Align it to the horizontal and vertical center of the row */
left: 0; top: 0; right: 0; bottom: 0;
margin: auto;
}
/* Positioning the textboxes to the center */
table tr {
position: relative;
display: block;
}
td.live_column .h_textbox {
position: absolute;
left: 0; right: 0; bottom: 0; top: 0;
margin: auto;
}
/* Some style to format the boxes */
td {
border: 2px #666 solid;
height: 40px;
width: 90px;
}
td.live_column .h_textbox {
height: 16px;
width: 80%;
border: 2px #F05 solid;
}
<table>
<tr>
<td class="live_column">
<input type="text" class="h_textbox" name="bidang_job" value="EDIT HERE" />
</td>
<td></td> <td></td> <td></td>
</tr>
<tr>
<td class="live_column">
<input type="text" class="h_textbox" name="bidang_job" value="EDIT HERE" />
</td>
<td></td> <td></td> <td></td>
</tr>
<tr>
<td class="live_column">
<input type="text" class="h_textbox" name="bidang_job" value="EDIT HERE" />
</td>
<td></td> <td></td> <td></td>
</tr>
</table>

HTMLTable: Empty link element should take up whole cell space

I am using a (bootstrap) table where I put a link inside one of the cells, where it might happen, that the actual link text is empty, thus not showing the link element (or better to say the user can't click it). Now the goal is, that the link element should take up the whole cell space regardless of whether there is some text in the link or not.
<table class="table table-bordered table-striped">
<tr>
<td><a ...>Text that might be empty</a></td>
...
I have tried setting the display property of the a-tag to inline-table which worked for the most browsers except IE. Is there a nice, clean and crossbrowser compatible way to achieve this?
Give the anchor a display: block. It then will take the full width of its parent.
I've made you this demo. By clicking the button, you'll see how it works.
Note, that the anchor should at least have 'something' in it.
$('button').click(function() {
$('a').toggleClass('block');
});
td {
border: 1px solid red;
}
tr, td {
height: 100%;
}
a {
background: blue;
}
a.block {
display: block;
height: 100%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr>
<td> </td>
<td>Text<br />text</td>
</tr>
<tr>
<td>Text text</td>
<td>Text text</td>
</tr>
</table>
<button>Toggle block</button>
Set min-width for the column
<td style="min-width:50px"><a ...>Text that might be empty</a></td>
This will work with/without text.
.hasLink{
position: relative;
height: 38px;
}
.hasLink a{
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
font-size: 0px; //if you don't want to show any text
padding: 8px 0 0 5px;
}
<tr>
<td class="hasLink"></td>
<td></td>
</tr>

input field width is not what I set it to be, misaligned. Additional border in input

http://jsfiddle.net/HnnHf/1/
Trying to understand what I do wrong. Plain table, I want input boxes to fill cells evenly. On first row you see 2 inputs and second row has one input spanned across cells.
Their right sides don't match. Why? When I run inspector it shows additional pixels?
Part of my HTML:
<div style="width: 1000px; margin-left: auto; margin-right: auto; padding-left: 20px; padding-top: 10px;">
<table>
<tr>
<td style="width: 80px;"><label>From </label></td>
<td style="width: 120px;">
<input type="text" class="fill-space" />
</td>
<td style="width: 80px;"><label>To </label></td>
<td style="width: 120px;">
<input type="text" class="fill-space" />
</td>
<td style="width: 80px;"><label>Sort by </label></td>
<td></td>
</tr>
<tr>
<td colspan="6"> </td>
</tr>
<tr>
<td></td>
<td colspan="3">
<input type="text" class="search" />
</td>
<td></td>
<td>
Refresh button
</td>
</tr>
</table>
</div>
Style:
td label {
width: 100%;
color: #F1F1F1;
text-align: right;
vertical-align: central;
}
input.fill-space {
width: 100%;
}
input.search {
width: 100%;
background-image: url("/images/Search.png");
background-position: right center;
background-repeat: no-repeat;
}
</style>
My live site misalignment:
Also, why do I get this another border inside input if I set background?
Working fiddle: http://jsfiddle.net/ghUEw/
Default padding and margins for table elements differ in different browsers.
So you'd better use a CSS reset on table elements.
table * {
margin: 0;
padding: 0;
}
Then, comes the border-collapse property. It determines whether the table borders are collapsed into a single border or rendered individually, let's say for neighboring table cells. You need to set it as following to make them collapsed since you have different number of cells per table row.
table {
border-collapse: collapse;
}
Then, you need to set the borders of the inputs in your table if you want them look the same.
table input {
border: 1px solid #aaa;
}
If you don't want any borders to appear, replace it with border: none;
Then, in your CSS, for the labels to appear the way you want, you can apply float:right; (also corrected vertical-align: middle;)
td label {
width: 100%;
color: #F1F1F1;
text-align: right;
vertical-align: middle;
float:right;
}

Floatable element into td element

I cannot get this style to work. Take a look at my drawing:
Markup:
<h1Title</h1>
<table>
<tr>
<td>
<dfn>help</dfn>
<a href="link0.php">
<span>text</span></a>
</td>
<td><a href="link1.html">
<span>text</span></a>
</td>
</tr>
</table>
I'm trying to make the <td> element clickable by using the <a> element as a block. But, I need to put a small "header" with <dfn> element inside the <td> too. I can make the <dfn> align to top-right and preserve the <a> vertical text align relative to its container without conflicting with <dfn> when it exists.
Thank you in advance
I changed your markup bit and added some positioning and padding to get something close to the image you posted:
HTML
<h1>Title</h1>
<table>
<tr>
<td>
<span class="cellContainer">
<dfn>help</dfn>
text
</span>
</td>
<td>
text
</td>
</tr>
</table>
CSS
td {
border: 1px solid black;
}
.cellContainer {
position: relative;
display: inline-block;
padding: 12px 0;
}
a {
background: grey;
padding: 12px 24px;
}
dfn {
position: absolute;
top: 0;
right: 0;
}
jsFiddle Demo
The borders in the demo represent the cell borders. The grey background is the link area.