gpt4 book ai didi

html - 我无法正确定位导航栏中的某个元素

转载 作者:行者123 更新时间:2023-11-28 00:07:40 26 4
gpt4 key购买 nike

我在 Symfony 3 下工作,在我的文件 base.html.twig 中,我有一个导航栏,其中包含我页面上的链接。

在最右边,它还包含一个注销链接,该链接前面必须是已登录用户的用户名。

只是,我无法正确定位用户的用户名,使其与断开链接保持一致。我尝试了各种方法,但无能为力......

这是导航栏的渲染

navbar

这是我的代码:

base.html.twig:

<!DOCTYPE html>
<html>

<head>
<meta charset="UTF-8" />
<title>{% block title %}Antivirus{% endblock %}</title>
{% block stylesheets %}


{% endblock %}
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<link rel="icon" type="image/x-icon" href="{{ asset('favicon.ico') }}" />
<link rel="stylesheet" href="https://bootswatch.com/4/flatly/bootstrap.min.css">
<link rel="stylesheet" href="{{ asset('css/baner.css') }}">

<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
</head>

<body style="background-color:#f2f2f2;">

<div class="hero-image">
<div class="hero-text">
<h1>Site</h1>
</div>
</div>

<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
<a class="navbar-brand" href="{{path('connexion_index')}}">Atelech</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarColor01"
aria-controls="navbarColor01" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>

<div class="collapse navbar-collapse" id="navbarColor01">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="{{path('connexion_index')}}">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{path('user_packages')}}">Packages</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{path('accueil')}}">Sécurité informatique</a>
</li>
{% if is_granted('ROLE_SUPER_ADMIN') %}
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Gestion</a>

<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<a class="dropdown-item" href="{{path('paquets_index')}}">Packages</a>
<a class="dropdown-item" href="{{path('informations_index')}}">Informations</a>
<a class="dropdown-item" href="{{path('utilisateurs_index')}}">Utilisateurs</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Statistiques</a>
</div>
</li>
{% endif %}
{% if is_granted('ROLE_USER') %}
<li class="nav-item">
<a class="nav-link" href="{{path('fos_user_profile_show')}}">Mon compte</a>
</li>
{% endif %}

</ul>

{% if is_granted("IS_AUTHENTICATED_REMEMBERED") %}
<div class="nav navbar-nav navbar-right">
<div class="collapse navbar-collapse" id="navbarColor01">
<ul class="navbar-nav mr-auto">
<li class="nav-item">{{ app.user.username }} </li>
<li class="nav-item">
<a class="nav-link" href="{{ path('fos_user_security_logout') }}">Déconnexion</a>
</li>
</ul>
</div>
</div>
{% endif %}

</div>
</nav>

<div class="container">
{% block body %}{% endblock %}
</div>
{% block javascripts %}{% endblock %}
{% block fos_user_content %}{% endblock %}
</body>

</html>

我把文件中给我带来问题的部分单独放在这里:

{% if is_granted("IS_AUTHENTICATED_REMEMBERED") %}
<div class="nav navbar-nav navbar-right">
<div class="collapse navbar-collapse" id="navbarColor01">
<ul class="navbar-nav mr-auto">
<li class="nav-item">{{ app.user.username }} </li>
<li class="nav-item">
<a class="nav-link" href="{{ path('fos_user_security_logout') }}">Déconnexion</a>
</li>
</ul>
</div>
</div>
{% endif %}

有人会知道这段代码有什么问题吗?

最佳答案

为用户 li 添加这个类 pt-2 text-white pr-2

<li class="nav-item pt-2 text-white pr-2">{{ app.user.username }} </li>

关于html - 我无法正确定位导航栏中的某个元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55606599/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com