need help from a CSS wiz - create a table “look” without using a table

I'm trying to create a page which looks somewhat like this:

http://www.drmichaelbogdan.com/plastic-surgery/

(I'm referring to the "Find Out More About Our Featured Procedures:" table with alternating colors).

I prefer to refrain from using tables, since from what I understand, it is much wiser to use "pure" css.

Alas, I my CSS skills are somewhat lacking.

Is there anyone out there which can help me create this look in CSS?

my HTML "structure" looks like this:

<div id="latestArticlesWrapper">
       <div class = "newArticle"> 
            <div class = "newArticleImage">
            </div>
            <div class="newArticleData">
            </div>
       </div>
       <div class = "newArticle"> 
            <div class = "newArticleImage">
            </div>
            <div class="newArticleData">
            </div>
       </div>
       <div class = "newArticle"> 
            <div class = "newArticleImage">
            </div>
            <div class="newArticleData">
            </div>
       </div>
       <div class = "newArticle"> 
            <div class = "newArticleImage">
            </div>
            <div class="newArticleData">
            </div>
       </div>
       <div class = "newArticle"> 
            <div class = "newArticleImage">
            </div>
            <div class="newArticleData">
            </div>
       </div>
</div> 

If needed, and if you think that it'll help, I can change the tags from "div" to anything you say, as long as it "helps the cause" :-) (perhaps for the odd/even requirement - the divs are created in a loop...)

Obviously, it should look good on all major browsers (Firefox, Chrome and IE for that matter).

Thank you!!


Well, as usual - IE is giving me problems. It looks great on firefox, it really does, but on IE - it gets messed up

I did change the html and CSS a bit, here is what I am using now:

HTML:

<div id="latestArticlesWrapper">
       <div class = "<%= (oddEven = !oddEven) ? "newArticle white" : "newArticle yellow"%>"> 
             <div class = "newArticleImage">
             </div>
             <div class="newArticleData">
                <span class="newArticleTitle"></span>
                <span class="newArticleDate"></span>
                <span class="newArticleContent"></span>
                <span class="newArticleLink"></span>

             </div>
       </div>
</div>

CSS:

#latestArticlesWrapper {
    width:100%;
    font-size:12px;
    font-family:Arial, Helvetica, sans-serif;
    text-align:justify;
}

.newArticle {
    height:146px;
}

.yellow {
    background:#F2E4C2; 
}
.white 
{
    background:#fff;
}

.newArticleImage {
    width:96px;
    height:96px;
    margin-right:20px;
    margin-top:10px;
    float:right;
}

.newArticleData {
    margin-right:20px;
    margin-top:10px;
    float:right;
    width:404px;
}

.newArticleData h3 {
    padding:0;
    margin:0;
    margin-bottom:3px;
}

.newArticleTitle 
{
    float: right;
}

.newArticleDate
{
    float: left;
    padding-left: 5px;
    padding-right:20px;
    background:url(../images/icons/date.png) right no-repeat;
}

.newArticleContent
{
    float: right;
}

.newArticleLink
{
    float: left;
}

So.... How do I make IE happy? :-P

Answers


here my try: http://jsbin.com/umeno3

html

<div id="latestArticlesWrapper">
       <div class = "newArticle yellow"> 
            <div class = "newArticleImage"><img src="http://www.drmichaelbogdan.com/images/featured-rhinoplasty.jpg" />
            </div>
            <div class="newArticleData"><h3>Rhinoplasty (Nose Job)</h3>Subtle changes in the shape or size of the nose can have a tremendous impact on overall facial appearance. Rhinoplasty, also known as cosmetic nose surgery, can help people feel more confident about their appearance.
            </div>
       </div>
      <div class = "newArticle white"> 
            <div class = "newArticleImage"><img src="http://www.drmichaelbogdan.com/images/featured-rhinoplasty.jpg" />
            </div>
            <div class="newArticleData"><h3>Rhinoplasty (Nose Job)</h3>Subtle changes in the shape or size of the nose can have a tremendous impact on overall facial appearance. Rhinoplasty, also known as cosmetic nose surgery, can help people feel more confident about their appearance.
            </div>
       </div>
       <div class = "newArticle yellow"> 
            <div class = "newArticleImage"><img src="http://www.drmichaelbogdan.com/images/featured-rhinoplasty.jpg" />
            </div>
            <div class="newArticleData"><h3>Rhinoplasty (Nose Job)</h3>Subtle changes in the shape or size of the nose can have a tremendous impact on overall facial appearance. Rhinoplasty, also known as cosmetic nose surgery, can help people feel more confident about their appearance.
            </div>
       </div>
       <div class = "newArticle white"> 
            <div class = "newArticleImage"><img src="http://www.drmichaelbogdan.com/images/featured-rhinoplasty.jpg" />
            </div>
            <div class="newArticleData"><h3>Rhinoplasty (Nose Job)</h3>Subtle changes in the shape or size of the nose can have a tremendous impact on overall facial appearance. Rhinoplasty, also known as cosmetic nose surgery, can help people feel more confident about their appearance.
            </div>
       </div>
       <div class = "newArticle yellow"> 
            <div class = "newArticleImage"><img src="http://www.drmichaelbogdan.com/images/featured-rhinoplasty.jpg" />
            </div>
            <div class="newArticleData"><h3>Rhinoplasty (Nose Job)</h3>Subtle changes in the shape or size of the nose can have a tremendous impact on overall facial appearance. Rhinoplasty, also known as cosmetic nose surgery, can help people feel more confident about their appearance.
            </div>
       </div>
