I have a table column and there are other divs inside of this table column. On mouse hover, I want to highlight all of the content (multiple divs inside the ). I have got this working but here is the problem.
The also has some padding from 4 sides. When I apply the CSS :hover effect, I don't want the padding area to be affected. Rather, everything else inside the div excluding the padding area should be highlighted.
Here is the html
<table id="MyTable">
<tr>
<td style="padding:120px;">
<div>SomeStuff</div>
<div>SomeMoreStuff</div>
</td>
</tr>
</table>
And here is the css
#MyTable td { /* added only for visualisation */
border:1px solid red;
}
#MyTable td:hover {
background: black;
}
JsFiddled here
Working fiddle: http://jsfiddle.net/9zzcY/
Change the HTML to:
<td style="padding:20px;">
<div class="tdContentWrapper">
<div>SomeStuff</div>
<div>SomeMoreStuff</div>
</div>
</td>
Change the CSS to:
#MyTable .tdContentWrapper:hover{
background: black;
}
Change your style declaration to :
td:hover div {
Try this
td:hover div{
//your code here
}
Try inserting an inner markkup to your design witch will not overflow the padding.
<table id="MyTable">
<tr>
<td style="padding:120px;">
<div class="inner-td">
<div>SomeStuff</div>
<div>SomeMoreStuff</div>
</div>
</td>
</tr>
</table>
And apply styling to the 'inner-td' divider on the td:hover
jsFiddle updated here
#MyTable td { /* added only for visualisation */
border:1px solid red;
}
#MyTable td:hover .inner-td {
background: black;
}
Also, Note that :hover on anything other than <a> elements is not fully supported in many older browsers.
Related
So I want to select a specific table row and change the background color. I know I can code it via html. But I would rather do it through CSS. I tried giving the table row a class name, but it still wont change the background color. I'm trying to change the background of the class "update". https://jsfiddle.net/q0395cyc/
<table class="table3">
<tbody>
<tr class="update">
<td >
FUNDRAISING UPDATE: $2.5 million in commited capital
</td>
</tr>
First fix your HTML syntax errors (unclosed tbody, tables etc...)
TR are not meant for design. Forget they exist.
TRs are just a way to tell the browser where your TDs group spans/ends.
Style the inner TD instead
.update td {
background: red;
}
Example trying to style TR:
tr.styled{
background: red; /* will become red but... don't. */
border-radius: 10px; /* this will not work */
padding: 10px; /* neither will this */
/* neither many other styles here */
}
<table>
<tr class="styled">
<td>Special offer</td>
</tr>
</table>
Styling inner TD:
tr.styled td{
background: red;
border-radius: 5px;
padding: 10px;
}
<table>
<tr class="styled">
<td>Special offer</td>
</tr>
</table>
I use Bootstrap framework.
I have HTML code:
<table class="table">
<tbody>
<tr>
<td class="non-border">First case</td>
</tr>
<tr>
<td style="border-style:none">Second case</td>
</tr>
</tbody>
</table>
And CSS code:
.non-border { border-style: none; color: red }
Why for the first case class "non-border" doesn't remove the top-border of td (for left, right and bottom border it works; CSS works because color changes for red)?
For the second case (style) all borders of td are removed.
What should I do to get working "border-style: none" of td by class?
Thank you in advance.
Use !important. Like so:
.non-border {
border-style: none !important;
color: red;
}
All styles are cascaded, but inline styles are given the highest preference. In your case, class .non-border is getting lower preference than twitter-bootstrap's predefined styles.
I am trying to change the background color of my whole tbody using CSS and :hover. When a background is already set, I cannot make the hover background change. I simply cannot. I even tried with !impotant but without luck.
<table border="1">
<tbody>
<tr>
<th>Testing</th>
<td>Some stuff</td>
</tr>
<tr>
<th>Testing</th>
<td>Second more stuff</td>
</tr>
</tbody>
</table>
My CSS
th {
background: red;
}
tbody:hover {
background: blue !important;
}
http://jsfiddle.net/W4cJh/1/
As you can see, the hover works fine if the background has not been set. Remove the background: red from the th-tag, to see that it works without a preset color.
This will do the work for you, no need for !important:
th {
background: red;
}
tbody:hover,
tbody:hover th {
background: blue;
}
Demo: http://jsfiddle.net/W4cJh/4/
That's because the TH is a child of the table, and so is technically on top of it. By setting the TABLE background to blue, it does not override the TH background.
To fix this, add this:
tbody:hover th {
background: blue;
}
(and you can skip the !importants. Those are bad practice.)
Example fiddle is here.
I am trying to show a checkmark in the top right corner of a td. I can't seem to get it there without expanding the whole tr. This is my table:
<tr style="position:relative;>
<td><p class="mark" style="position:relative; left:10px;></p><input type="text"></td> <-- in this td the icon should be placed.
...more rows...
</tr>
I just tried using a class for the icon and making the tr relative and the td relative but it keeps expanding the td's height.
Any ideas?
You can use first-child selector and background-position attribute to show icon on right top of first td
tr:first-child td:first-child
{
background-image:url('http://files.softicons.com/download/toolbar-icons/iconza-light-green-icons-by-turbomilk/png/32/check_mark.png');
background-position:right top;
background-repeat:no-repeat;
padding-right:35px;
padding-top:5px;
padding-bottom:5px;
}
You can shorten this like
tr:first-child td:first-child
{
background:url('http://files.softicons.com/download/toolbar-icons/iconza-light-green-icons-by-turbomilk/png/32/check_mark.png') no-repeat right top red;
padding:5px 35px 5px 0
}
JS Fiddle Demo
Since you cannot use a position rule on table cells (prohibited by standards, only strictly enforced by Gecko) you have to use a workaround with another element inside, or use some other solution. Also you shouldn't be generating images for 'semantic' stuff like this, use classes, makes it both easier to generate, and easy to manipulate with JS.
HTML
<table>
<tr>
<td class="checked">...data 1...<br>multiline</td>
</tr>
<tr>
<td>...data 2...</td>
</tr>
<tr>
<td class="checked">...data 3...</td>
</tr>
</table>
CSS
td{
background:#fcf4cf;
}
td.checked:before {
content:url(http://www.kyoceradocumentsolutions.com.au/Style%20Library/en-us/Images1/TickMark.gif);
float:right;
padding-left:4px;
}
See this work on JSFiddle
This is compatible with all major browsers and semantically more correct than your current approach, with shorter CSS and HTML.
I need help in this:
if i try to integrate this on a newsletter mailchimp the lines goes down here is the screenshot:
http://i197.photobucket.com/albums/aa253/tintingerri/Test/pic4.png
can someone help me why is this happening?
if I test this in a textpad it looks good, and if I try to put the code now in mailchimp, it the lines are reformatted. any idea?
thanks
Add
border-top: 1px solid #000;
To the style attribute for the <td> tags.
You can change the color to anything you want obviously and you may want to look into using external CSS stylesheets.
Something like:
td { border-top:2px solid #fb0 }
td { padding-left:25px; padding-bottom:10px; padding-top:10px; width: 30% }
tr.alt { background: #ffc }
the row to have the background will use
<tr class="alt">
it is also common practice to put all the style in a css file or in the separate <style> tag region.
sample: http://jsfiddle.net/2LXUn/2/
If you want a table, with only border at the top, the following will work.
<table style="border-color:#008000;border-style: solid none none none;border-width:2px; width: 100%">
<tr> <td > row1</td>
</tr> <tr >
<td>row2</td> </tr>
</table>
You may also apply the border style to table rows as required.