I have a CSS coding challenge for everyone here...
I have searched google and looked at multiple options, but cannot figure this one out.
Is also worth mentioning that I'm not a developer, but I understand the basics of how to implement CSS.
I have a section of code that contains check boxes,
I need to make only specific checkbox items bold (not all of the items) via CSS...
Under normal circumstances, the CSS code for this would be: font-weight: bold;
in the right class or ID, however, in my case, I'm using a third party platform with predefined, css classes for each of the code sessions, in the case of the checkboxes section, the CSS class for this is called: .formFieldLabel
So the CSS code section would like so:
.formFieldLabel {
padding-bottom: 2px;
}
Below is the html code section for the checkboxes:
<table cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<div class="" style="overflow: hidden">
<table cellspacing="0" cellpadding="1" class="">
<tbody>
<tr>
<td width="20" align="left">
<input type="checkbox" name="Field 1" id="form_0006_fld_2-0" value="First Choice">
</td>
<td width="*" align="left" style="padding-top: 3px; padding-right: 10px">
<label for="form_0006_fld_2-0" class="formFieldLabel">First Choice</label>
</td>
</tr>
</tbody>
</table>
</div>
</td>
</tr>
<tr>
<td>
<div class="" style="overflow: hidden">
<table cellspacing="0" cellpadding="1" class="">
<tbody>
<tr>
<td width="20" align="left">
<input type="checkbox" name="Field 1" id="form_0006_fld_2-1" value="Second Choice">
</td>
<td width="*" align="left" style="padding-top: 3px; padding-right: 10px">
<label for="form_0006_fld_2-1" class="formFieldLabel">Second Choice</label>
</td>
</tr>
</tbody>
</table>
</div>
</td>
</tr>
<tr>
<td>
<div class="" style="overflow: hidden">
<table cellspacing="0" cellpadding="1" class="">
<tbody>
<tr>
<td width="20" align="left">
<input type="checkbox" name="Field 1" id="form_0006_fld_2-2" value="Third Choice">
</td>
<td width="*" align="left" style="padding-top: 3px; padding-right: 10px">
<label for="form_0006_fld_2-2" class="formFieldLabel">Third Choice</label>
</td>
</tr>
</tbody>
</table>
</div>
</td>
</tr>
</tbody>
</table>
Resuming, the CSS code to make such item bold will need to go inside the following CSS code section:
.formFieldLabel {
padding-bottom: 2px;
}
Can anyone please help me implement this solution?
You could use :nth-child() selector in css to select the checkbox you want.
So maybe something like this to select the second checkbox:
tr:nth-child(2) table input { }
Not sure it the above css works but, you can use :nth-child() to select the <tr> you want from the parent table then from there you can select the input box in the child table.
You can use attribute selectors like this.
<style>
.formFieldLabel[for=form_0006_fld_2-0] {
font-weight: bold;
}
</style>
But you have to know the id of checkbox to do this.
or just add a second css class
class="formFieldLabel boldLabel"
Related
I'm working on a form in my application and trying to clean up the code that was put in place before me. HEre's something I'm coming across that seems like bad practice and I am having a hard time trying to abbreviate it and clean it up.
Here's the code...
<tr>
<td style="padding-top: 10px; padding-bottom: 10px;">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="6%"></td> <---- I want to get rid of this!
<td width="45%">
<asp:CheckBox ID="chkBHRAExpiresDischarge" runat="server" onclick="RadioControl(this);" Text="Upon my discharge from treatment" />
</td>
<td>
<asp:CheckBox ID="chkBHRAExpiresReceiptOfInfo" runat="server" onclick="RadioControl(this);" Text="Upon receipt of the requested information" />
</td>
</tr>
<tr>
<td></td> <------- Have to keep adding this for every checkBox
<asp:Checkbox ID=.............."
</tr>
So what I'm trying to get rid of the the initial indentation, mainly ....
<td width="6%"></td>
Because this is in place, i have to do a
<td></td>
before every single row otherwise the indentation dissapears. Is there any way to fix this so that all my checkboxes are indented?
You can use colspan="2" on the checkbox cells and put padding-left: 6% as a style. Here's a JS fiddle. I added a row above your first row to show the column spacing, modified the first row use this change, and left the second row intact.
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr><td>One</td><td>Two</td><td>Three</td></tr>
<tr>
<td width="45%" colspan="2" style="padding-left: 6%">
<input type="checkbox" /><label>Checkbox</label>
</td>
<td>
<input type="checkbox" /><label>Checkbox</label>
</td>
</tr>
<tr>
<td width="6%"></td> <!---- I want to get rid of this! -->
<td width="45%">
<input type="checkbox" /><label>Checkbox</label>
</td>
<td>
<input type="checkbox" /><label>Checkbox</label>
</td>
</tr>
</table>
edit: Also, I recommend validating your HTML. You can wrap your code snippet up with a doctype and the other necessary items to get identify errors and warnings at https://validator.w3.org.
<!DOCTYPE html><html><head><title>Title is Required!</title></head><body>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr><td>One</td><td>Two</td><td>Three</td></tr>
<tr>
<td width="45%" colspan="2" style="padding-left: 6%">
<input type="checkbox" /><label>Checkbox</label>
</td>
<td>
<input type="checkbox" /><label>Checkbox</label>
</td>
</tr>
<tr>
<td width="6%"></td> <!---- I want to get rid of this! -->
<td width="45%">
<input type="checkbox" /><label>Checkbox</label>
</td>
<td>
<input type="checkbox" /><label>Checkbox</label>
</td>
</tr>
</table>
</body><html>
Not sure if you'll find this acceptable, but you could keep the <td width="6%"></td> and give it a huge rowspan value. So like this:
<td width="6%" rowspan="999999"></td>
Then you can omit the empty <td></td> for the first 999999 rows. Most likely you have fewer rows than that; or if not, just make the rowspan even higher. The table will not become longer just because of the huge rowspan value.
Of course this all breaks down if you also have rows where the indent should not be applied; a fix for that could be to calculate the exact rowspan value in advance.
I have a HTML table in which a background color is set on each cell. As a result, the contrast between two bg colors appears as a border. Please refer to accepted solution at
Borders around every cell and table
This is a follow up question.
Now I need to include bootstrap in my application. However, as soon as I include bootstrap CSS the border appearance disappears (even if I don't include any bootstrap class). How can I include bootstrap and still have a border like appearance around each cell.
Here is the fiddle with bootstrap included
https://jsfiddle.net/hqkw4x1s/1/
and below is the original code, without reference to bootstrap css (this gives a border like appearance due to bgcolors)
.lab {
HEIGHT: 18px; FONT-WEIGHT: normal; TEXT-ALIGN: left; PADDING-LEFT: 4px; PADDING-RIGHT: 3px; BACKGROUND-COLOR: #e6f6f6
}
.val {
PADDING-BOTTOM: 1px; PADDING-TOP: 1px; PADDING-LEFT: 2px; PADDING-RIGHT: 3px; BACKGROUND-COLOR: white
}
<FORM>
<DIV>
<TABLE width="100%" bgColor=#cecece border=0 cellSpacing=1 cellPadding=0>
<TBODY>
<TR vAlign=middle>
<TD width="6%" class=lab>Country</TD>
<TD width="44%" class=val>
<INPUT name="A" id="A" type=checkbox CHECKED>
<LABEL for="A">A</LABEL>
<INPUT name="B" id="B" type=checkbox CHECKED>
<LABEL for="B">B</LABEL>
</TD>
<TD width="6%" class=lab>States</TD>
<TD width="44%" class=val>
<TABLE width="100%" border=0 cellSpacing=0 cellPadding=0>
<TBODY>
<TR>
<TD>
<SELECT>
<OPTION value="p" selected>P</OPTION>
<OPTION value="q">Q</OPTION>
<OPTION value="r">R</OPTION>
</SELECT>
</TD>
</TR>
</TBODY>
</TABLE>
</TD>
</TR>
<TR vAlign=middle>
<TD class=lab>Ownership</TD>
<TD class=val>
<TABLE width="100%" border=0 cellSpacing=0 cellPadding=0>
<TBODY>
<TR>
<TD><TEXTAREA style="WIDTH: 95%" rows=1 cols=20></TEXTAREA></TD>
<TD style="WIDTH: 75px; TEXT-ALIGN: left"><SPAN
style="BACKGROUND-COLOR: #f8f8f8"></SPAN>
</TD>
</TR>
</TBODY>
</TABLE>
</TD>
<TD class=lab>Partnership</TD>
<TD class=val><INPUT type=text xHeight="32px"> </TD>
</TR>
<TR vAlign=middle>
<TD class=lab>Accounts Payable</TD>
<TD
style="PADDING-LEFT: 2px; PADDING-RIGHT: 3px; BACKGROUND-COLOR: white">
<INPUT type=text>
</TD>
<TD class=lab>Start Date</TD>
<TD class=val>
<INPUT type=text xHeight="32px">
</TD>
</TR>
</TBODY>
</TABLE>
</DIV>
</FORM>
Please update below table tag.Here you just need to use the bootstrap standard class to achieve this.
Instead
<table width="100%" bgcolor="#cecece" border="0" cellspacing="1" cellpadding="0">
Should be:
<table class="table table-bordered" width="100%" bgcolor="#cecece" border="0" cellspacing="1" cellpadding="0">
The rest of my page conforms to the container width which would be equal to the top line and the bottom line of this midBodyWrapper but these boxes won't lay out side by side. I'm not sure what's going on but I've tried some inline styles too but nothing works. Please see picture attached. Thank you for your help.
<table id="midBodyWrapper" border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody><tr>
<td class="subHeader" width="35%"><br>I Mainly Shop For:
</td>
</tr>
<tr>
<td class="checks2">
<div>
<table cellpadding="0" cellspacing="0">
<tbody><tr valign="middle">
<td></td>
<td></td>
</tr>
</tbody></table>
<input type="checkbox" name="CheckBox.A address.Men's Clothing">Men's Clothing<input type="hidden" name="CheckBox.A address.Men's Clothing" value="off">
</div>
<div>
<table cellpadding="0" cellspacing="0">
<tbody><tr valign="middle">
<td></td>
<td></td>
</tr>
</tbody></table>
<input type="checkbox" name="CheckBox.A address.Women's Clothing">Women's Clothing<input type="hidden" name="CheckBox.A address.Women's Clothing" value="off">
</div>
<div>
<table cellpadding="0" cellspacing="0">
<tbody><tr valign="middle">
<td></td>
<td></td>
</tr>
</tbody></table>
<input type="checkbox" name="CheckBox.A address.Boy's Clothing">Boy's Clothing<input type="hidden" name="CheckBox.A address.Boy's Clothing" value="off">
</div>
</td>
</tr>
</tbody></table>
#midBodyWrapper {
border: 1px solid #bbb;
border-left: 0;
border-right: 0;
padding: 30px 0;
margin: 40px 0;
}
It's also a responsive page so i think for some reason it's stuck in it's responsive smaller squished form. Because this would be how it's suppose to look on mobile, kind of.
To display your elements in one row, you need to apply the following property:
td div {
display: inline-block;
}
or
td div {
float: left;
}
Demo
I'm trying to change the standard checkboxes to a font-awsome version.
The problem is I can't change the HTML since it's generated and I can't use jQuery either.
Is there a way to "find" the label for my checkbox in the html below and change label:before on checkbox true or false?
EDIT: I think I might have been a bit unclear, the full code includes a javascript that makes it impossible for me to use javascript without changing it.
Also, the class for the labeltext is commonly used and can be -1 or -2 as well.
<table cellpadding="0" cellspacing="0" class="odincategory odincategory38 odincategory-even odincategory-placement2 odincategory-placement-even odincategory-multi" id="odincategory38-holder">
<tbody>
<tr>
<td class="odincategorycheckcolumn">
<input type="checkbox" name="odinanswer1" value="38" class="odincategorycheckmulti" id="odincategory38">
</td>
<td class="odincategorylabelcolumn">
<table cellpadding="0" cellspacing="0" id="odincategorylabel38">
<tbody>
<tr>
<td class="odincategorylabel">
<label for="odincategory38"><span class="odinfontnumber-0">Choice<br>
</span></label>
</td>
</tr>
</tbody>
</table>
</td>
<td class="odincategorymarkcolumn"></td>
</tr>
</tbody>
</table>
This cannot be done using pure CSS.
The problem is that you can only select adjacent, following or descending elements. In your case the label is somewhere else in the document tree.
If you could have the label next to the checkbox you could do something like
input[type=checkbox] + label {
color: green;
}
input[type=checkbox]:checked + label {
color: red;
}
But this does not work with your code.
Try this sample that change the color of the label...
In the same way you can change what you need.
In this example I used a button but you can write a special function that changes the font after page is loaded
<table cellpadding="0" cellspacing="0" class="odincategory odincategory38 odincategory-even odincategory-placement2 odincategory-placement-even odincategory-multi" id="odincategory38-holder">
<tbody>
<tr>
<td class="odincategorycheckcolumn">
<input type="checkbox" name="odinanswer1" value="38" class="odincategorycheckmulti" id="odincategory38">
</td>
<td class="odincategorylabelcolumn">
<table cellpadding="0" cellspacing="0" id="odincategorylabel38">
<tbody>
<tr>
<td class="odincategorylabel">
<label for="odincategory38" id="labelForodincategory38"><span class="odinfontnumber-0">Choice<br>
</span></label>
</td>
</tr>
</tbody>
</table>
</td>
<td class="odincategorymarkcolumn"></td>
</tr>
</tbody>
</table>
<input type="button" onclick="document.getElementById('labelForodincategory38').style.color='blue'" value="Click Me to Change Color" />
I create the table like this.
<table border="1">
<tr>
<td width="250px" rowspan="2"><input type="image" src="dash.jpg" name="image" style=width:50% height="100"> </td>
<td width="1100px" align="center" valign ="top"><div id="head1" style="font-size: 55px;letter-spacing:3px">Sample programming html</div></td>
<td width="300px" align="center" valign ="top"><span id="subhead1" style="font-size: 25px;letter-spacing:3px">Chap: <label id = "l1" style = "color:white;font:normal 22px chalkdust;">1</label></span><br>
<span id="subhead2" style="font-size: 30px;letter-spacing:3px"> <input type="text" id="text2" disabled="disabled" value="0" style= "color: #fff; font-size: 18pt;"/> - POINT</span>
</td>
</tr>
<tr>
<td colspan="3" align="center" style="position: relative;" valign ="top">
<div id="head2" style="font-size: 25px;letter-spacing:4px">1-COORDINATE GRID</div></td>
</tr>
<tr><td colspan="3" align="center"><hr id="line" color="#fff" size="2" width="75%"></td></tr>
</table>
I want the content "Sample programming html" in center and the "1-COORDINATE GRID" is exactly center to that of the content. I use various code but it not allign exactly to the center of the "Sample programming html". Can anybody help this to fix the problem.
your td cells are differnt width ,if you want adjust the text alignment yourself you might use
left or right padding css property.
<div id="head2" style="padding-left:250px..../>
Just remove the colspan="3" from the row and it get alligned.
<tr>
<td align="center" style="position: relative;" valign ="top">
<div id="head2" style="font-size: 25px;letter-spacing:4px">1-COORDINATE GRID</div></td>
</tr>