简体   繁体   English

如何使我的网站徽标居中?

[英]How to center the logo of my site?

I'm using the Bootstrap 3.6 theme with Drupal 8.4 我在Drupal 8.4中使用Bootstrap 3.6主题

I try to center the llogo of my site but I can not do it. 我尝试将我网站的llogo居中放置,但我做不到。

I tested with: 我测试了:

margin: auto;

and

text-align: center;

without success 没有成功

Here is my site https://www.s1biose.com/ 这是我的网站https://www.s1biose.com/

Here is the content of my page.html.twig file on drupal and bootstrap 这是我在drupal和bootstrap上的page.html.twig文件的内容

{# /** * @file * Default theme implementation to display a single page. {#/ ** * @file *默认主题实现,以显示单个页面。 * * The doctype, html, head and body tags are not in this template. * * doctype,html,head和body标记不在此模板中。 Instead they * can be found in the html.html.twig template in this directory. 而是可以在此目录的html.html.twig模板中找到它们*。 * * Available variables: * * General utility variables: * - base_path: The base URL path of the Drupal installation. * *可用变量:* *通用工具变量:*-base_path:Drupal安装的基本URL路径。 Will usually be * "/" unless you have installed Drupal in a sub-directory. 除非您在子目录中安装了Drupal,否则通常为* /。 * - is_front: A flag indicating if the current page is the front page. *-is_front:一个标志,指示当前页面是否为首页。 * - logged_in: A flag indicating if the user is registered and signed in. * - is_admin: A flag indicating if the user has permission to access * administration pages. *-login_in:一个标志,指示用户是否已注册并登录。*-is_admin:一个标志,指示用户是否有权访问*管理页面。 * * Site identity: * - front_page: The URL of the front page. * *网站标识:*-front_page:首页的URL。 Use this instead of base_path when * linking to the front page. *链接到首页时,请使用此名称代替base_path。 This includes the language domain or prefix. 这包括语言域或前缀。 * * Page content (in order of occurrence in the default page.html.twig): * - title_prefix: Additional output populated by modules, intended to be * displayed in front of the main title tag that appears in the template. * *页面内容(按在默认page.html.twig中的出现顺序):*-title_prefix:模块填充的其他输出,旨在*显示在模板中显示的主标题标签的前面。 * - title: The page title, for use in the actual content. *-标题:页面标题,用于实际内容。 * - title_suffix: Additional output populated by modules, intended to be * displayed after the main title tag that appears in the template. *-title_suffix:由模块填充的附加输出,旨在*显示在模板中出现的主要title标签之后。 * - messages: Status and error messages. *-消息:状态和错误消息。 Should be displayed prominently. 应突出显示。 * - tabs: Tabs linking to any sub-pages beneath the current page (eg, the * view and edit tabs when displaying a node). *-选项卡:链接到当前页面下任何子页面的选项卡(例如,*显示节点时查看和编辑选项卡)。 * - node: Fully loaded node, if there is an automatically-loaded node * associated with the page and the node ID is the second argument in the * page's path (eg node/12345 and node/12345/revisions, but not * comment/reply/12345). *-节点:完全加载的节点,如果有一个与页面相关联的自动加载的节点*并且节点ID是*页面路径中的第二个参数(例如,node / 12345和node / 12345 / revisions,但没有*注释) / reply / 12345)。 * * Regions: * - page.header: Items for the header region. * *地区:*-page.header:标题区域的项目。 * - page.navigation: Items for the navigation region. *-page.navigation:导航区域的项目。 * - page.navigation_collapsible: Items for the navigation (collapsible) region. *-page.navigation_collapsible:导航(可折叠)区域的项目。 * - page.highlighted: Items for the highlighted content region. *-page.highlighted:高亮显示的内容区域的项目。 * - page.help: Dynamic help text, mostly for admin pages. *-page.help:动态帮助文本,主要用于管理页面。 * - page.content: The main content of the current page. *-page.content:当前页面的主要内容。 * - page.sidebar_first: Items for the first sidebar. *-page.sidebar_first:第一个侧边栏的项目。 * - page.sidebar_second: Items for the second sidebar. *-page.sidebar_second:第二个侧边栏的项目。 * - page.footer: Items for the footer region. *-page.footer:页脚区域的项目。 * * @ingroup templates * * @see template_preprocess_page() * @see html.html.twig */ * * @组模板* * @请参见template_preprocess_page()* @请参见html.html.twig * /

} }

