Flex项似乎继承了一个我找不到的表单的高度属性。

huangapple go评论80阅读模式
英文:

The Flex Items Seem to Inherit a Height Property From a Form That I Can't Find

问题

I understand you want a translation of the provided code and description, excluding the code itself. Here's a translation of your description:

我理解你需要提供的是代码和问题描述的翻译,以下是问题描述的翻译:

我正在尝试通过使用Flexbox来拉伸我的导航栏的内容,以填充整个导航栏的宽度。但似乎存在一个问题,因为导航栏内部的表单设置了特定的高度,从而拉伸了作为其兄弟元素的另外两个弹性项目。

这是我的标记:
(代码已省略)

我正在使用Compass的Flexbox模块,并且我有一个用于媒体查询的mixin。以下是与导航栏相关的所有CSS:

(代码已省略)

这里是问题的屏幕截图:

Flex项似乎继承了一个我找不到的表单的高度属性。

我尝试过使用display: inline-block,但这并不能以我想要的方式填充容器。我已经仔细检查了所有样式,但没有一个指定了高度。当我使用Chrome的DevTool删除表单时,其兄弟元素的高度恢复正常。我确信是表单的问题。只有在我添加该元素到标记中后才出现。我不知道是什么问题。即使ChatGPT也无法正确诊断问题。

如果你需要更多帮助,请随时提出具体的问题或需求。

英文:

I'm trying to stretch out the contents of my navigation bar to fill the width of the bar, so I'm using Flexbox. There seems to be a problem because the form within the navigation bar is set to a certain height that stretches the other two flex items that are its siblings.

Here is my markup:

<?php
// Define HTML structure of the Header Menu
$args = array (
  'theme_location' => 'header-menu',
  'menu_class' => 'nav-list',
  'menu_id' => null,
  'container' => 'nav',
  'link_before' => '<h2>',
  'link_after' => '</h2>'
);
?>
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
  <head>
    <title><?php bloginfo('name'); ?> » <?php is_front_page() ? bloginfo('description') : wp_title(''); ?></title>
    <meta charset="<?php bloginfo( 'charset' ); ?>">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>">
