Find CSS styles assigned to an element

baychaser

New Member
Get the rendered style of an element(Should be able to handle inline CSS also)I have been learning Nokogiri and understand how to select a node based on an ID or Class. However, I would like to select a node/element and get back the specific CSS styles assigned to it, including inherited styles.CSS Style Sheet:\[code\]<head> <style type="text/css"> .myfont {font-family: Times New Roman: font-size: 80% } .bold {font-weight: bold} .50_font_size { font-size:50% } </style> </head>\[/code\]HTML:\[code\]<Body> <div id="article1" class="myfont"> <div id="title1" class="bold"> My Title Text <div id="author1" class="50_font_size"> By First Name Last Name </div> </div> General article text. General article text. General article text. </div> </div>\[/code\]In the above example, I would like to use...\[code\]require "nokogiri"document=Nokogiri.HTML(HTML_String)#Hoping for something like the following:author_css = node.css_style("author1") puts author_css#=> {font-family=>"Times New Roman",#=> font-weight=> "bold",#=> font-size=> 50%} \[/code\]As you can see it should output the inherited items, so that I get the correct CSS of the element. What is the best way to get this result?
 
Back
Top