Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Starting from your fiddle and wrapped the content into a <code>&lt;div&gt;</code> with a default class of <code>content</code>, used for selection and a class called <code>hideContent</code> which will be swapped with <code>showContent</code> when clicking the <code>show more/show less</code> link. </p> <p>I also removed the <code>&lt;p&gt;</code> the text was in. The text is now within the content-div and we are also now able to apply correct height and line-height settings.</p> <p>HTML:</p> <pre><code>&lt;div class="text-container"&gt; &lt;h1&gt;Title goes here&lt;/h1&gt; &lt;h2&gt;Subtitle&lt;/h2&gt; &lt;div class="content hideContent"&gt; Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. &lt;p&gt;Some more text&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Some more text&lt;/li&gt; &lt;li&gt;Some more text&lt;/li&gt; &lt;li&gt;Some more text&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;div class="show-more"&gt; &lt;a href="#"&gt;Show more&lt;/a&gt; &lt;/div&gt; &lt;/div&gt;​ </code></pre> <p>CSS:</p> <pre><code>.hideContent { overflow: hidden; line-height: 1em; height: 2em; } .showContent { line-height: 1em; height: auto; } </code></pre> <p>I'm assuming setting the <code>line-height</code> will ensure it is the same in all browsers. I'm not 100% certain on that though.</p> <p>I attached a click event to the "show more" link which switches the classes on the div using jQueryUI <a href="http://jqueryui.com/demos/switchClass/" rel="noreferrer"><strong>switchClass()</strong></a>:</p> <pre><code>$(".show-more a").on("click", function() { var $this = $(this); var $content = $this.parent().prev("div.content"); var linkText = $this.text().toUpperCase(); if(linkText === "SHOW MORE"){ linkText = "Show less"; $content.switchClass("hideContent", "showContent", 400); } else { linkText = "Show more"; $content.switchClass("showContent", "hideContent", 400); }; $this.text(linkText); });​ </code></pre> <h3><a href="http://jsfiddle.net/Wpn94/" rel="noreferrer">JsFiddle Demo</a> - show more / show less and applying line-height and animation</h3> <p><div class="snippet" data-lang="js" data-hide="true" data-console="false" data-babel="false"> <div class="snippet-code snippet-currently-hidden"> <pre class="snippet-code-js lang-js prettyprint-override"><code>$(".show-more a").on("click", function() { var $this = $(this); var $content = $this.parent().prev("div.content"); var linkText = $this.text().toUpperCase(); if (linkText === "SHOW MORE") { linkText = "Show less"; $content.switchClass("hideContent", "showContent", 400); } else { linkText = "Show more"; $content.switchClass("showContent", "hideContent", 400); }; $this.text(linkText); });</code></pre> <pre class="snippet-code-css lang-css prettyprint-override"><code>div.text-container { margin: 0 auto; width: 75%; } .hideContent { overflow: hidden; line-height: 1em; height: 2em; } .showContent { line-height: 1em; height: auto; } .showContent { height: auto; } h1 { font-size: 24px; } p { padding: 10px 0; } .show-more { padding: 10px 0; text-align: center; }</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"&gt;&lt;/script&gt; &lt;script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"&gt;&lt;/script&gt; &lt;div class="text-container"&gt; &lt;h1&gt;Title goes here&lt;/h1&gt; &lt;h2&gt;Subtitle&lt;/h2&gt; &lt;div class="content hideContent"&gt; Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. &lt;p&gt;Some more text&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Some more text&lt;/li&gt; &lt;li&gt;Some more text&lt;/li&gt; &lt;li&gt;Some more text&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;div class="show-more"&gt; &lt;a href="#"&gt;Show more&lt;/a&gt; &lt;/div&gt; &lt;/div&gt;</code></pre> </div> </div> </p> <p>The above code is an example only but should get you started into the right direction.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload