首页  >  问答  >  正文

CSS行类使某些元素超出框架,而它们应该是静态的并固定在显示器底部

目前我的页面如下所示。添加行类以使两个元素彼此相邻后,底部导航栏被向下推到我必须滚动的位置。

在这里,您可以看到另一个没有行元素的页面,其中导航链接完美地粘在显示屏的底部(植物和房间导航元素不应该位于提醒选项卡中(图 1),因此请忽略此元素图片 2) 该页面是可滚动的,并且使我的导航栏保持在正确的位置,但元素的轮廓不正确。所有绿色框显示应位于另一个上方,以及编辑和删除按钮。我尝试使用用于图 1 的行类来修复此问题,但这导致了图 1 中的问题。

在这里您可以在“提醒”选项卡中看到我想要实现的目标

我想知道当我的 html 中存在行元素时,我当前的 css 代码有什么问题会导致此错误。

如果您知道一种更好的方式来显示彼此相邻的项目,从而可以防止这种行为,我们也欢迎您。

.row {
    display: flex;
    align-items: center;
    border-bottom: 1px solid #bdbdbd;
    font-family: 'Montserrat', sans-serif;
  }

  .CheckButton {
    margin-left: 30px;
    width: 60px;
    height: 80px;
  }

  .ReminderDescription {
    flex-grow: 1;
    font-weight: bold;
    margin-right: 80px;
  }

导致问题的html代码片段

{% block content %}
  {% for reminderInstance in Reminders %}
  <div class="row">
    <div class="CheckButton">
      <form action="{{ url_for('reminder', Plant_id = reminderInstance.Plant_id) }}">
        <button class="NewButton NewButton1"></button>
      </form>
    </div>
    <div class="ReminderDescription "> Give {{ reminderInstance.Plant_name }} water {{ reminderInstance.TimeSinceWaterNeeded }} days ago </div>
  </div>
  {% endfor %}
{% endblock %}

如果问题出在其他地方,我将包含整个 html 页面以及导航 css 代码。 提醒 HTML

<!DOCTYPE html>
<html>
    <head>
        <title> Reminders </title>
        <meta name="viewport" content="width=devide-width, initial-scale=1.0">
        <meta charset="utf-8">
        <link rel="shortcut icon" href="/assets/favicon.ico">
        <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
        <link rel= "stylesheet" type= "text/css" href= "{{ url_for('static',filename='src/nav.css') }}">
        <link rel= "stylesheet" type= "text/css" href= "{{ url_for('static',filename='src/Collection.css') }}">
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
    </head>
    <body>
        <nav class="nav">
          <a href="{{ url_for('collection') }}" class="nav__link">
            <span class="nav__text">Collection</span>
          </a>
          <a href="{{ url_for('index') }}" class="nav__link">
            <span class="nav__text">Home</span>
          </a>
          <a href="{{ url_for('reminders') }}" class="nav__link nav__link--active">
            <span class="nav__text">Reminders</span>
          </a>
        </nav>
    </body>
</html>

{% block content %}
  {% for reminderInstance in Reminders %}
  <div class="row">
    <div class="CheckButton ">
      <form action="{{ url_for('reminder', Plant_id = reminderInstance.Plant_id) }}">
        <button class="NewButton NewButton1"></button>
      </form>
    </div>
    <div class="ReminderDescription "> Give {{ reminderInstance.Plant_name }} water {{ reminderInstance.TimeSinceWaterNeeded }} days ago </div>
  </div>
  {% endfor %}
{% endblock %}

导航 CSS

body {
    margin: 0 0 55px 0;
}

.nav {
    position: fixed;
    bottom: 0;
    width: 100%;
    height: 55px;
    box-shadow: 0 0 3px rgba(0, 0, 0, 0.2);
    background-color: #4ea662;
    display: flex;
    overflow-x: auto;
}

.nav__link {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex-grow: 1;
    min-width: 50px;
    overflow: hidden;
    white-space: nowrap;
    font-family: 'Montserrat', sans-serif;
    font-weight: bold;
    font-size: 15px;
    color: #ffffff;
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
    transition: background-color 0.1s ease-in-out;
}

.nav__link:hover {
    background-color: #eeeeee;
}

.nav__link--active {
    padding: 2px 4px;
    border: none;
    text-align: center;
    border-radius:5px;
    background-color: #468454;
    color: #ffffff;
}

P粉156415696P粉156415696179 天前296

全部回复(1)我来回复

  • P粉905144514

    P粉9051445142024-04-04 10:11:30

    将整个内容放入 div 中(如下所示,宽度为 90%)解决了整个问题:

    .div-2 {
          margin: auto;
          width: 90%;
          height: 90%;
     }

    回复
    0
  • 取消回复