【问题标题】:css circular image anchor too largecss圆形图像锚太大
【发布时间】:2016-01-29 09:39:54
【问题描述】:

我目前正在 php 中显示用户的个人资料图片,如果他们点击它,则会将他们带到他们自己的个人资料。图像正确显示并且链接有效,但链接区域超出图片和附近的链接。我将如何减少锚的面积?

    <?php }    if ($searchuser == $username)
 { ?>
                                    <a href="profile.php">
                                        <?php } ?>

                                            <div style="background-image: url('<?php echo $profilepic; ?> ')" class="user-pic"></div>
                                            <?php if ($searchuser == $username)
 {?>
                                    </a>
div.user-pic {
    margin: 0 auto;
    width: 125px;
    height: 125px;
    border-radius: 50%;
    background-repeat: no-repeat;
    background-position: center center;
    background-size: cover;
    border: 0.09em solid white;
    position: relative;
    top: -60px;
    padding: 0px;
    z-index: -100;
}

【问题讨论】:

    标签: css image background anchor


    【解决方案1】:

    试试这个:

    php

    <?php } 
        $show_user_link = false;
        if ($searchuser == $username) { 
            $show_user_link = true;
        }
    ?>
    
    <div style="background-image: url('<?php echo $profilepic; ?>')" class="user-pic">
        <?php if( $show_user_link ): ?>
            <a class="user-link" href="profile.php">
            </a>
        <?php endif; ?>
    </div>
    

    css

    div.user-pic {
        position: relative;
    }
    
    a.user-link {
        height: 125px;
        width: 100%; 
    }
    

    你把锚点放在 div 标签中,然后你可以使 div 的相对位置和锚点的宽度为 100%。

    PS:你可以尝试使用类似的东西

    <?php if(true): ?>
    <strong> some html </strong>
    <?php endif; ?>
    

    混合使用 php 和 html 以使您的代码更具可读性。

    --- 编辑

    好的,我明白了,看看新代码现在是否更有帮助,我认为唯一可能出错的是锚的高度,以防它没有固定为 125px,如果你有问题,请告诉我。

    【讨论】:

    • 抱歉,我没有正确解释自己。图片显示给任何想要查看它的人,但如果用户正在查看自己的图片,他们可以单击链接。所以链接条件只受 if 语句的影响——总是显示图片。我认为将链接移到内部会导致只有用户能够查看自己的图片。
    • 新编辑的答案是否可以解决您的问题?如果不是,它在哪里失败了?
    猜你喜欢
    • 1970-01-01
    • 2016-05-07
    • 2016-07-29
    • 1970-01-01
    • 2012-05-19
    • 2014-12-12
    • 2016-05-06
    • 1970-01-01
    • 2013-07-19
    相关资源
    最近更新 更多