3
\$\begingroup\$

I've managed to position the link boxes as I wanted and to apply a background to them, but I'm not sure I've done it in the most elegant or efficient way.

Is there a better way to position the elements without mixing positioning and floats? And is there a way to remove the background between the link boxes without having to turn it off in the section and turn it on again for the boxes? Or any other suggestions?

I've only been coding for a few months, but I aspire to write nice shiny code.

jsfiddle link

<section class="three">
    <a href="#"class="left-link link-box">
        <h2>Title</h2>
        <p>Lorem ipsum dolor sit amet.</p>
    </a>
    <a href="#"class="middle-link link-box">
        <h2>Title</h2>
        <p>Lorem ipsum dolor sit amet.</p>
    </a>
    <a href="#"class="right-link link-box">
        <h2>Title</h2>
        <p>Lorem ipsum dolor sit amet.</p>
    </a>
</section>
section {
    width: 1000px;
    margin: 1em auto;
    background: #C3C3C3 url(images/background.png);
    overflow: hidden;
    border-radius: 5px;
}

.three, .five {
    background: none;
}

.link-box {
    position: relative;
    display: block;
    float: left;
    text-decoration: none;
    color: #333;
    border-radius: 5px;
    width: 300px;
    background: #C3C3C3 url(images/background.png);
}

.left-link {
    float: left;
}

.right-link {
    float: right;
}

.middle-link {
    left: 5%;
}
\$\endgroup\$
3
  • \$\begingroup\$ Your background images in your fiddle don't load because you have to update the links to a public URL. \$\endgroup\$ Commented Mar 8, 2013 at 16:39
  • \$\begingroup\$ I anticipated that which is why I added the colour. I was more interested in the best way to apply a background to the link boxes and not to the parent section element. \$\endgroup\$ Commented Mar 8, 2013 at 17:18
  • \$\begingroup\$ I think the way you applied the background to the link boxes is correct. You can see this if you remove the background declaration from .section, the link boxes will have their respective background. \$\endgroup\$ Commented Mar 8, 2013 at 17:22

1 Answer 1

1
\$\begingroup\$

I edited your fiddle jsFIddle. Basically what I have done is removed position:relative and added float:left and then added some margin to the elements. Then with the last-child selector I removed margin from the last item.

\$\endgroup\$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.