开发者

How do I style a table like a notepad?

I would like to create a CSS/HTML version of this notepad on my page:

How do I style a table like a notepad?

I was thinking of using a simple table like this:

<div id="notepad">
        <table> 
            <thead id="tbl_header">Comments</thead>     
            <tr></tr>
            <tr>
                <td class="col1">D开发者_高级运维ot</td>
                <td class="col2">Text for column 2</td>
            </tr>
            <tr>
                <td class="col1"></td>
                <td class="col2"></td>
            </tr> 
            <tr>
                <td class="col1"></td>
                <td class="col2"></td>
            </tr>
            <tr>
                <td class="col1"></td>
                <td class="col2"></td>
            </tr>
            <tr>
                <td class="col1"></td>
                <td class="col2"></td>
                     <td class="col3"></td>
            </tr>
        </table>    
    </div>

So what I was thinking was cutting up the graphic. Have the top part, be the bg img for the <thead>. Then just create one of the lines as the rows (there would be two graphics, one for col1 and col2 - so when a new row is created the bg of both columns would be populated), so that it can scale vertically as needed. Then, for the last set, I have two more graphics. One is for col1. One for col2 (which is the regular row but a little narrower in width) and the curl would be col3.

Is there a scalable way I can do this, using CSS & HTML only (no JS or jQuery) ?

Thanks.

P.S. Or is there another way to create this same thing without having to use bg images - and just using CSS?


Using tables to do this is probably not correct (I assume your "notepad" isn't filled with tabular data); instead, a simple HTML5 <section> could be enough:

<section class="notepad">
    <header><h1>Comments</h1></header>
    <!-- Your text here -->
    <footer>&nbsp;</footer>
</section>

With appropriate CSS, this is easily styled to become a "notepad":

.notepad, .notepad>* {
    margin: 0;
    padding: 0;
    overflow: auto;
}
.notepad {
    background: url('middle-part.png');
}
.notepad header {
    background: url('top-part.png');
}
.notepad footer {
    background: url('curl-part.png');
    float: right;
    /* Set a correct size as well. */
}

Untested; may require some tweaking. Just be sure to set line-height appropriately, so that text doesn't overlap row lines. If you're using HTML4 (or even XHTML, shrug), simply replace the HTML5-specific elements with <div>s.


It seems like you want the content to have vertical rhythm. It's very painstaking to achieve, but it's rewarding to do. Basically you select a line-height and then make everything have a vertical height that is some multiple of your chosen line-height. Here is a link that might better explain it as well as some tools that I use:

  • http://coding.smashingmagazine.com/2011/03/14/technical-web-typography-guidelines-and-techniques/
  • http://drewish.com/tools/vertical-rhythm
  • http://pxtoem.com/
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