I am attempting to add an input element next to a drop down menu so that when the drop down menu open it does not cover the input. However, even after setting the display property of the input box to inline-block it still appears below the dropdown button element. May i please have some assistance in figuring out why this is happening and what may be a solution? I tried to use the display property and set it to inline-block but it does not work.
div.metric.two {
display:block;
position: relative;
align-items: center;
background-color: var(--blue);
flex: 1 1 0%;
padding: 2rem 1rem;
max-width: 450px;
width:100%;
}
.workout-header {
display: block;
align-items: center;
}
.dropdown {
position: relative;
}
.dropbtn {
display:flex;
margin-right: 10px;
background-color: var(--darker);
border-radius: 1rem;
color: white;
padding: 16px;
font-size: 16px;
border: none;
}
.dropbtn::after {
content: "";
display: inline-block;
margin-left: 5px;
width: 0;
height: 0;
border-top: 5px solid white;
border-right: 5px solid transparent;
border-left: 5px solid transparent;
position: relative;
top: -2px;
}
/* Style the dropdown content */
.dropdown-content {
display: none;
background-color: var(--dark);
align-items: flex-start;
justify-content: flex-start;
font-size: 20px;
position: absolute;
z-index: 1;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
border-radius: 1rem;
padding: 8px 0;
font-size: 14px;
}
.dropdown-content a {
color: white;
padding: 12px 16px;
text-decoration: none;
display: block;
border-radius: 1rem;
}
.dropdown-content a:hover {
background-color: var(--darker);
}
/* Show the dropdown menu on hover */
.dropdown:hover .dropdown-content {
display: inline-block;
}
/* Change the background color of the dropdown button when the dropdown content is shown */
.dropdown:hover .dropbtn {
background-color: var(--dark);
}
.exercise-input {
display:inline-block;
/* top:0; */
/* left: calc(100% +10px); */
background-color: var(--dark);
margin-left: 4px;
padding: 1rem;
border-radius: 1rem;
color:var(--light-gray)
}
<div class="metric two">
<div class="workout-header">
<h2 class="title_workouts">Workouts</h2>
<div class="dropdown">
<button class="dropbtn">Workout Type</button>
<div id="workoutsDropdown" class="dropdown-content">
<a href="#">Weight Training 🏋️</a>
<a href="#">Cardio 🏃</a>
<a href="#">Calisthenics 💪</a>
</div>
<input type="text" name="exercise-input" class="exercise-input" placeholder="Exercise"/>
</div>
</div>
</div>
2
Answers
I assume you would like to have a working dropdown list next to an input field.
This answer just aimed to solve the overlapping problem.
Change both the dropdown button and input field to be
inline-block
, such to be side by side. The content set toblock
such that placed below.You can do it using list group.