Stylize only input text fields of table rows with differrent colours - html

I would like to stylize every row input text field with different colour per row, following the schema of :odd :even pseudo classes. The problem is that the nth-of-child(N) doesn't provide me the correct result. It rather make all input field with the same colour. Please advise!
input[type=text]:nth-last-child(even){
width:150px;
display:block;
background:#ccc;
border: 1px solid #999;
height: 25px;
-webkit-box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.3);
-moz-box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.3);
box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.3);
}
input[type=text]:nth-last-child(odd){
width:150px;
display:block;
background:#0F9;
border: 1px solid #999;
height: 25px;
-webkit-box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.3);
-moz-box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.3);
box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.3);
}
AND THE HTML CODE :
<form name="form1" method="post" action="" >
<table width="500" border="0" cellspacing="1" cellpadding="0">
<?php while ($rows = mysql_fetch_array($result)) : ?>
<tr>
<td align="center">
<?php
$id[] = $rows['id'];
echo $rows['id'];
?>
<input type="hidden" name="id[]" value="<?php echo $rows['id']; ?>" />
</td>
<td align="center">
<input name="name[]" type="text" id="name" value="<?php echo $rows['name']; ?>" />
</td>
<td align="center">
<input name="lastname[]" type="text" id="lastname" value="<?php echo $rows['lastname']; ?>" />
</td>
<td align="center">
<input name="email[]" type="text" id="email" value="<?php echo $rows['email']; ?>" />
</td>
</tr>
<?php endwhile; ?>
<tr>
<td colspan="4" align="center"><input type="submit" name="submit1" value="ΕΝΗΜΕΡΩΣΗ"></td>
</tr>
</table>
</td>
</tr>
</table>
</form>

Set the :nth-child(even) on the <td>, not on your <input>. In your code the <input> is always the first child because it is wrapped inside a <td>.
Example:
td:nth-last-child(even) input[type=text]{
background:#ccc;
}
Fiddle:
http://jsfiddle.net/sfpK8/3/

Your inputs are placed in a <td>, so input[type=text]:nth-last-child(even) triggers just once on a one input.
Do it in that way:
td:nth-child(even) input[type=text] {
//your styles for even
}
Also you don't have to apply styles to odd elements, just make default styles for all inputs, and then add styles for even:
input[type=text] {
//style#1
}
td:nth-child(even) input[type=text] {
//style#2
}

Related

How to remove padding (cellpadding) from the <td> element?

