Hi. I’m writing some html and css code to create a webpage. My problem is when I resize the webpage the location of some elements get disorganized. Example is in the below picture:
In my code there are two searchbars like in the below picture. And I want when I click in the left search bar that has a label “find” then a list of items be shown exactly under it.
Here is what exactly I want to show that you can find the complete code in the
Thanks Erik. My problem is when I minimize the web page, the search bars that were located horizontally near each other get disorganized, I mean after minimizing the screen they locate vertically on top of each other like you can see in the first picture I attached. I need both of them to be still horizontally in the same location like before changing the size of screen. I don’t know how can I fix this?
And my other problem is how can I specify the width of “divlist” which is a div containing some items to have the same width as the search bar?
And my last question is, what do you mean by AP?
I’m assuming you want the drop down portion to be absolutely placed so that it sits over any content below? You don’t need to absolutely place the search bar itself and I already gave you code to centre horizontally and vertically with flex. Instead you have used absolute positioning which takes it out of the flow and you have placed off centre which looks very odd indeed. Let flex centre vertically and horizontally with ease and maintain the flow of the document.
If you want the menu as wide as the whole search bar then set its left position to zero and its right position to zero and it will take up the whole space of its relatively placed parent. You may need to offset it by 10px to account for padding outside the search bar. (If you only wanted the menu as wide as the 'search our website" input only then you would need a revised html source to do this easily and automatically. Once you start throwing magic number fixes at something then you know that you are doing something wrong)
When you go to smaller screen the inputs drop to a vertical line for more room which means that you have to adjust the top position of the dropdown portion in your media query accordingly. Unfortunately because of the way this is constructed you can’t have an automatic top position so you will need a bit of magic number fix to account for the input and label height.
Here’s a quick fork of your codepen.
Please stop using html comments in the css file as that will break things. Usee CSS comments /* css comment */
Thank you so much for your help Erik. I didn’t use datalist because it has got very simple style. That’s why I prefered to use some code with javascript.
Thank you so much for your help. You exactly understood what I want just I wanted the menu as wide as search our website input . I positioned my divlist absolutely and its ok for it to sits over any content below.
If you want the drop down only as wide as that single input then the html will need to be revised so that only the input and the drop down live in the same container.
I’ll put up an example but it won’t be until this evening now as out all day.