字段集对齐在HTML CSS中不起作用

时间:2018-09-13 20:33:23

标签: html css

我有HTML CSS代码,希望在其中使用弹出式联系表进行覆盖。 HTML代码:

<div class="overlay" id= "form">
    <form accept-charset="UTF-8"  class="infusion-form">


    <!-- First fieldset starts from here -->
        <fieldset id="ff">
            <h2 class="fs-title"> Some heading</h2>
            <div class="infusion-field">    
                <input class="infusion-field-input" placeholder=" First Name " type="text" required="required"/>
            </div>
            <div class="infusion-field">
                <input class="infusion-field-input" required="required" placeholder=" Last Name " type="text" />
            </div>
            <!-- The NEXT button -->
            <input type="submit" name="next" class="next action-button" id = "next" value="Next"  />
        </fieldset>

    <!-- Second feildset start from here -->

        <fieldset id="sf">
            <h2 class="fs-title">  Some heading 2</h2>
            <div class="infusion-field">
                <input class="infusion-field-input" placeholder=" Phone Number " type="text" />
            </div>
            <div class="infusion-field">
                <input class="infusion-field-input"  placeholder=" Email-id " type="email" />
            </div>

            <!-- Submit Button-->
            <input type="submit" name="submit" class="submit action-button" id = "submit" value="Submit"  />
        </fieldset>
    </form>
</div>

相应的CSS代码为

.overlay {
          position: fixed;
          top: 0;
          left: 0;
          display: none;
          width: 100%;
          height: 100%;
          background-color: rgba(204,204,204,0.8);
          z-index: 10;
        }
.infusion-field-input {
  width: 100%;
  margin-bottom: 30px;
  width: 281px;
  height: 30px;
}
.infusion-form fieldset {
  background: #c8e6c9;
  border-radius: 3px;
  margin-top: 10px;
  padding: 30px 30px;
  box-sizing: border-box;
  width: 20%;
  opacity: 1;
  margin-left: 769px;
  position: absolute;

}

/*//Hidden field sets*/
.infusion-form fieldset:not(:first-of-type) {
  display: none;
}


/*Button*/
.infusion-form .action-button {
  cursor: pointer;
  width: 100%;
  border: none;
  background: #4CAF50;
  color: #FFF;
  margin: 0 0 5px;
  padding: 10px;
  font-size: 15px;
}

.infusion-form .action-button:hover, .infusion-form .action-button:focus {
  background: #43A047;
  -webkit-transition: background 0.3s ease-in-out;
  -moz-transition: background 0.3s ease-in-out;
  transition: background-color 0.3s ease-in-out;
}

.infusion-form .action-button:active{
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.5);

}

.infusion-form .action-button:disabled{
  border: 1px solid #999999;
  background-color: #cccccc;
  color: #666666;
}

现在,每当我减小屏幕尺寸时,contact-f0rm弹出窗口都不会相应移动。如果进一步缩小尺寸,有时会从屏幕上消失。

无法找到需要修改的div / class。 JS Fiddle

1 个答案:

答案 0 :(得分:0)

我认为您希望表单居中,因此请使用左右边距的尖端来自动消除绝对位置

.infusion-form fieldset {
    background: #c8e6c9;
    border-radius: 3px;
    margin-top: 10px;
    padding: 30px 30px;
    box-sizing: border-box;
    width: 20%;
    opacity: 1;
    margin-left: auto;
    margin-right: auto;
}

已在浏览器Chrome和Firefox中签入,并且有效