duanqin2026 2013-04-29 18:57
浏览 40
已采纳

在css中重叠图像

I am using a PHP include that features my header content. For my navigation section I am using a list which just features text. I am using a small bit of php on the list items which basically states whatever the current page is, have an image displayed over that list item within the navigation. Below is what I am 'trying' to achieve:

enter image description here

As you can see, I want that blue shaped image placed over the top of the current page list item.

But below is what I have achieved and you will notice that the image is displayed but not like it should. I have used absolute positioning on the .current class which displays the whole image, however I cannot use absolute position on the image because then it wont display properly on another list item. What can I do?

enter image description here

Below is the relevant CSS and HTML/PHP:

<div id="navbar">
        <ul>
            <li><a <?php if (strpos($_SERVER['PHP_SELF'], 'index.php')) echo 'class="current"';?> href="#">Home</a></li>
            <li><a <?php if (strpos($_SERVER['PHP_SELF'], 'shows.php')) echo 'class="current"';?> href="pages/shows.php">Shows</a></li>
            <li><a <?php if (strpos($_SERVER['PHP_SELF'], 'classes.php')) echo 'class="current"';?> href="pages/classes.php">Classes</a></li>
            <li><a <?php if (strpos($_SERVER['PHP_SELF'], 'noticeboard.php')) echo 'class="current"';?> href="pages/noticeboard.php">Notice Board</a></li>
            <li><a <?php if (strpos($_SERVER['PHP_SELF'], 'about.php')) echo 'class="current"';?> href="pages/about.php">Our Story</a></li>
            <li><a <?php if (strpos($_SERVER['PHP_SELF'], 'contact.php')) echo 'class="current"';?> href="pages/contact.php">Contact</a></li>
        </ul>


.current {
width:138px;
height:57px;
background-image: url('../images/current.png');
background-repeat: no-repeat;
}
  • 写回答

2条回答 默认 最新

  • doumeilmikv7099 2013-04-29 19:02
    关注

    the <li> element is restricting the size of your <a> tag. set the size of the individual <li> items to match the size of your tag and you will see the entire thing.

    Modified code:

    <div id="navbar">
        <ul>
            <li><a <?php if (strpos($_SERVER['PHP_SELF'], 'index.php')) echo 'class="current"';?> href="#">Home</a></li>
            <li><a <?php if (strpos($_SERVER['PHP_SELF'], 'shows.php')) echo 'class="current"';?> href="pages/shows.php">Shows</a></li>
            <li><a <?php if (strpos($_SERVER['PHP_SELF'], 'classes.php')) echo 'class="current"';?> href="pages/classes.php">Classes</a></li>
            <li><a <?php if (strpos($_SERVER['PHP_SELF'], 'noticeboard.php')) echo 'class="current"';?> href="pages/noticeboard.php">Notice Board</a></li>
            <li><a <?php if (strpos($_SERVER['PHP_SELF'], 'about.php')) echo 'class="current"';?> href="pages/about.php">Our Story</a></li>
            <li><a <?php if (strpos($_SERVER['PHP_SELF'], 'contact.php')) echo 'class="current"';?> href="pages/contact.php">Contact</a></li>
        </ul>
    </div>
    
    #navbar ul li {
        width:138px;
        height:57px;
    }
    
    .current {
        width:138px;
        height:57px;
        background-image: url('../images/current.png');
        background-repeat: no-repeat;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题