Like most web developers, I occasionally like to look at the source of websites to see how their markup is built. Tools like Firebug and Chrome Developer Tools make it easy to inspect the code, but if I want to copy an isolated section and play around with it locally, it would be a pain to copy all the individual elements and their associated css. And probably just as much work to save the entire source and cut out the unrelated code.
It would be great if I could right-click a node in Firebug and have a "Save HTML+CSS for this node" option. Does such a tool exist? Is it possible to extend Firebug or Chrome Developer Tools to add this feature?
A tool with a single solution for this I'm unaware of, but you can use Firebug and Web Developer extension at the same time.
Use Firebug to copy the html section you need (Inspect Element) and Web Developer to see which css is associated with an element (Calling Web Developer "View Style Information" - it works like Firebug's "Inspect Element", but instead of showing the html markup it shows the associated CSS with that markup).
It's not exactly what you want (one click for everything), but it's pretty close, and at least intuitive.
Lately I created a chrome extension "eXtract Snippet" for copying the inspected element, html and only the relevant css and media queries from a page. Note that this would give you the actual relevant CSS
https://chrome.google.com/webstore/detail/extract-snippet/bfcjfegkgdoomgmofhcidoiampnpbdao?hl=en
Webkit browsers (not sure about FireBug) allow you to copy the HTML of an element easily, so that's one part of the process out of the way.
Running this (in the javascript console) prior to copying the HTML for an element will move all the computed styles for the parent element given, as well as all child elements, into the inline style attribute which will then be available as part of the HTML.
It's a total hack and you'll have alot of "junk" css attributes to wade through, but should at least get your started.
I've created this tool years ago for the same purpose:
http://www.betterprogramming.com/htmlclipper.html
You're welcome to use and improve upon it.
divclip is an updated version of Florentin Sardan's htmlclipper
with modern enhancements: ES5, HTML5, scoped CSS...
you can programmatically extract a stylized div with:
Enjoy.
I've adapted the top voted answer as a dragabble bookmarklet.
Just visit this page and drag the "Run jQuery Code" button to your bookmark bar.