I have a webpage that I am trying to optimize for desktop and mobile but have little experience in how to place divs in separate places on the screen that reference the same id
. Any suggestions about best practices would be extremely helpful.
<input id='feature-filter' type='text' placeholder='Filter by name' />
For example, above I have an input named feature-filter
that on desktop should be positioned in the menu bar called header
on desktop. Note that there is no accompanying CSS to feature-filter
.
#header {
display: flex;
position: absolute;
align-items: center;
top: 0px;
width: 100%;
line-height: 50px;
height: 50px;
background: rgba(12, 12, 12, 0.8);
color: #eee;
font: 16px/20px 'Open Sans', sans-serif;
font-weight: 500;
text-align: center;
vertical-align: middle;
}
<div id='header'>
<button title = "ButtonA" id = "A"></button>
<button title = "ButtonB" id = "B"></button>
<button title = "ButtonC" id = "C"></button>
<input id='feature-filter' type='text' placeholder='Filter by name' />
</div>
In the mobile version, however, I would like to place this input in a legend that is at the bottom of the page. In my javascript, there is an event listener that pulls data from feature-filter
.
#legend { z-index: 101010; padding: 5px; position: fixed; text-align: center;
color: #fff; bottom: 0px; width: 300px; background: #181818; opacity: 0.92;
font-family: 'Open Sans', sans-serif; left: 0; right: 0; font-weight: 300}
<div id='legend'>
<input id='feature-filter' type='text' placeholder='Filter by name' />
</div>
Is it possible to reference the same DOM id
in javascript AND place feature-filter
in two separate places in the html
- one for the mobile and one for the desktop version ?
What is the best approach to this problem? Using CSS classes would still require having two separate inputs with the same id
in the html
Any basic explanation or suggestions would be appreciated.