Tutorial - take control of your site with css

Discussion in 'Tips & Tricks' started by freeze2, Jun 23, 2012.

  1. freeze2 Super Moderator

    I just wanted to give a little example of how easy it is to take full control of your site design and look with css.

    One of the first things that I wanted to accomplish while working on a couple of my clients sites, was to dump as much of the <table> layout as possible and replace it with a very controllable <div> layout. This is very easy to accomplish if you have a good working knowledge of css.

    The following examples will be focused on the User Admin.

    If you open up any template file in your theme, you will notice that the structure is based primarily using tables. This works good for the most part, the downside is that controlling the design can be a little difficult.

    Swapping out the tables for divs is very easy and can land you a much more controllable way to fine-tune the look of your site.

    Below is a typical example of how {data} is displayed in a template file using a <table> structure:

    Code:
    <table width="100%">
        <tr>
            <td>{data}</td>
            <td>{data}</td>
        </tr>
        <tr>
            <td>{data}</td>
            <td>{data}</td>
        </tr>
        <tr>
            <td>{data}</td>
            <td>{data}</td>
        </tr>
        <tr>
            <td>{data}</td>
            <td>{data}</td>
        </tr>
        <tr>
            <td>{data}</td>
            <td>{data}</td>
        </tr>
    </table>

    To take control with divs and css, swap out your <table>, <tr>, <td> structure and replace with something like below:

    Code:
    <div id="wrapper">
        <div class="datawrapper">
            <div class="data1">{data}</div>
            <div class="data2">{data}</div>
        </div>
        <div class="datawrapper">
            <div class="data1">{data}</div>
            <div class="data2">{data}</div>
        </div>
        <div class="datawrapper">
            <div class="data1">{data}</div>
            <div class="data2">{data}</div>
        </div>
        <div class="datawrapper">
            <div class="data1">{data}</div>
            <div class="data2">{data}</div>
        </div>
        <div class="datawrapper">
            <div class="data1">{data}</div>
            <div class="data2">{data}</div>
        </div>
    </div>
    Once you have the structure like above, you can easily control the design with css as below:

    Code:
    #wrapper {
        width: 800px;
    }
    .datawrapper {
        margin-bottom: 10px;
        overflow: hidden;
    }
    .data1 {
        width: 400px;
        float: left;
    }
    .data2 {
        width: 400px;
        float: left;
    }
    This is just a very basic example of how to display your data using divs instead of tables.

    Below is an example of some User Admin panels I've created using 68C and a <div> design. Hopefully this will encourage you to dig deep into your creative mind and come up with some great designs for you and your customers. :)

    [IMG]
    Blair likes this.
  2. Mike-N-Tosh Owner

    Nice little tutorial, freeze2! :)

    One trivial suggestion that I would make in this example is using a different name for the table wrapper in the CSS as it's pretty standard to use the id, "wrapper" as a wrapper for the entire page content in the main "layout.tpl" file (or any main page template for that matter) typically to give the page a set width and center it in the viewport (e.g. browser window).

    My suggestion would be, first to make it a class element as there may be pages with more than one table equivalent (such as the show listings page), so that you can use that same css element more than once on the page which you can not do with an "id" element in CSS and be compliant. So I would use something more like ".divwrap" or ".container". That way it can be used just like you are using the ".datawrapper" class in your example.
  3. freeze2 Super Moderator

    Thanks Mike, yes...for sure...I wasn't thinking that far ahead as I put this together :oops:
  4. Mike-N-Tosh Owner

    It's all good. This is what the forum is all about... helping each other and sparking/sharing ideas.

Share This Page