</div>

css

#latestArticlesWrapper {
    width:560px;
    font-size:12px;
    font-family:Arial, Helvetica, sans-serif;
    text-align:justify;
}

.newArticle {
    height:116px;
}

.yellow {
    background:#F2E4C2; 
}
.white {
    background:#fff;
     }
.newArticleImage {
    width:96px;
    height:96px;
    margin-left:20px;
    margin-top:10px;
    float:left;
}

.newArticleData {
    margin-left:20px;
    margin-top:10px;
    float:left;
    width:404px;
}

h3 {
    padding:0;
    margin:0;
    margin-bottom:3px;
}

to change row's bakcground color, you just change the class near newArticle class

PS: For tabular data as your example I advice you to use table, it's more semantic, then you can style it through css. But if you still want do it with divs, then you can follow the above solution.


You've got the html part correct so far. You just need to add some float elements:

div.latestArticlesWrapper
{
    width: #px; /* static width */
}

div.newArticle, div.newArticleAlt
{
    float: left;
    width: #px;  /* should be the width of the entire area to force the float to wrap */
}

div.newArticle
{
    background-color: #ffffff;
}

div.newArticleAlt
{
    background-color: #eeeeee;
    /* alternate row color, use conditional to separate */
}

div.newArticleImage
{
    float: left;
    width: #px;
    padding: #px; /* width + padding = total width */
}

div.newArticleData
{
    float: left;
    width: #px;
    /* don't put padding here for text. use the <p> tag or another <div> */
}

Because you asked for a site like the one referenced (which is a static width), I've put style in here for static widths. If you have a dynamic width site, you'll have to work the widths in a different way.


Can I suggest using a slightly different html structure? I'd suggest the following, given the content itself:

<div id="latestArticlesWrapper">
    <dl>
        <dt>Rhinoplasty (nose job)</dt>
        <dd><img src="http://www.drmichaelbogdan.com/images/featured-rhinoplasty.jpg" />Subtle changes in the shape or size of the nose can have a tremendous impact on overall facial appearance. Rhinoplasty, also known as cosmetic nose surgery, can help people feel more confident about their appearance.</dd>
        <dt>Breast enlargement</dt>
        <dd><img src="http://www.drmichaelbogdan.com/images/featured-breast-augmentation.jpg" />With more choices than ever before, breast augmentation is an excellent option for women who are unsatisfied with the size of their breasts, and would like to create a more voluptuous silhouette.</dd>
        <dt>Mommy makeover</dt>
        <dd><img src="http://www.drmichaelbogdan.com/images/featured-mommy-makeover.jpg" />After having children, many mothers desire a Mommy Makeover to regain their pre-baby body. A Mommy Makeover can return a youthful appearance to your breasts and tummy.</dd>
    </dl>
</div>

With the css:

dt, dd {
    position: relative;
    padding: 0 0 0 110px;
}
dd img {
    position: absolute;
    top: -1em;
    left: 0.2em;
}
dt {
    font-weight: bold;
}
dd {
    margin: 0 0 1em 0;
}

JS Fiddle demo.

I'll note that there's nothing intrinsically wrong with the html you posted, it's just that the above has the advantage of being simpler, with fewer elements to worry about, and takes advantage of the semantics of the dl (definition list) element, and an easier intro from W3schools.


Need Your Help

Check empty UIView?

ios objective-c cocoa-touch uiview uiimageview

In my app, I have a UIView which will drawrect according to user touch. It is meant to be used as a signature box. When the user is finished "drawing", they hit accept and the app continues. Howeve...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.