<?php wp_head(); ?>
  </head>
  <body <?php body_class(); ?>>
    <div id="navigation" class="wrapper">
      <header>
        <h1>
          <a href="<?php echo esc_url( home_url( '/' ) ); ?>">
            <svg id="logo" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 122.11 122.11">
              <defs><style>.moon{stroke:#000;stroke-miterlimit:10;}</style></defs>
              <path class="moon" d="m96.69,15.5c-1.03-.81-2.47-.85-3.55-.1-1.08.75-1.55,2.1-1.16,3.36,2.9,9.36,3.35,19.38,1.3,28.99-6.62,31.04-37.25,50.9-68.29,44.28-1.58-.34-3.21-.76-4.97-1.3-1.25-.38-2.61.09-3.35,1.16-.74,1.08-.7,2.51.1,3.55,8.22,10.55,19.94,17.9,33.02,20.69,3.99.85,7.97,1.26,11.9,1.26,26.29,0,49.98-18.35,55.68-45.07,4.59-21.5-3.34-43.27-20.68-56.81Z"/>
              <path class="star"d="m65.33,15.55c-.2-.62-.78-1.04-1.43-1.04h-10.86l-3.36-10.33c-.2-.62-.78-1.04-1.43-1.04s-1.23.42-1.43,1.04l-3.36,10.33h-10.86c-.65,0-1.23.42-1.43,1.04-.2.62.02,1.29.54,1.68l8.79,6.38-3.36,10.33c-.2.62.02,1.29.54,1.68.26.19.57.29.88.29s.62-.1.88-.29l8.79-6.38,8.79,6.38c.53.38,1.24.38,1.76,0,.53-.38.75-1.06.54-1.68l-3.36-10.33,8.79-6.38c.53-.38.75-1.06.54-1.68Z"/>
              <path class="star" d="m28.02,38.34h-7.94l-2.45-7.55c-.2-.62-.78-1.04-1.43-1.04s-1.23.42-1.43,1.04l-2.45,7.55h-7.94c-.65,0-1.23.42-1.43,1.04-.2.62.02,1.29.54,1.68l6.42,4.67-2.45,7.55c-.2.62.02,1.29.54,1.68.53.38,1.24.38,1.76,0l6.42-4.67,6.42,4.67c.26.19.57.29.88.29s.62-.1.88-.29c.53-.38.75-1.06.54-1.68l-2.45-7.55,6.42-4.67c.53-.38.75-1.06.54-1.68-.2-.62-.78-1.04-1.43-1.04Z"/>
            </svg>
            <b class="invisible"><?php bloginfo('name'); ?></b>
          </a>
        </h1>
      </header>
      <form id="search" action="<?php echo esc_url( home_url( '/' ) ); ?>" method="get">
        <input type="search" class="input-text" name="s" placeholder="Search a neighborhood or city" autocomplete="off">
      </form>
      <?php if ( has_nav_menu( 'header-menu' ) ) : wp_nav_menu( $args ); endif; ?>
    </div>

I'm using Compass's Flexbox module and I have a mixin for media queries. Here's all the related CSS to the navigation bar:

// Define all navigation bar related styles here

#navigation {
  padding-top: $space-horizontal;
  padding-bottom: $space-horizontal;
  @include flexbox((
    display: flex,
    flex-direction: row
  ));
  position: relative;

  > header {
    width: 24px;
    padding-right: $space-horizontal * 0.5;

    h1 > a {
      padding-bottom: 0;
      overflow: hidden;

      > #logo {
        width: 24px;
        height: 24px;

        &:hover,
        &:active {
          .moon {
            fill: #FFF;
            transition: fill 0.1s ease-in;
          }

          .star {
            fill: #FFDD5C;
            transition: fill 0.1s ease-in;
          }
        }
      }
    }
  }

  a {
    color: $color-foreground;

    &:hover,
    &:active {
      padding-bottom: 0;
      border-bottom: 0;
    }
  }

  // Menu
  > .menu-header-menu-container {
    padding-left: $space-horizontal * 0.5;
    @include flex(1);

    > .nav-list {
      margin-top: $default-heading-size + 2 * $space-horizontal;
      position: absolute;
      top: 0;
      right: 0;
      bottom: 0;
      left: 0;

      @include respond-above(sm) {
        margin-top: 0;
        position: static;
        @include flexbox((
          display: flex,
          flex-direction: row,
        ));

        > .menu-item {
          padding-right: $space-horizontal * 0.5;
          padding-left: $space-horizontal * 0.5;
          @include flex(1);

          a {
            display: block;
          }
        }
      }
    }
  }

  // Search
  > #search {
    padding-right: $space-horizontal * 0.5;
    padding-left: $space-horizontal * 0.5;
    display: none;
    @include flex(3);

    @include respond-above(sm) {
      display: block;
    }

    > .input-text {
      width: 100%;
      font-size: $default-heading-size;
      color: $color-foreground;
      padding-top: 0;
      padding-bottom: 0;
      border: 0;
    }
  }
}

Here's a screenshot of the problem:
Flex项似乎继承了一个我找不到的表单的高度属性。

I've tried using display: inline-block but that doesn't fill out the container the way I want them to. I've tried double-checking all the styles, and none of them have a specified height. When I delete the form using Chrome's DevTool, the height of its siblings go back to normal. I'm sure it's the form. It only appeared when I added that element to the markup. I don't know what it is. Even ChatGPT can't diagnose the problem properly.

答案1

得分: 0

我能在处理其他元素的样式时修复它。问题不在表单中。可能只是因为在表单之前,我没有注意到问题存在,因为项目都对齐了。问题出现在<header>上的溢出上。锚点标签有一个溢出的不可见的<h1>元素,导致高度溢出到导航栏之外。当我将锚点标签的display属性设置为block并为其设置适当的高度时,溢出问题就解决了。

英文:

I was able to fix it when I moved on to styling other elements. The problem wasn't in the form. I probably just didn't notice the problem was there before the form because the items were aligned. The problem was with the overflow on the &lt;header&gt;. The anchor tag had an overflowing invisible &lt;h1&gt; element that was causing the height to overflow off the navigation bar. When I set the display property of the anchor tag to block and set a proper height for it the overflow was fixed.

huangapple
  • 本文由 发表于 2023年6月15日 12:02:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/76479026.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定