Jump to content

Recommended Posts

Yes, you need a set height of about 1em, then set the overflow to hidden. Be sure that the line-height is correct as well.

 

Use div:hover { height: auto; } to show the content again.

 

I.e

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">

  <head>
    <title>My first Website</title>
    <style type="text/css">
      * { margin: 0;padding: 0; }
      body {
        padding: 1em;
      }
      div {
        height: 1em;
        overflow: hidden;
      }
      div:hover {
        height: auto;
      }
      p {
        padding: 0 0 1em;
        line-height: 1em;
      }
    </style>
  </head>

  <body>
    <div>
     <p>My first Website.</p>
     <p>My first Website.</p>
     <p>My first Website.</p>
     <p>My first Website.</p>
     <p>My first Website.</p>
    </div>
  </body>

</html>

 

See also: CSS Selectors

As a side point, you should rethink your logic a little on this. If the user has javascript turned off, they will never be able to see more than that first line. So what you should do is leave it as a normal div, then use javascript to change the CSS of the div to what blue boden suggested. Although to be even more efficient, you are best creating two different CSS classes - one for each state - and using javscript to toggle between the classes. It's more efficient this way, and your javascript will run smoother.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.