21

For purposes of embedding very long Gists from Github in a Wordpress blog, what code will permit me to set the height so that vertical scroll-bars are generated? Something around 500px would be perfect.


EDIT: The issue is now resolved, but I spent so much time on this issue, I believe it would be helpful to have a thread dedicated to that issue. I've posted an answer below that is working.

lawlist
  • 13,099
  • 3
  • 49
  • 158
  • Perhaps @haxan7's answer should now be marked as the correct one considering that the original correct answer has now changed? – starbeamrainbowlabs Jan 24 '16 at 16:17
  • @starbeamrainbowlabs -- I just verified that my answer still works as of February 24, 2016 with Firefox 44.0.2 on OSX Snow Leopard 10.6.8. – lawlist Feb 24 '16 at 21:11

4 Answers4

28
<style type="text/css">
  .gist {width:500px !important;}
  .gist-file
  .gist-data {max-height: 500px;max-width: 500px;}
</style>

<script src="https://gist.github.com/user-name/123456789.js"></script>

Example: Boilerplate webpage borrowed from : http://www.dummies.com/how-to/content/a-sample-web-page-in-html.html [The answer works as advertised as of February 24, 2016 with Firefox 44.0.2 on OSX Snow Leopard 10.6.8.]

<html>
<!-- Text between angle brackets is an HTML tag and is not displayed.
Most tags, such as the HTML and /HTML tags that surround the contents of
a page, come in pairs; some tags, like HR, for a horizontal rule, stand 
alone. Comments, such as the text you're reading, are not displayed when
the Web page is shown. The information between the HEAD and /HEAD tags is 
not displayed. The information between the BODY and /BODY tags is displayed.-->
<head>
<title>Enter a title, displayed at the top of the window.</title>
</head>
<!-- The information between the BODY and /BODY tags is displayed.-->
<style type="text/css">
  .gist {width:300px !important;}
  .gist-file
  .gist-data {max-height: 300px;max-width: 300px;}
</style>
<body>
<h1>Enter the main heading, usually the same as the title.</h1>
<p>Be <b>bold</b> in stating your key points. Put them in a list: </p>
<ul>
<li>The first item in your list</li>
<li>The second item; <i>italicize</i> key words</li>
</ul>
<p>Improve your image by including an image. </p>
<p><img src="http://www.mygifs.com/CoverImage.gif" alt="A Great HTML Resource"></p>
<p>Add a link to your favorite <a href="http://www.dummies.com/">Web site</a>.
Break up your page with a horizontal rule or two. </p>
<hr>
<p>Finally, link to <a href="page2.html">another page</a> in your own Web site.</p>
<!-- And add a copyright notice.-->
<p>&#169; Wiley Publishing, 2011</p>
<script src="https://gist.github.com/lawlist/12345678.js"></script>
</body>
</html>
lawlist
  • 13,099
  • 3
  • 49
  • 158
  • This needs to be internal does it? I couldn't get it to work as an external style sheet. – Josh C Feb 24 '16 at 15:49
  • @Josh C -- I don't presently have a current setup for using gists in webpages. Try out the other two solutions in this thread and see if one of them works. Perhaps something has changed between April 19, 2014 and the current date. – lawlist Feb 24 '16 at 18:03
  • Sorry let me rephrase. Did this need to be internal? – Josh C Feb 24 '16 at 20:54
  • @Josh C -- I put the style code **above** the `` in the html webpage and I put the script code at the preferred location **within** the `` of the html webpage. It may have other usages, but I can't remember if I tried other ways to do this. I just tried it with Firefox 44.0.2 on OSX Snow Leopard 10.6.8 and the answer works as advertised. – lawlist Feb 24 '16 at 21:06
  • Thanks. I might do the same sorta thing, and put it in my header file. This answer still works though. No horizontal scrolling though; Hassan's answer can help with that. – Josh C Feb 24 '16 at 21:59
11

None of the above answers work anymore. Here is the updated CSS that displays the gist correctly with visible scrollbars where needed.

.gist {
   max-width:350px;
   overflow:auto;
}

.gist .blob-wrapper.data {
   max-height:200px;
   overflow:auto;
}

See this blog post for example: How to set custom height and width of embedded Github Gist.

Hassan
  • 870
  • 13
  • 25
1

They seem to have changed something, so now you need to do this:

<style type="text/css"> .gist {width:500px; overflow:auto}  .gist .file-data {max-height: 500px;max-width: 500px;} </style>
Anthony Wieser
  • 4,351
  • 1
  • 23
  • 25
1

If your gist is inside an iFrame, which is generated and you can't access since it's and embedded HTML, you might want to take a look at this.

Victor Oliveira
  • 3,293
  • 7
  • 47
  • 77