tags:

views:

76

answers:

3

Currently, on my site, I use a background-image with an exact height so that the text (which is also an exact height) fits in on each "line" in the background-image - unfortunately it doesn't work too good. Whenever Japanese characters are in the list it will "bump" the line, so the background-image loops onto a new "line" and shows about 3px of the other color in the image. I wonder if there is an easier and more "proper" way to do this?

Here's the current CSS:

div.list{
background-image:url('static/div.png');
margin:25px -25px 5px -25px; /* Just for some space around the list and some removement of the content-padding I have on the site */
}

div.listCaption{
color:#F57F37;
background-color:#D9D9D9; /* So that the listcaption doesn't look like a list-item */
margin-left:-25px; /* This just removes some of the content-padding I have on the site */
padding-left:25px; /* Makes the background for the caption gray */
padding-top:16px; /* Since I have a PHP loop within the list div, I have to make some space between the two lists I have to make it look better */
}
A: 

In your case there is a simple solution (3px is a small height):
in your css:

  • add 'repeat-x', so that background will not repeat vertically when text is resized

  • add 'background color' property that is equal to one of your gradient color

Sergey
None of that worked unfortunately. And actually, I just noticed - it doesn't look too bad in Firefox, but in Opera, it shows about 1.5px of the next color in the gradient (this goes for with or without repeat-x and BG color added in the CSS)
Nisto
@Nisto - At this point, I would just extend the image height by 5px, so the list item has room to vary its height.
derekerdmann
A: 

One simple option is to turn off the vertical repeat on your background image, and set the background color of the list item to be the same as the bottom color on your image. Then you could set up your CSS to look like this:

div.list {
    background: url("static/div.png") repeat-x left top #fff; /* example color */
    margin:25px -25px 5px -25px;
}

You could also make your background image taller, so you could extend your gradient to avoid a large solid band at the bottom of the list items when their height is forced to expand.


EDIT: The PNG in your comment clears things up a bit.

I'm not entirely sure how you have your HTML set up, but you could simplify the whole thing by using an ordered list and pure CSS.

<h3>Latest Submissions</h3> <!-- or whatever your title element is -->
<ul>
    <li>Lorem Ipsum</li>
    <li class="stripe">Lorem Ipsum</li>
    <li>Lorem Ipsum</li>
    <li class="stripe">Lorem Ipsum</li>
</ul>

Then you could use styles along these lines:

li {
    display: block;
    background: #999;
    padding: 3px;
}

.stripe {
    background: #ddd;
}

Add the strip class to every other list item using your PHP script. What this does makes each list item a block element, and applies a different background if it's one of the stripe rows. Any extra content in a list item will simply cause it to expand vertically, pushing the next one down, but the background colors will stay with the correct elements.


EDIT 2: Outputting the list in PHP

Let's assume that you have an array of values that you're iterating through, called $myarray. We can loop through this array and apply the stripe class to even list items like this:

for($i = 0; $i < len($myarray); i++) {
    $output = "<li";

    if($i % 2 == 0) {
        $output .= ' class="stripe"'
    }

    $output .= ">" . $myarray[$i] . "</li>";
}

Make sure that this output is contained within the ul, so you'll want to do something like this:

<ul>
    <?php //Put your loop here ?>
</ul>
derekerdmann
Sorry, but would the white color be the top color or the bottom color? I haven't really used the background-rule in that way before.
Nisto
@Nisto - The color would show through anywhere the image doesn't cover. In this case the image is set at the top, so you would put the bottom color as the background color.
derekerdmann
Hmm, I think you've misunderstood my position. Since each item in the list creates a new part of the background, it will loop the part of the background further. Everything inside the list is surrounded by the list div, that's why I also made the listCaption div, and also why it looks so "advanced". Look here for an example:http://anony.ws/i/gqga.png
Nisto
How would I go about using that in a while loop in PHP though? The reason why I used a background was actually because of this.
Nisto
@Nisto - Just updated my answer with some example PHP code.
derekerdmann
Alright, I couldn't find any better way to do it, so thanks!
Nisto
A: 

Just to be complete: Almost all current browsers (surprisingly enough even IE6) support CSS background gradients.

http://www.webdesignerwall.com/tutorials/cross-browser-css-gradient/

RoToRa
There's a link posted in a later comment - looks like he wants something more like zebra striping than true gradients.
derekerdmann
a) But it is invalid CSS though, I'm aiming for valid CSS on my site.b) Yes, I am sorry, I shouldn't have used "gradient" to describe what I wanted. What I really want is a striped list.
Nisto
@Nisto - Have you tried the snippet from my last edit yet? Making any progress?
derekerdmann
No, I actually didn't try it yet. Right now, I'm looking for a better way to do it, but thanks for your help though! Will use that if I can't come up with something better.
Nisto