Results 1 to 6 of 6

Thread: CSS/HTML for dummies

  1. #1
    Nobody expects the Senior Member Lemur's Avatar
    Join Date
    Jan 2004
    Location
    Wisconsin Death Trip
    Posts
    15,754

    Exclamation CSS/HTML for dummies

    If we have any bright code jockeys in the Org, I could use a spot of help. Attempting to create a collapsing field for a small business website, something like this:

    Code:
    Button
    
    Content content content content

    Where clicking the button shows the content, and clicking it again hides the content. You would think this would be easy. You would think this could be accomplished without resorting to Javascript.

    Anyway, having copied and tweaked several code samples, all of which proved unsatisfactory, I'm curious if any Org code-monkeys have a simple, non-Javascript method for creating collapsing fields. Code samples appreciated.

  2. #2
    Senior Member Senior Member naut's Avatar
    Join Date
    Dec 2005
    Posts
    9,103

    Default Re: CSS/HTML for dummies

    A click? Javascript is your best bet. CSS allows a hover, which is nice, but not a click to my (rusty) knowledge.
    #Hillary4prism

    BD:TW

    Some piously affirm: "The truth is such and such. I know! I see!"
    And hold that everything depends upon having the “right” religion.
    But when one really knows, one has no need of religion. - Mahavyuha Sutra

    Freedom necessarily involves risk. - Alan Watts

  3. #3
    Nobody expects the Senior Member Lemur's Avatar
    Join Date
    Jan 2004
    Location
    Wisconsin Death Trip
    Posts
    15,754

    Default Re: CSS/HTML for dummies

    Well, I'm basically trying to re-create the functionality of this board's [ex] tag with a few extras thrown in. "Frustrating" doesn't begin to cover it.

  4. #4

    Default Re: CSS/HTML for dummies

    It is the on/off behaviour that means you'll need JavaScript, more than the click. (The click is possible to work with using :visited (pseudo-class) and the + selector).

    The typical JavaScript thing to do is to have the CSS define two classes for this purpose and do something like:
    Code:
    var toggleOn="toggleOn"; // class name used in CSS for active/visible style
    var toggleOff="toggleOff"; // class name used in CSS for hidden style
    function toggleButton(elementId) {
       var elem=document.getElementById(elementId); // find the element to toggle on/off
       if(elem !=null) { // do not do anything unless the element actually exists
          if(elem.className.indexOf(toggleOn) == -1) { // if class name does not contain the toggleOn name
            elem.className.replace(toggleOff,toggleOn);
          }
          else {
            elem.className.replace(toggleOn,toggleOff);
          }
       }
       return false; // do not let the event bubble up any further, in case of hyperlinks this prevents the browser from changing address
    }
    Then in HTML something like
    Code:
    <a href="#someValidIdHere" onclick="javascript:toggleButton('elementToToggle');">Button</a>
    <p id="elementToToggle">Content content content</p>
    In CSS:
    Code:
    .toggleOn {
      /* styles to make elements appear visible, I simply swap background & foreground instead */
      background: #cccccc;
      color: #dedede;
    }
    .toggleOff {
      /* styles to make elements appear hidden, I simply swap background & foreground instead */
      color: #cccccc;
      background: #dedede;
    }
    Last edited by Tellos Athenaios; 08-16-2010 at 21:17.
    - Tellos Athenaios
    CUF tool - XIDX - PACK tool - SD tool - EVT tool - EB Install Guide - How to track down loading CTD's - EB 1.1 Maps thread


    ὁ δ᾽ ἠλίθιος ὣσπερ πρόβατον βῆ βῆ λέγων βαδίζει” – Kratinos in Dionysalexandros.

  5. #5
    Nobody expects the Senior Member Lemur's Avatar
    Join Date
    Jan 2004
    Location
    Wisconsin Death Trip
    Posts
    15,754

    Default Re: CSS/HTML for dummies

    Bloody hell, Tellos, may I send you a copy of the page I'm working on? I must learn all of your mad skillz to make phat rain.

  6. #6

    Default Re: CSS/HTML for dummies

    Yes but you're probably better off reading through some tutorials here: http://www.w3schools.com/ and using a keen mind to solve your problems. Quite a lot of that mad skillset can be yours for the mere effort of some Google searches and reading tutorials on the web.
    - Tellos Athenaios
    CUF tool - XIDX - PACK tool - SD tool - EVT tool - EB Install Guide - How to track down loading CTD's - EB 1.1 Maps thread


    ὁ δ᾽ ἠλίθιος ὣσπερ πρόβατον βῆ βῆ λέγων βαδίζει” – Kratinos in Dionysalexandros.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Single Sign On provided by vBSSO