Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,097
    Thanks
    297
    Thanked 12 Times in 12 Posts

    Exclamation aligning li content text with custom bullet point image?

    hi all,

    im currently developing a new website for a friend of mine, and i've run into a bit of trouble when trying to use custom images when showing a list.

    the trouble being is that the image has a height of 50px and the <li> text appears at the bottom of the image where as i want it to start at the top of the image, hope that makes sence?

    my php code for this list is as follows
    PHP Code:
    <ul class="latestnews<?php echo $moduleclass_sfx?>">
    <?php foreach ($list as $item) : #print_r($item);
        
    $link $item->link
        
    $intro $item->introtext;
        
    $intro preg_replace("/<img[^>]+\>/i"""$intro); 
        
        
    // strip tags to avoid breaking any html
        
    $intro strip_tags($intro);
        
        if (
    strlen($intro) > 200) {
        
            
    // truncate string
            
    $stringCut substr($intro0200);
        
            
    // make sure it ends in a word so assassinate doesn't become ***...
            
    $intro substr($stringCut0strrpos($stringCut' '))."... <a href='$link'>Read More</a>"
        }
        
    ?>
        <li class="news">
            <a href="<?php echo $item->link?>">
                <?php echo "<b>".$item->title."</b>"?></a><br /><?php echo $intro?>
        </li>
    <?php endforeach; ?>
    </ul>
    and the css for the .news is
    Code:
    .news{list-style:none; list-style-position:inside; list-style-image:url(../../../images/article_images/newspaper-icon.jpg); }
    any help would be appreciated
    thanks
    Last edited by LJackson; 01-11-2013 at 09:22 PM.

  • #2
    Master Coder Excavator's Avatar
    Join Date
    Dec 2006
    Location
    Alaska
    Posts
    9,675
    Thanks
    22
    Thanked 1,827 Times in 1,811 Posts
    Hello LJackson,
    I actually have a little writeup on exactly this problem - http://nopeople.com/CSS%20tips/li_image/index.html
    Validate often DURING development - Use it like a splelchecker | Debug during Development |Write it for FireFox, ignore IE
    Use the right DocType | Validate your markup | Validate your CSS | Why validating is good | Why tables are bad

  • Users who have thanked Excavator for this post:

    LJackson (01-10-2013)

  • #3
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,097
    Thanks
    297
    Thanked 12 Times in 12 Posts
    thats great thank you very much for sharing! very interesting indeed

    needless to say after reading that i've solved the problem!

    THANKS

  • #4
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    @Excavator
    I was trying to achieve this using the :before pseudo element but it seems to ignore any settings I apply to the content. Do you know if it is possible? I've tried line-height, vertical-align, etc..

    [The image is 18x18]

    Code:
    <!DOCTYPE html>
    <html>
    <head>
        <title>Page Title</title>
        <style type="text/css">
            ul {
                list-style: none;
                height: 30px;
            }
            li {
                height: 30px;
                line-height: 30px;
            }
            li:before {
                content: url('images/checkcross.png');
                display: inline-block;
                vertical-align: baseline;
    
            }
        </style>
    </head>
    
    <body>
    <ul>
        <li>The first line</li>
        <li>The second</li>
        <li>A third</li>
    </ul>
    
    </body>
    </html>
    Attached Thumbnails Attached Thumbnails aligning li content text with custom bullet point image?-beforepseudo.png  
    Attached Files Attached Files
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  • #5
    Master Coder Excavator's Avatar
    Join Date
    Dec 2006
    Location
    Alaska
    Posts
    9,675
    Thanks
    22
    Thanked 1,827 Times in 1,811 Posts
    Quote Originally Posted by AndrewGSW View Post
    @Excavator
    I was trying to achieve this using the :before pseudo element but it seems to ignore any settings I apply to the content. Do you know if it is possible? I've tried line-height, vertical-align, etc..
    It's difficult to control the text separate from the image. That was the whole point of putting the image in as a background of the li.

    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Page Title</title>
    <style type="text/css">
    html, body {
    	margin: 0;
    	font: 100% "Trebuchet MS", Arial, Helvetica, sans-serif;
    	color: #000;
    	background: #fc6;
    }
    #container {
    	width: 800px;
    	margin: 0 auto;
    	padding: 50px 0 200px;
    	background: #999;
    }
    	ul {list-style: none;}
    		li {
    			line-height: 30px;
    			margin: 0 0 5px;
    			padding: 0 0 0 22px;
    			background: #0f0 url(checkcross.png) no-repeat left center;
    		}
    		li#checked {background: #0f0 url(checktick.png) no-repeat left center;}
    </style>
    </head>
    <body>
        <div id="container">
            <ul>
                <li>The first line</li>
                <li id="checked">The second</li>
                <li>A third</li>
            </ul>
        <!--end container--></div>
    </body>
    </html>
    Validate often DURING development - Use it like a splelchecker | Debug during Development |Write it for FireFox, ignore IE
    Use the right DocType | Validate your markup | Validate your CSS | Why validating is good | Why tables are bad

  • #6
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    It's difficult to control the text separate from the image. That was the whole point of putting the image in as a background of the li.
    Thank you @Excavator. I wasn't sure if I just wasn't finding the correct CSS. Andy.
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •