- This topic is empty.
-
AuthorPosts
-
April 22, 2013 at 10:33 am #44297
Yonikenneth
MemberHey!
I have a table like this:
label 1 content 2 label 3 content 4 And I want to have a background color on hover per two td’s (label + content). The problem is, when you hover nth-child(2), :first-child doen’st get the same background because there is no going back or up in CSS.
Anybody have an idea how to solve this?
Thanks!
April 22, 2013 at 10:47 am #132719Senff
ParticipantNot sure if this is what you mean?
April 22, 2013 at 11:42 am #132731Yonikenneth
MemberNo that’s not it.
See my example of how it should be. The different colors respresent the hover areas.
http://i36.tinypic.com/zmgocn.png
Thanks!
April 22, 2013 at 11:49 am #132733Paulie_D
MemberHow is this table structured?
April 22, 2013 at 11:51 am #132736Senff
ParticipantHmmm… this then? http://www.codepen.io/senff/pen/BsJmc (pen updated)
April 22, 2013 at 12:01 pm #132737Paulie_D
MemberI’m thinking it’s more like this: http://www.codepen.io/anon/pen/iaGoI
Still can’t work the hover on the ‘even’ items because (as has been said) you can’t select a parent.
JS the answer I feel.
April 22, 2013 at 12:07 pm #132738CrocoDillon
Participant> JS the answer I feel.
Or not using a table.
April 22, 2013 at 12:13 pm #132740Paulie_D
MemberWell, on looking at the image, it is **kinda** tabular data.
I certainly could be done in other ways which might make it easier but there would still be the selecting the ‘previous’ element issue.
April 22, 2013 at 12:21 pm #132741CrocoDillon
ParticipantIt could be tabular data (if there were more then one entity), but then the rows would be entities and the columns would be labeled by a header. Not sure but it doesn’t seem like semantic use of tables how it is now.
April 22, 2013 at 12:23 pm #132742Senff
ParticipantYea, if it HAS to be one table and nothing else, JS is the answer.
However if the table cells are allowed to have elements (either another table, or divs) then it can be done without JS.
April 22, 2013 at 12:28 pm #132744CrocoDillon
ParticipantIf it HAS to be a table the structure would be something like this to be any semantic:
`
City Country Company department Hours per week Salary Startdate Enschede German Business to Trade 40 Millions 01-06-2013 `
Is it possible to style this to look like the image?
April 22, 2013 at 12:54 pm #132750Yonikenneth
MemberSorry about that, forgot to post the link.
Here you go: http://www.cygnific.com/vacancies/customer-contact-representative-german/
April 22, 2013 at 1:17 pm #132756Yonikenneth
Member@Paulie_D This looks good! It may be the solution, thanks! I’ll try implementing this.
@Senff, @CrocoDillon Yes it HAS to be a table, as for the table is being filled by a CMS.I also tried jQuery:
$(document).ready(function() {
$("tr > td").hover(function() {
$(this).toggleClass("active");
});
$("tr > td").hover(function() {
$(this).next("td").toggleClass("next");
});
$("tr > td").hover(function() {
$(this).prev("td").toggleClass("prev");
});
});
April 22, 2013 at 1:35 pm #132758Yonikenneth
Member@Paulie_D your solutions is coming close, but it taking your codepen as example, try hovering over the “content” td’s – there’s the problem… it does’nt get the same background color.
So this is where it gets interesting! I think with the script in my previous post the solution is within arms reach.
April 22, 2013 at 1:56 pm #132760CrocoDillon
ParticipantIf you’re going with jQuery: http://codepen.io/anon/pen/ufilE
-
AuthorPosts
- The forum ‘CSS’ is closed to new topics and replies.