{% set container = theme.settings.fluid_container ? 'container-fluid' : 'container' %}
{# Navbar #}
{% if page.navigation or page.navigation_collapsible %}
  {% block navbar %}
    {%
      set navbar_classes = [
        'navbar',
        theme.settings.navbar_inverse ? 'navbar-inverse' : 'navbar-default',
        theme.settings.navbar_position ? 'navbar-' ~ theme.settings.navbar_position|clean_class : container,
      ]
    %}
    <header{{ navbar_attributes.addClass(navbar_classes) }} id="navbar" role="banner">
      {% if not navbar_attributes.hasClass(container) %}
        <div class="{{ container }}">
      {% endif %}
      <div class="navbar-header">
        {{ page.navigation }}
        {# .btn-navbar is used as the toggle for collapsed navbar content #}
        {% if page.navigation_collapsible %}
          <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-collapse">
            <span class="sr-only">{{ 'Toggle navigation'|t }}</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
        {% endif %}
      </div>

      {# Navigation (collapsible) #}
      {% if page.navigation_collapsible %}
        <div id="navbar-collapse" class="navbar-collapse collapse">
          {{ page.navigation_collapsible }}
        </div>
      {% endif %}
      {% if not navbar_attributes.hasClass(container) %}
        </div>
      {% endif %}
    </header>
  {% endblock %}
{% endif %}

{# Main #}
{% block main %}
  <div role="main" class="main-container {{ container }} js-quickedit-main-content">
    <div class="row">

      {# Header #}
      {% if page.header %}
        {% block header %}
          <div class="col-sm-12" role="heading">
            {{ page.header }}
          </div>
        {% endblock %}
      {% endif %}

      {# Sidebar First #}
      {% if page.sidebar_first %}
        {% block sidebar_first %}
          <aside class="col-sm-3" role="complementary">
            {{ page.sidebar_first }}
          </aside>
        {% endblock %}
      {% endif %}

      {# Content #}
      {%
        set content_classes = [
          page.sidebar_first and page.sidebar_second ? 'col-sm-6',
          page.sidebar_first and page.sidebar_second is empty ? 'col-sm-9',
          page.sidebar_second and page.sidebar_first is empty ? 'col-sm-9',
          page.sidebar_first is empty and page.sidebar_second is empty ? 'col-sm-12'
        ]
      %}
      <section{{ content_attributes.addClass(content_classes) }}>

        {# Highlighted #}
        {% if page.highlighted %}
          {% block highlighted %}
            <div class="highlighted">{{ page.highlighted }}</div>
          {% endblock %}
        {% endif %}

        {# Help #}
        {% if page.help %}
          {% block help %}
            {{ page.help }}
          {% endblock %}
        {% endif %}

        {# Content #}
        {% block content %}
          <a id="main-content"></a>
          {{ page.content }}
        {% endblock %}
      </section>

      {# Sidebar Second #}
      {% if page.sidebar_second %}
        {% block sidebar_second %}
          <aside class="col-sm-3" role="complementary">
            {{ page.sidebar_second }}
          </aside>
        {% endblock %}
      {% endif %}
    </div>
  </div>
{% endblock %}

{% if page.footer %}
  {% block footer %}
    <footer class="footer {{ container }}" role="contentinfo">
      {{ page.footer }}
    </footer>
  {% endblock %}
{% endif %}

I see you are trying to center an inline element. 我看到您正在尝试将内联元素居中。 Hence you need to use 因此,您需要使用

text-align: center

to the parent element of the inline element. 到内联元素的父元素。 Also you need to remove any floating properties given to the inline element. 另外,您还需要删除赋予内联元素的所有浮动属性。

If it is a block element you need to give 如果它是一个块元素,则需要给出

margin: x auto; //x can be any number of your choice

to the block element that you want to be in the center. 到要位于中心的块元素。

You can take advantage of the position property together with the left property which is calculated as the calc() of: 你可以利用的position与属性一起left其作为计算属性calc()的:

50% width of the <div class="region region-navigation"> - half of the logo width - half of the <button class="navbar-toggle"> width (including margins and padding), which adds up to 107.17485px or roughly 107.175px . <div class="region region-navigation"> 50% width -徽标width一半- <button class="navbar-toggle"> width一半(包括边距和填充),总计107.17485px或约107.175px

So to center the logo add: 因此,将徽标居中添加:

style="position: relative; left: calc(50% - 107.175px)"

to the <a class="logo navbar-btn pull-left"> <a class="logo navbar-btn pull-left">

Or better, add it externally and not internally or inline. 或者更好的是,在外部而不是内部或内联添加它。

On the other hand, if you place the <button class="navbar-toggle"> inside the <div class="region region-navigation"> you can do that easily with the Flexbox like this: 另一方面,如果将<button class="navbar-toggle">放在<div class="region region-navigation"> ,则可以使用Flexbox轻松地做到这一点,如下所示:

.region-navigation {
  display: flex;
  justify-content: space-between; /* aligns the three children as far as it can from each other horizontally, which means that one is placed at the far left, another at the far right and the middle one right in the middle/center */
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM