Make img and input line up properly and float to right in html

Jeff Saremi

I want a relatively simple navbar which has a search icon to it's right. Clicking on the icon exposes a hidden search input to its left.

I tried following the advice here after getting frustrated with some other solutions such as playing with "float" or "white-space".

If you look at the after-click picture you'll see that the aspect ratio of the image has changed.

What is the right way to do this?

Code:

ul {
  list-style-type: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background-color: #333;
}

li {
  float: left;
}
<div id="topnav">
  <ul>
    <li><a href="#home">Top Questions</a></li>
    <li style="float:right;">
      <div style="display:flex;flex-direction:row">
        <form><input type="search" id="mySearch" placeholder="Search..." style="display:none;width:200px"></form>
        <img src="search-icon-24.png" alt="" id="searchicon" />
      </div>
    </li>
  </ul>
</div>

Before/after click

Brendan

Does this code help?

function TQ() {
var a = document.getElementById("test");
a.style.display = "block"
}
ul {
	list-style-type: none;
	margin: 0;
	padding: 0;
	overflow: hidden;
	background-color: #333;
    }
    
    li {
    	float: left;
    }
    #test {
    display: none
    }
<!DOCTYPE html>
<html>

<div id="topnav">
	<ul>
    <li><a href="#home">Top Questions</a></li>
	<li style="float:right"><a href="javascript:void(0);" onclick="TQ()">&#128270;</a></li>
		
		<li style="float:right;">
			<div id="test">					
				    <form><input type="search" id="mySearch" placeholder="Search..." style="width:200px"></form>
                    
				
			</div>
		</li>
	</ul>
    

    
    </div>



</html>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to make hyperlinks line up right next to eachother with HTML

float input to the right on the same line as an element

HTML float right drop to next line

Float element right, but make it appear after in the HTML

<input> box keeps dropping to the next line with float: right

float: right; messes up the vertical alignment of elements in HTML

Float: right is messing up the order

Html float right

Make fire float up

Line up img and div css

make ul float right but still have bottom border take up whole page

Text not placed properly when using float:right

Aligning the bottoms of an img (float:left) and a nav (right:float)

CSS Float Left to Line Up

Float <i> to the right of <div> in html

How to get these timestamps, which come after in the html, to float right on the same line

Float Right Pushing Label Text Up

How to make html text input where each line is a different color

How to make <label> and <input> appear on the same line on an HTML form?

Make the right input for json file

Float right without creating new line

Make an element float to the right inside a div

jQuery. make menu float to the right of parent?

How to make a list float to the right in CSS?

How to make a list float to the right in a div

Make slide out up to icon img

How to make mat-label float to the right (RTL language) when appearance is outline and input value is LTR in Angular Material

How can I make input fields line up next to the middle of the labels?

Inline-block, floats or other solution to make squares line up with edge of input on both sides