Skip to content Skip to sidebar Skip to footer

Html Dropdown Box Shifting Html Elements Downwards

So I'm trying to make a dropdown list overlap the elements below when expanded. Unfortunately, even when elements in the same stacking context have a position, and dropdown contain

Solution 1:

You dropdown content should be absolute positioned.

Update your dropdown styles as shown below :

.dropdown-content {
  display: none;
  background-color: rgba(0, 0, 0, 0.2);
  width: 222px;
  overflow: auto;
  position: absolute;
  left: 0;
  top: 100%;
}

Solution 2:

Try following code just set position absolute. also i change width 100% in dropdown-content div for good design.

#firstone {
  z-index: 2;
}

#contain {
  height: 400px;
  width: 400px;
  background-color: rgba(100, 25, 25, 0.2);
}

body {
  text-align: center;
}

input:focus {
  outline: none;
}

.fancy_input_box {
  text-align: left;
  display: inline-block;
  margin: 40px3%1px;
  position: relative;
}

.fancy_input {
  font: 15px/24px"Lato", Arial, sans-serif;
  color: #aaa;
  box-sizing: border-box;
  letter-spacing: 1px;
  border: 0;
  padding: 7px7px;
  border: 1px solid #ccc;
  position: relative;
  background: transparent;
}

.fancy_input:focus~.dropdown-content {
  display: block;
  cursor: default;
}

.fancy_input:focus~.dropdown-content>span {
  display: block;
  cursor: default;
}

.dropdown-content {
  display: none;
  background-color: rgba(0, 0, 0, 0.2);
  width: 100%;
  overflow: auto;
  position: absolute;
  
}

.dropdown-content:active {
  display: block;
}

.dropdown-content>span {
  padding: 12px16px;
  display: none;
}

.dropdown-content>span:hover {
  background-color: rgba(0, 0, 0, 0.1);
}

.fancy_input~.fancy_label {
  position: absolute;
  left: 14px;
  width: 100%;
  top: 10px;
  color: #aaa;
  letter-spacing: 0.5px;
  transition: 0.3s;
  -webkit-transition: 0.3s;
  -moz-transition: 0.3s;
  z-index: -1;
}

.fancy_input:focus~.fancy_label {
  top: -18px;
  left: 1px;
  font-size: 12px;
  color: grey !important;
  transition: 0.3s;
  -webkit-transition: 0.3s;
  -moz-transition: 0.3s;
}

.fancy_input:focus {
  border: 1px solid grey !important;
}

.fancy_input:not(focus):valid~.fancy_label {
  top: -18px;
  font-size: 12px;
  left: 1px;
  color: #aaa;
  transition: 0.3s;
  -webkit-transition: 0.3s;
  -moz-transition: 0.3s;
}
<divid="contain"><divid="firstone"class="fancy_input_box"><inputclass="fancy_input"type="text"placeholder=""maxlength="25"size="25"required><labelclass="fancy_label">Search</label><divclass="dropdown-content"><span>a</span><span>b</span><span>c</span><span>d</span><span>e</span></div></div><divclass="fancy_input_box"><inputclass="fancy_input"type="text"placeholder=""maxlength="4"size="10"><labelclass="fancy_label">Thing</label></div><br><div><divclass="fancy_input_box"><inputclass="fancy_input"type="text"placeholder=""maxlength="4"size="10"><labelclass="fancy_label">stuff</label></div><divclass="fancy_input_box"><inputclass="fancy_input"type="text"placeholder=""maxlength="4"size="10"><labelclass="fancy_label">more stuff</label></div><divclass="fancy_input_box"><inputclass="fancy_input"type="text"placeholder=""maxlength="4"size="10"><labelclass="fancy_label">more stuff</label></div></div></div>

Solution 3:

just add position:absoute and top:100%; in your dropdown-content class

jsfiddle from your code

.dropdown-content {
  display: none;
  background-color: rgba(0, 0, 0, 0.2);
  width: 222px;
  overflow: auto;
  position: absolute;
  left: 0;
  top: 100%;
  }

Post a Comment for "Html Dropdown Box Shifting Html Elements Downwards"