Is it possible to give each record a differant css class?

General Tech Learning Aids/Tools 2 years ago

0 1 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on Learning Aids/Tools related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (1)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago

 

Is there any way to give each record in a table its own css class? Im displaying records as partials but would like to be able to give each partial its own individual css attributes. Maybe a way of assigning css rules by a div's name and id of the record combined?

EDIT

Sorry for the poorly written question I'll try and explain in more detail.

I have a table of venue records being displayed on the index page in partials and want each one to have an icon placed on a map off to the left side of the screen (map_container). The map is just a hand drawn image as the background of a fixed width and height div.

Venue index.html.erb:

 class="map_container">
class="filter_options_container"> class="filter_form", method="get"> class="filter_form_fieldset"> class="filter_form_fieldset_legend">Choose an area: <% Area.all.each do |a| %> <span class="filter_form_checkbox_label"> <%= check_box_tag("areas[]", a.id, false, :class => "styled")%> <%= a.name %>
span> <% end %> type="submit" value="Filter" />
class="venue_partials_container"> <%= render :partial => 'venue', :collection => @venues %> class="clearall">
<%= will_paginate @venues %> class="venue_partial_button"> <%= link_to 'add a new venue', new_venue_path %>
class="clearall">

I was thinking a way of doing this could be to make another table of icon records where one venue belongs to one icon and one icon belong to one venue. Then yielding the map div area to partials of the icon records. The differant css classes could then be something like:

.icon(with_venue_id_1) {
position: absolute;
top: 10px;
left: 10px;
}

.icon(with_venue_id_2) {
position: absolute;
top: 15px;
left: 20px;
}

etc etc....

Which I know is so horrifically bad it may bring a bit of sick in your mouth but my zero experience of programming ever has led me to this. I imagine theres so many better ways of doing it but this could work as a learning aid for me at least.

I would eventually like these icons and their positioning to be added from the running app itself but for now I'm happy just to get something working.

Thanks for any help, its much appreciated.

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.

Important General Tech Links