I am building a simple calculator using HTML, CSS, and JS. My question is how to remove the padding of the element inside my calculator table.
Visuals
To remove spacing between elements in HTML, googling suggests adding the attributes cellspacing="0" cellpadding="0" to the element, which I did. It also suggests adding a CSS selector table { border-collapse: collapse}. However, border-collapse does not work as I expected: the padding does not get removed, and the table corners become wrecked.
/* Global CSS */
*,
*::before,
*::after {
box-sizing: border-box;
}
:root {
--calc-bg: rgb(184, 243, 216);
--btn-bg: rgb(252, 246, 230);
--active-btn-bg: rgb(106, 200, 153);
--main-btn-bg: rgb(71, 202, 143);
--text-color: rgb(45, 53, 44);
--display-bg: rgb(252, 246, 230);
}
/* Calculator CSS */
#import url('https://fonts.googleapis.com/css2?family=Source+Code+Pro:wght#900&display=swap');
.calculator {
font-family: 'Source Code Pro', monospace;
font-weight: 900;
padding: 10px;
border-radius: 2em;
height: 580px;
width: 500px;
margin: auto;
background-color: var(--calc-bg);
border: solid rgb(45, 52, 42) 5px;
-webkit-box-shadow: 3px 3px 0px 2px rgb(45, 52, 42);
-moz-box-shadow: 3px 3px 0px 2px rgb(45, 52, 42);
box-shadow: 3px 3px 0px 2px rgb(45, 52, 42);
}
.display-box {
background-color: var(--display-bg);
border: solid black 0.5px;
color: black;
border-radius: 1em;
width: 100%;
height: 80px;
-webkit-box-shadow: 3px 3px 0px 2px rgb(45, 52, 42);
-moz-box-shadow: 3px 3px 0px 2px rgb(45, 52, 42);
box-shadow: 3px 3px 0px 2px rgb(45, 52, 42);
}
#btn {
background-color: var(--main-btn-bg);
}
th,
td {
padding: 0;
}
td {
text-align: center;
vertical-align: middle;
}
input[type=button] {
font-weight: 900;
background-color: var(--btn-bg);
color: var(--text-color);
border: solid rgb(45, 52, 42) 2px;
width: 4rem;
border-radius: 10%;
height: 4rem;
outline: none;
-webkit-box-shadow: 3px 3px 0px 2px rgb(45, 52, 42);
-moz-box-shadow: 3px 3px 0px 2px rgb(45, 52, 42);
box-shadow: 3px 3px 0px 2px rgb(45, 52, 42);
}
input:active[type=button] {
background: var(--active-btn-bg);
transition-duration: 100ms;
transition-timing-function: ease-out;
<table class="calculator" cellspacing="0" cellpadding="0">
<tr>
<td colspan="3"> <input class="display-box" type="text" id="result" disabled /> </td>
<!-- clearScreen() function clears all the values -->
<td> <input type="button" value="C" onclick="clearScreen()" id="btn" /> </td>
</tr>
<tr>
<!-- display() function displays the value of clicked button -->
<td> <input type="button" value="1" onclick="display('1')" /> </td>
<td> <input type="button" value="2" onclick="display('2')" /> </td>
<td> <input type="button" value="3" onclick="display('3')" /> </td>
<td> <input type="button" value="/" onclick="display('/')" /> </td>
</tr>
<tr>
<td> <input type="button" value="4" onclick="display('4')" /> </td>
<td> <input type="button" value="5" onclick="display('5')" /> </td>
<td> <input type="button" value="6" onclick="display('6')" /> </td>
<td> <input type="button" value="-" onclick="display('-')" /> </td>
</tr>
<tr>
<td> <input type="button" value="7" onclick="display('7')" /> </td>
<td> <input type="button" value="8" onclick="display('8')" /> </td>
<td> <input type="button" value="9" onclick="display('9')" /> </td>
<td> <input type="button" value="+" onclick="display('+')" /> </td>
</tr>
<tr>
<td> <input type="button" value="." onclick="display('.')" /> </td>
<td> <input type="button" value="0" onclick="display('0')" /> </td>
<!-- calculate() function evaluates the mathematical expression -->
<td> <input type="button" value="=" onclick="calculate()" id="btn" /> </td>
<td> <input type="button" value="*" onclick="display('*')" /> </td>
</tr>
</table>
} ```
Changing the width and height of the table and its elements, along with using border-collapse: collapse and border-spacing: 0 helped to solve the issue

Set TD Width To Width Of Largest Span

I am currently having an issue with TD widths; no matter the length of the spans within the TD elements, it stays a consistent width. I need the TD elements to be completely resized to the width of the longest span element contained within the same column.
.Form {
width: 100%;
}
.Form td {
border: 1px solid black;
}
.Form td > span {
font-weight: bold;
}
.Form td > input[type="text"] {
border-radius: 3px;
box-shadow: -2px 2px 5px 0px rgba(0, 0, 0, 0.4);
width: 99%;
}
<table class="Form">
<tr><td colspan="6"><h3>Some super header text with useful information.</h3></td></tr>
<tr><td colspan="6"><h3>Other useful information.</h3></td></tr>
<tr>
<td><span>LONGEST EVER</span></td>
<td colspan="2"><input type="text" id="txtPOC" runat="server" /></td>
<td><span>Phone</span></td>
<td colspan="2"><input type="text" id="txtPhone" runat="server" /></td>
</tr>
<tr>
<td><span>Short</span></td>
<td colspan="2"><input type="text" id="txtOrg" runat="server" /></td>
<td><span>E-Mail</span></td>
<td colspan="2"><input type="text" id="txtMail" runat="server" /></td>
</tr>
</table>

HTML table data adding weird padding

I have a table with some table data, I'm using inline styles because I want the html to work in an email. But it seems the table data is adding padding to where the images are, I tried using border-collapse: collapse, and everything, but still that little 3 or 4 px padding goes onto the bottom of images in the table data. Here is code for reference:
<!DOCTYPE html>
<html lang="en">
<body>
<table style="background: #E6E6E6; ">
<tr><td style="padding-left:18%;">
<!--one main column in a nested table-->
<table >
<tr><td><p style="text-align: center; font-size: 11px; color: grey;">There’s never been a better time to use the Hulu Plus App on your PS3 » | View as Web page </p></td></tr>
<tr><td><img src="pics/psnetworkheader.png" /></td></tr>
<tr style="background-image: url('pics/topGreyBack.png'); background-repeat:no-repeat;"><td style="padding-left:35px;">
<table><tr style="padding-top:35px;"><!--one row, two td columns and nested table-->
<td style="padding-right: 60px; padding-top: 40px; width:30%;" ><!--left column in grey block-->
<img src="pics/huluImg.png" style="box-shadow: 0 0 6px #eee;"/>
<p style="color: #F2F2F2; margin-top: 20px; font-size: 12px; ">The Hulu Plus App on the PS3 features an updated experience with a new layout and intuitive controls. Watch Fall Premieres, stream current hit TV shows
and classic series all from your PS3.</p>
<p style="color: #F2F2F2; margin-top: 20px; font-size:12px;">Not a member? Get a <b>FREE MONTH</b>
of unlimited instant streaming.
<br/>Your promo code is: <b>XXXXXXXXX</b>
</p>
› Try 1 Month Free
<p style="color: #F2F2F2; margin-top: 9px; font-size:9px;">Expires 10/20/12. You must be a new subscriber to receive this offer. </p>
</td>
<td >
<img src="pics/tvImg.png"/>
</td>
</tr></table> <!--end row in grey block-->
</td></tr><!--end grey block-->
<table style="margin-left:2px; width: 720px;">
<tr style="padding-top:35px; "><td style="width:50%;padding-left: 35px; padding-right: 20px;">
<h3>Hulu Plus, its TV on your terms. </h3>
<p><small>With the Hulu Plus app you can watch your favorite shows right on your PS3. From current seasons to the classics, it’s all yours for only $7.99 a month.</small></p>
<ul style="font-size: 13px;">
<li>Easily scroll through popular shows and movies, clips, movie trailers, and personalized recommendations.</li>
<li>Use the new enhanced search function and Shows You Watch feature which highlights the content you regularly enjoy so you can jump straight to the latest episode.</li>
</ul>
</td><!--end first td-->
<td style="padding-left: 55px; padding-top: 40px;">
<table style="border-spacing:10px; ">
<tr>
<td style="padding:0px;-webkit-box-shadow: 2px 4px 30px -7px rgba(0,0,0,0.75);
-moz-box-shadow: 2px 4px 30px -7px rgba(0,0,0,0.75);
box-shadow: 2px 4px 30px -7px rgba(0,0,0,0.75); ">
<img src="pics/mofa.png"/>
</td>
<td style="padding:0px;-webkit-box-shadow: 2px 4px 30px -7px rgba(0,0,0,0.75);
-moz-box-shadow: 2px 4px 30px -7px rgba(0,0,0,0.75);
box-shadow: 2px 4px 30px -7px rgba(0,0,0,0.75);">
<img src="pics/grimm.png"/>
</td>
</tr>
<tr >
<td style="-webkit-box-shadow: 2px 4px 30px -7px rgba(0,0,0,0.75);
-moz-box-shadow: 2px 4px 30px -7px rgba(0,0,0,0.75);
box-shadow: 2px 4px 30px -7px rgba(0,0,0,0.75);">
<img src="pics/snl.png"/>
</td>
<td style="-webkit-box-shadow: 2px 4px 30px -7px rgba(0,0,0,0.75);
-moz-box-shadow: 2px 4px 30px -7px rgba(0,0,0,0.75);
box-shadow: 2px 4px 30px -7px rgba(0,0,0,0.75);">
<img src="pics/americandad.png"/>
</td>
</tr>
<tr >
<td style="-webkit-box-shadow: 2px 4px 30px -7px rgba(0,0,0,0.75);
-moz-box-shadow: 2px 4px 30px -7px rgba(0,0,0,0.75);
box-shadow: 2px 4px 30px -7px rgba(0,0,0,0.75);">
<img src="pics/community.png"/>
</td>
<td style="-webkit-box-shadow: 2px 4px 30px -7px rgba(0,0,0,0.75);
-moz-box-shadow: 2px 4px 30px -7px rgba(0,0,0,0.75);
box-shadow: 2px 4px 30px -7px rgba(0,0,0,0.75);">
<img src="pics/familyguy.png"/>
</td>
</tr>
<tr >
<td >
<img src="pics/theoffice.png"/>
</td>
<td >
<img src="pics/naruto.png"/>
</td>
</tr>
<tr >
<td >
<img src="pics/newgirl.png"/>
</td>
<td >
<img src="pics/once.png"/>
</td>
</tr>
</td></tr>
<!--end white block row-->
</table><!-- end white block-->
<!--one big column-->
</table>`enter code here`
</tr></td>
</table> <!--container-->
</body>
</html>
Your images should have inline CSS for display: block;. So something like this:
<img src="pics/huluImg.png" style="box-shadow: 0 0 6px #eee;"/>
Will be this:
<img src="pics/huluImg.png" style="box-shadow: 0 0 6px #eee; display: block;"/>

CSS : Border in IE8

I have dialog with html :
<div id="sample">
<div class="sample-wraper">
<a class="modal_close" href="#"></a>
<form id="Form1" name="Form1" method="post">
<table id="tt">
<tr align="center">
<td colspan="2" id="naam"><b>Cha test</b></td>
</tr>
<tr>
<td colspan="2">
<div id="boodschap" class="text" style="border-right: 1px solid; border-top: 1px solid; overflow: auto;
border-left: 1px solid; width: 468px; height: 182px; border-bottom: 1px solid;
background-color: white">njnknkkm</div>
</td>
</tr>
<tr>
<td colspan="2">
<textarea id="antwoord" name="antwoord" class="text"
style="width: 465px; height: 182px; border-width: 1px; border-style: solid; border-color: black;"
onkeydown="textCounter(antwoord,aantal,1000)"
onkeyup="textCounter(antwoord,aantal,1000)"></textarea>
</td>
</tr>
<tr>
<td class="text" align="left" width="210">
Caráters permitidas
<input readonly type="text" name="aantal" size="3" maxlength="4" value="1000" id="aantal"></td>
<td align="right">
<input id="Submit" name="Submit" type="button" value="Enviar" onclick="submitForm();"
class="button" style="width: 130px">
</td>
</tr>
</table>
<input id="IdTo" name="IdTo" type="hidden">
</form>
</div>
and css like this :
#sample {
background: none repeat scroll 0 0 #FFFFFF;
border-radius: 5px;
box-shadow: 0 0 4px rgba(0, 0, 0, 0.7);
border: 1px solid;
display: none;
padding: 15px 10px 10px;
position:absolute !important;
}
.modal_close {
background: url("Close-icon-download-182005456677-png/button.png") no-repeat scroll 0 0 rgba(0, 0, 0, 0);
filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='Close-icon-download-182005456677-png/button.png',sizingMethod='scale');
-ms-filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='Close-icon-download-182005456677-png/button.png',sizingMethod='scale')";
display: block;
height: 20px;
position: absolute;
right: 10px;
top: 10px;
width: 20px;
z-index: 2;
}
Problem is that in IE8 on this dialog in top-left corner i get some square, which disappears if i remove border from dialog (#sample).
http://clip2net.com/s/i6klpi (sample of problem)
In IE7 and IE9 i didn't get this "feature" in corner.
I found this post about problem with IE borders http://www.brasee.com/displayPost.htm?postId=64. As my dialog is with position absolute (this is for not moving dialog when scrolls) i add wrapper of this dialog. So i set for dialog position relative and for wrapper position absolute. But this also didn't help. Get this result: clip2net.com/s/i6lcKz

CSS/HTML: Input fields not using CSS styles

I want to style the text input areas on my form, however when I create a style for input in css, it does not actually style the input box. I have been able to style my button, just not input boxes.
<div class="loginContainer">
<form action ="" method="post">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<label for="username" class="label">Username</label>
</td>
<td width="150">
<input type="text" name="username" size="25" id="username" autocomplete="off" />
</td>
</tr>
<tr>
<td>
<label for="password" class="label">Password</label>
</td>
<td width="150">
<input type="password" name="password" size="25" id="password" autocomplete="off" />
</td>
</tr>
<input type="hidden" name="token" value="<?php echo Token::generate(); ?>">
<tr>
<td>
<label for="remember">
<input type="checkbox" name="remember" id="remember"> Keep me signed in
</td>
</tr>
<tr>
<td>
<input type="submit" class="submit" value="Log in">
</td>
</tr>
</table>
</form>
And here is the CSS for it:
input[type="text"] {
padding: 4px;
border-radius: 4px;
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
box-shadow: 0px 0px 8px #d9d9d9;
-moz-box-shadow: 0px 0px 8px #d9d9d9;
-webkit-box-shadow: 0px 0px 8px #d9d9d9;
display: block;
}
This ends up creating a form which creates: http://i.imgur.com/9Hj9Vie.png
Note the lack of style on the input fields. How should I go about fixing this?
It's kind of strange that the border radius is not applied, you can try the following ( note the lack of quotes ):
input[type=text] {
padding: 4px;
border-radius: 4px;
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
box-shadow: 0px 0px 8px #d9d9d9;
-moz-box-shadow: 0px 0px 8px #d9d9d9;
-webkit-box-shadow: 0px 0px 8px #d9d9d9;
display: block;
/* new stuff */
border: 1px solid pink;
outline: 1px solid green;
background: orange;
}
If you want the for the password field also to be styled you need to add that tag in the style as well, like this:
input[type=text], input[type=password] {
padding: 4px;
border-radius: 4px;
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
box-shadow: 0px 0px 8px #d9d9d9;
-moz-box-shadow: 0px 0px 8px #d9d9d9;
-webkit-box-shadow: 0px 0px 8px #d9d9d9;
display: block;
}