代码之家  ›  专栏  ›  技术社区  ›  Mendes

模式内居中对齐反应日期时间

  •  0
  • Mendes  · 技术社区  · 6 年前

    我正在构建一个允许用户选择日期和时间的模式。我用的是 react-datetime component

    这是我的代码:

    <div className="date-time-modal">
      <div className="date-time-modal-container">
        <div className="date-time-modal-button">
          <Button onClick={this.handleCloseModal} type="noborder">
            <Icon name="window-close" size={"2x"} />
          </Button>
        </div>
        <div className="date-time-modal-title">
          "Please select date and time:"
        </div>
        <div className="date-time-modal-calendar"> 
          <DateTime input={false} />
        </div>
      </div>
    </div>
    

    还有我的造型:

    .date-time-modal {
        position: fixed;
        z-index: 1;
        padding: 5%;
        left: 0;
        top: 0;
        width: 100%;
        height: 100%;
        background-color: $ux-theme-color-modal-brackground;
        display: flex;
        align-items: center;
        justify-container: center;
    
    }
    
    .date-time-modal-container {
        background-color: $ux-theme-color-template-header;
        padding: 20px;
    
    }
    
    .date-time-modal-button {
        flex: 1;
        text-align: right;
    }
    
    .date-time-modal-title {
        flex: 1;
        text-align: left;
    }
    
    .date-time-modal-calendar {
        flex: 1;
    }
    
    .date-time-modal-calendar * {
        text-align: center;
    }
    

    每次打开模式时,日历都锁定在左侧。如果我选择时间选择器,它就变得堆积起来了。

    在当前渲染下方(检查堆叠的时间选择器和所有左对齐的时间选择器):

    enter image description here

    enter image description here

    1 回复  |  直到 6 年前
        1
  •  0
  •   Mendes    6 年前

    我的答案是 this post

    必须使用react datetime css文件正确设置组件的样式。