Alright, what I am trying to do is, I want the button beside my text box to be aligned beside the text box whenever my page resize, which would cause my text box to shrink or expand accordingly ( as you can see below in the following snippet) Can someone help me out here? Thanks in advance for the help!
function myFunction() {
var x = document.getElementById("myTopnav");
if (x.className === "topnav") {
x.className += " responsive";
} else {
x.className = "topnav";
}
}
.topnav {
background-color: transparent;
}
.topnav a {
display: inline-block;
color: black;
padding: 14px 16px;
text-decoration: none;
font-size: 16px;
}
.topnav .icon {
display: none;
}
.dropdown {
float: right;
padding-top: 5px;
}
.hehe {
float: right;
padding-top: 5px;
}
.dropdown .dropbtn {
font-size: 17px;
border: none;
outline: none;
color: black;
padding: 14px 16px;
background-color: inherit;
font-family: inherit;
margin: 0;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
}
.dropdown-content a {
float: none;
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.topnav a:hover,
.dropdown:hover .dropbtn {
background-color: transparent;
color: skyblue;
}
.dropdown-content a:hover {
background-color: #ddd;
color: black;
}
.dropdown:hover .dropdown-content {
display: block;
}
#media screen and (max-width: 900px) {
.topnav a:not(:nth-child(-n+2)),
.dropdown .dropbtn {
display: none;
}
.topnav a:not(:nth-child(-n+2)),
.hehe {
display: none;
}
.topnav a.icon {
float: right;
display: block;
}
}
#media screen and (max-width: 900px) {
.topnav.responsive {
position: relative;
}
.topnav.responsive .icon {
position: absolute;
right: 0;
top: 0;
}
.topnav.responsive a {
float: none;
display: block;
text-align: left;
}
.topnav.responsive .dropdown {
float: none;
}
.topnav.responsive .hehe {
float: none;
}
.topnav.responsive .dropdown-content {
position: relative;
}
.topnav.responsive .dropdown .dropbtn {
display: block;
width: 100%;
text-align: left;
}
.topnav.responsive .hehe {
display: block;
width: 100%;
text-align: left;
}
}
.searchFeature {
border: 1px solid #999;
padding: 3px 18px 3px 4px; /* Use the same right padding (18) in jQ! */
border-radius: 3px;
/* transition: background 0.4s; */
width:40%;
position: absolute;
top: 18px;
left: 75px;
}
.test {
position: absolute;
top: 20px;
left: 350px;
}
<div class="topnav" id="myTopnav" ng-controller="searchController">
<img ng-src="" />LOGO
<input type="text" class="searchFeature" ng-model="selected" ng-keyup="$event.keyCode == 13 && searchFunction()" uib-typeahead="value for value in themename | filter:$viewValue | limitTo:7" placeholder="Start your search here..."><button class="test">Test</button>
<div class="hehe">
Developer
Data Enquiry
</div>
<div class="dropdown">
<button class="dropbtn">Categories <i class="fa fa-caret-down"></i></button>
<div class="dropdown-content" >
<a ng-click="pickCate(x)" ng-repeat="x in selectCate">{{ x }}</a>
</div>
</div>
☰
</div>
Remove absolute positioning from both .test and .searchFeature, then wrap them in a flexbox. I also recommend adding a min-width to the input.
HTML:
<div class="search-wrapper">
<input type="text" class="searchFeature" ng-model="selected" ng-keyup="$event.keyCode == 13 && searchFunction()" uib-typeahead="value for value in themename | filter:$viewValue | limitTo:7" placeholder="Start your search here...">
<button class="test">Test</button>
</div>
CSS:
.search-wrapper {
display: flex;
flex-direction: row;
}
.test {}
.searchFeature {
border: 1px solid #999;
padding: 3px 18px 3px 4px; /* Use the same right padding (18) in jQ! */
border-radius: 3px;
/* transition: background 0.4s; */
width:40%;
}
Related
body {
margin: 0;
font - family: Arial,
Helvetica,
sans - serif;
}
.topnav {
overflow: hidden;
background - color: #333;
}
.topnav a {
float: left;
display: block;
color: # f2f2f2;
text - align: center;
padding: 14 px 16 px;
text - decoration: none;
font - size: 17 px;
}
.topnav a: hover {
background - color: #ddd;
color: black;
}
.topnav a.active {
background - color: #04aa6d;
color: white;
}
.topnav .icon {
display: none;
}
#media screen and (max-width: 600px) {
.topnav a:not(:first-child) {
display: none;
}
.topnav a.icon {
float: right;
display: block;
}
}
#media screen and (max-width: 600px) {
.topnav.responsive {
position: relative;
}
.topnav.responsive .icon {
position: absolute;
right: 0;
top: 0;
}
.topnav.responsive a {
float: none;
display: block;
text-align: left;
}
}
/* select dropdown css code */
select {
-webkit-appearance: none;
-moz-appearance: none;
-ms-appearance: none;
appearance: none;
outline: 0;
box-shadow: none;
border: 0 !important;
background: # 5 c6664;
background - image: none;
flex: 1;
padding: 0 0.5e m;
color: #fff;
cursor: pointer;
font - size: 1e m;
font - family: "Open Sans", sans - serif;
}
select::-ms - expand {
display: none;
}
.select {
position: relative;
display: flex;
width: 20e m;
height: 3e m;
line - height: 3;
background: #5c6664;
overflow: hidden;
border-radius: 0.25em;
}
.select::after {
content: "\25BC";
position: absolute;
top: 0;
right: 0;
padding: 0 1em;
background: # 2 b2e2e;
cursor: pointer;
pointer - events: none;
transition: 0.25 s all ease;
}
.select: hover::after {
color: #23b499;
}
<div class="topnav" id="myTopnav">
Red FMTuning
Choose a tune from ur favourite
<a href="#contact">
<div class="select">
<select name="format" id="format">
<option selected>Choose a book format</option>
<option value="pdf">PDF</option>
<option value="txt">txt</option>
<option value="epub">ePub</option>
<option value="fb2">fb2</option>
<option value="mobi">mobi</option>
</select>
</div>
</a>
About
<a href="javascript:void(0);" class="icon" #click="myFunction()">
<i class="fa fa-bars"></i>
</a>
</div>
As in the above image, u can see the , all the elements like "tuning", "Choose a tune from ur favourite" , "Choose a book format", ""About". All the contents are not in proper shape. and mainly the dropdown("Choose a book format") it is in not aligned according to other content. and when click on dropdown also. it is overlapping on content.
I need to align all the elements until it reaches to some 1200px like below.
Code:- https://jsfiddle.net/se8pa7m3/2/
I have wrapped "Choose a book format", "About" <div class="topnav-inner-wrap"> and applied flexbox css on .topnav & .topnav-inner-wrap
Working Demo: https://jsfiddle.net/k2beLnrv/
function myFunction(){
var x = document.getElementById("myTopnav");
if (x.className === "topnav") {
x.className += " responsive";
} else {
x.className = "topnav";
}
}
body {
margin: 0;
font-family: Arial, Helvetica, sans-serif;
}
.topnav {
overflow: hidden;
background-color: #333;
display: flex;
align-items: center;
justify-content: space-between;
}
.topnav a {
float: left;
display: block;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}
.topnav a:hover {
background-color: #ddd;
color: black;
}
.topnav a.active {
background-color: #04aa6d;
color: white;
}
.topnav .icon {
display: none;
}
#media screen and (max-width: 600px) {
.topnav > a:not(:first-child) {
display: none;
}
.topnav a.icon {
float: right;
display: block;
}
}
#media screen and (max-width: 600px) {
.topnav.responsive {
position: relative;
display: block;
}
.topnav.responsive .icon {
position: absolute;
right: 0;
top: 0;
}
.topnav.responsive a,
.topnav.responsive .topnav-inner-wrap {
float: none;
display: block;
text-align: left;
}
}
#media screen and (max-width: 1200px) {
.topnav > a:not(:first-child), .topnav .topnav-inner-wrap {
display: none;
}
.topnav a.icon {
float: right;
display: block;
}
}
#media screen and (max-width: 1200px) {
.topnav.responsive {
position: relative;
display: block;
}
.topnav.responsive .icon {
position: absolute;
right: 0;
top: 0;
}
.topnav.responsive a,
.topnav.responsive .topnav-inner-wrap {
float: none;
display: block !important;
text-align: left;
}
}
/* select dropdown css code */
select {
-webkit-appearance: none;
-moz-appearance: none;
-ms-appearance: none;
appearance: none;
outline: 0;
box-shadow: none;
border: 0 !important;
background: #5c6664;
background-image: none;
flex: 1;
padding: 0 0.5em;
color: #fff;
cursor: pointer;
font-size: 1em;
font-family: "Open Sans", sans-serif;
}
select::-ms-expand {
display: none;
}
.select {
position: relative;
display: flex;
width: 20em;
height: 3em;
line-height: 3;
background: #5c6664;
overflow: hidden;
border-radius: 0.25em;
}
.select::after {
content: "\25BC";
position: absolute;
top: 0;
right: 0;
padding: 0 1em;
background: #2b2e2e;
cursor: pointer;
pointer-events: none;
transition: 0.25s all ease;
}
.select:hover::after {
color: #23b499;
}
.topnav-inner-wrap {
display: flex;
align-items: center;
}
<div class="topnav" id="myTopnav">
Red FMTuning
Choose a tune from ur favourite
<div class="topnav-inner-wrap">
<a href="#contact">
<div class="select">
<select name="format" id="format">
<option selected>Choose a book format</option>
<option value="pdf">PDF</option>
<option value="txt">txt</option>
<option value="epub">ePub</option>
<option value="fb2">fb2</option>
<option value="mobi">mobi</option>
</select>
</div></a
>
About
</div>
<a href="javascript:void(0);" class="icon" onclick="myFunction()">
<i class="fa fa-bars"></i>
</a>
</div>
Check this fiddle. You can use flexbox for this scenario. Add these properties to your topnav:
display: flex;
align-items: center;
justify-content: space-evenly;
align-items is used to align the items vertically, and justify-content is used to space them equally. You can only use both properties if you've set the display to flex.
More on flexbox here.
Use justify-content:space-between; in the parent class
How do i display the icons in the right place as shown in the following image? :
HTML Code
<header id="logo"></header>
<div class="navbar" id="nav">
Home
Facilities
Airlines Offices
<input type="text" placeholder="Search..">
<a href="javascript:void(0);" class="icon" onclick="myFunction()"><i class="fa fa-bars"></i>
</a> </div>
</div>
<script>
function myFunction() {
var x = document.getElementById("nav");
if (x.className === "navbar") {
x.className += " responsive";
} else {
x.className = "navbar";
}
}
</script>
CSS Code
.navbar {
overflow: hidden;
background-color: #0000ff;
}
.navbar a {
float: left;
display: block;
color: white;
text-align: center;
padding: 14px 14px;
text-decoration: none;
font-size: 17px;
height:18px;
}
.active {
background-color: #0033CC;
color: white;
}
.navbar .icon {
display: none;
}
.navbar a:hover, input:hover {
background-color: #dddddd;
color: black;
}
/* CSS for search box */
.navbar input[type=text] {
float: right;
padding: 12px;
border: none;
margin-top: 3px;
margin-right: 5px;
}
#media screen and (max-width: 600px) {
.navbar a, .navbar input {
display: none;
}
.navbar a.icon {
float: left;
display: block;
}
}
#media screen and (max-width: 600px) {
.navbar.responsive {position:relative;}
.navbar.responsive .icon {
position: absolute;
right: 0;
top: 0;
}
.navbar.responsive a {
float: none;
display: block;
text-align: left;
}
.navbar.responsive input {
float: none;
display: block;
width: 90%;
padding: 12px;
border: 2px solid black;
text-align: left;
}
}
Note: For the search box I need to make it as a HTML form, and the font awesome search icon to be a submit button, not just normal HTML icon tag.
To achieve this just update your HTML with following code
<header id="logo"></header>
<div class="navbar" id="nav">
Home
Facilities
Airlines Offices
<form class="search-box">
<input type="text" placeholder="Search..">
<button type="submit" class="search-icon"><i class="fa fa-search"></i></button>
</form>
<i class="fa fa-bars"></i>
</div>
<script>
function myFunction() {
var x = document.getElementById("nav");
console.log(barIcon)
if (x.className === "navbar") {
x.className += " responsive";
var barIcon = document.getElementsByClassName('fa-bars')[0];
barIcon.classList.add("fa-times");
barIcon.classList.remove("fa-bars");
} else {
var closeIcon = document.getElementsByClassName('fa-times')[0];
closeIcon.classList.remove("fa-times");
closeIcon.classList.add("fa-bars");
x.className = "navbar";
}
}
</script>
and Your CSS with the following
.navbar {
overflow: hidden;
background-color: #0000ff;
}
.navbar a {
float: left;
display: block;
color: white;
text-align: center;
padding: 14px 14px;
text-decoration: none;
font-size: 17px;
height:18px;
}
.active {
background-color: #0033CC;
color: white;
}
.navbar .icon {
display: none;
}
.navbar a:hover, input:hover {
background-color: #dddddd;
color: black;
}
/* CSS for search box */
.navbar .search-box {
float: right;
position: relative;
margin-top: 3px;
padding-right: 30px;
display: flex;
}
.navbar .search-box input {
padding: 12px;
border: none;
width: 100%;
height: 100%;
padding: 10px;
}
.navbar .search-box button {
color: #999;
border: navajowhite;
padding: 10px;
}
#media screen and (max-width: 600px) {
.navbar a, .navbar .search-box, .navbar .search-icon {
display: none;
}
.navbar a.icon {
float: left;
display: block;
}
}
#media screen and (max-width: 600px) {
.navbar.responsive {position:relative;}
.navbar.responsive .icon {
position: absolute;
right: 0;
top: 0;
}
.navbar.responsive a {
float: none;
display: block;
text-align: left;
}
.navbar.responsive .search-box {
float: none;
display: flex;
width: 90%;
padding: 4%;
border: 2px solid black;
}
.navbar.responsive .search-icon{
display: flex;
}
}
Enjoy!
Hi there are millions of ways to reach this structure. I usually use MDBOOTSTAP . But if you are looking for a raw html css, you can use the relative/absolute capability. This answer assumes that you have font awsome installed for the search icon:
<style>
.position-relative{
position:relative;
}
.position-absolute{
position:absolute;
}
.w-100{
width:100%;
}
.search-container{
top:0.5rem;
right:1rem;
z-index:99999;
}
</style>
<div class="navbar" id="nav">
Home
Facilities
Airlines Offices
<div class="position-relative w-100">
<input type="text" placeholder="Search.." class="w-100 p-3 m-0">
<div class="position-absolute search-container">
<a href="javascript:void(0);" class="icon" onclick="myFunction()"><i class="fa fa-bars"></i>
</a>
</div>
Here is a dropdown and I want to make this like wp. When anyone arrive the dashboard and click on the avatar.Dropdown will show full screen. And when anyone visit this dashboard from pc and click on the avatar. This drop-down size will be 180px.
Here's codepen link check this out and give me solution.
In media query position relative not working. Please help me out to fix that.
<div class="dropdown">
<button class="dropbtn">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQbnpURUI0RXpHWPtUZouzXUDiXme-mFvQDjzuXbeRE3XB5QGKOYg" alt="User Profile">
</button>
<div class="dropdown-content">
Inad Islam
Edit my Profile
Log Out
</div>
</div>
.dropbtn {
margin: 0;
border: 0;
outline: 0;
background: inherit;
font: inherit;
cursor: pointer;
width: 100%;
height: 50px;
line-height: 50px;
padding: 5px 5px 0 5px;
}
.dropdown {
overflow: hidden;
}
.dropdown-content {
display: none;
position: absolute;
left:0;
background: #4796b3;
width: 100%;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown-content a {
margin:0;
padding: 10px;
color: #fff;
font-size: 18px;
text-decoration: none;
display: block;
}
.dropdown:hover .dropdown-content {
display: block;
}
.dropbtn img {
width: 40px;
height: 40px;
}
.dropdown:hover .dropbtn {
background: #25a2c1;
}
#media only screen and (min-width: 900px) {
.dropdown {
position: relative;
disolay: inline-block;
}
.dropdown-content {
min-width: 160px;
}
}
If I understand you correctly by 'responsive' I have come up with a solution.
I removed the position:absolute and left:0 from the .dropdown-content. I also removed the typo that you did on your media-query.Try this out.
https://codepen.io/ekinalcar/pen/PMBPMd
.dropdown-content {
display: none;
background: #4796b3;
width: 100%;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
#media only screen and (min-width: 900px) {
.dropdown {
position: relative;
}
}
$(document).ready(function(){
$('.dropbtn').click(function(){
$(this).next('.dropdown-content').slideToggle();
});
});
body{margin:0px; padding:0px;}
.dropbtn {
margin: 0;
border: 0;
outline: 0;
background: inherit;
font: inherit;
cursor: pointer;
width: 100%;
height: 50px;
line-height: 50px;
padding: 5px 5px 0 5px;
}
.dropdown-content {
display: none;
position: absolute;
left:0;
background: #4796b3;
width: 100%;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown-content a {
margin:0;
padding: 10px;
color: #fff;
font-size: 18px;
text-decoration: none;
display: block;
}
.dropbtn img {
width: 40px;
height: 40px;
}
.dropdown:hover .dropbtn {
background: #25a2c1;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="dropdown">
<button class="dropbtn"><img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQbnpURUI0RXpHWPtUZouzXUDiXme-mFvQDjzuXbeRE3XB5QGKOYg" alt="User Profile"></button>
<div class="dropdown-content">
Inad Islam
Edit my Profile
Log Out
</div>
</div>
Hope so this will help full for you.
In my CSS code, the navbar boxes resize when the screen's width changes and also resizes when the screen is smaller than 600px amount of pixels. The drop-down box and content also resizes like the navbar boxes, however, the content is not resizing properly. When the screen is resized, the drop-down content is slightly smaller than the drop-down box, but, when the screen is less than 600px, it becomes larger than the box.
I had tried making the drop down content width the same as the boxes, however, this had no affect. I tried this with all the classes that is related to the content. None of them affected anything.
Note: I changed the background colour so that you can see how the content wasn't the same width as the drop-down box itself.
body {
background-color: blue;
}
p {
color: white;
font-size: 20px;
display: inline;
padding: 20px;
font-family: arial;
}
.navbar {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: rgb(10,10,10);
top: 0;
}
.navcont {
margin: 0;
position: relative;
float: left;
}
.navcont a, .dropbtn {
margin: 0;
position: relative;
display: block;
color: white;
font-size: 20px;
text-align: center;
padding: 5vh 7vw;
text-decoration: none;
border-right: 1px solid rgb(50,50,50);
border-left: 1px solid rgb(50,50,50);
}
.navcont a:hover {
transition-duration: 0.3s;
background-color: rgb(30,30,30);
}
.navcont a:active {
background-color: rgb(9,194,36);
}
.sticky {
position: sticky;
position: -webkit-sticky;
top: 0;
z-index:3
}
.dropdown:hover .dropbtn {
transition-duration: 0.3s;
background-color: red;
}
li.dropdown {
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown-content a {
color: black;
padding: 5vh 7.4vw;
text-decoration: none;
display: block;
text-align: left;
}
.dropdown-content a:hover {
background-color: #f1f1f1
}
.dropdown:hover .dropdown-content {
display: block;
}
#media screen and (max-width: 600px) {
.navcont a {
padding: 3vh 3vw;
}
.dropdown-content {
padding: 3vh 3vw;
}
a.dropdown-content {
padding: 3vh 3vw;
width: 100%;
}
.dropbtn {
padding: 3vh 3vw;
}
div.tr_about {
width: 60%;
}
div.tl_about {
width: 37.5%;
}
}
<!doctype html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div>
<ul class="navbar">
<li class="navcont">Home</li>
<li class="navcont">About</li>
<li class="navcont">Purchase</li>
<li class="dropdown" style="float: right;">
Contact
<div class="dropdown-content">
Support
FAQ
</div>
</li>
</ul>
</div>
</body>
</html>
As mentioned above, I want the drop-down box content to have the same width as the drop-down box when the screen is being resized. However, the actual results I got was the content being slightly narrower than the drop-down box, and then when the screen is less than 600px wide, it becomes wider than the box.
modify your media query like below
.dropdown-content {
padding: 1vh 1vw;
right:10px;
}
a.dropdown-content {
padding: 1vh 1vw;
width: 98%;
}
.dropdown-content a {
padding: 5vh 2.9vw;
}
body {
background-color: blue;
}
p {
color: white;
font-size: 20px;
display: inline;
padding: 20px;
font-family: arial;
}
.navbar {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: rgb(10,10,10);
top: 0;
}
.navcont {
margin: 0;
position: relative;
float: left;
}
.navcont a, .dropbtn {
margin: 0;
position: relative;
display: block;
color: white;
font-size: 20px;
text-align: center;
padding: 5vh 7vw;
text-decoration: none;
border-right: 1px solid rgb(50,50,50);
border-left: 1px solid rgb(50,50,50);
}
.navcont a:hover {
transition-duration: 0.3s;
background-color: rgb(30,30,30);
}
.navcont a:active {
background-color: rgb(9,194,36);
}
.sticky {
position: sticky;
position: -webkit-sticky;
top: 0;
z-index:3
}
.dropdown:hover .dropbtn {
transition-duration: 0.3s;
background-color: red;
}
li.dropdown {
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown-content a {
color: black;
padding: 5vh 7.4vw;
text-decoration: none;
display: block;
text-align: left;
}
.dropdown-content a:hover {
background-color: #f1f1f1
}
.dropdown:hover .dropdown-content {
display: block;
}
#media (max-width:650px) {
.navcont a {
padding: 3vh 3vw;
}
.dropdown-content {
padding: 1vh 1vw;
right:10px;
}
a.dropdown-content {
padding: 1vh 1vw;
width: 98%;
}
.dropdown-content a {
padding: 5vh 6.8vw;
}
}
#media screen and (max-width: 600px) {
.navcont a {
padding: 3vh 3vw;
}
.dropdown-content {
padding: 1vh 1vw;
right:10px;
}
a.dropdown-content {
padding: 1vh 1vw;
width: 98%;
}
.dropdown-content a {
padding: 5vh 2.9vw;
}
.dropbtn {
padding: 3vh 3vw;
}
div.tr_about {
width: 60%;
}
div.tl_about {
width: 37.5%;
}
}
<body>
<div>
<ul class="navbar">
<li class="navcont">Home</li>
<li class="navcont">About</li>
<li class="navcont">Purchase</li>
<li class="dropdown" style="float: right;">
Contact
<div class="dropdown-content">
Support
FAQ
</div>
</li>
</ul>
</div>
</body>
PFB code that is working as per your requirement
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style type="text/css">
body {
background-color: blue;
}
p {
color: white;
font-size: 20px;
display: inline;
padding: 20px;
font-family: arial;
}
.navbar {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: rgb(10,10,10);
top: 0;
}
.navcont {
margin: 0;
position: relative;
float: left;
width: 24% !important;
}
.navcont a, .dropbtn {
margin: 0;
position: relative;
display: block;
color: white;
font-size: 20px;
text-align: center;
padding: 5vh 7vw;
text-decoration: none;
border-right: 1px solid rgb(50,50,50);
border-left: 1px solid rgb(50,50,50);
}
.navcont a:hover {
transition-duration: 0.3s;
background-color: rgb(30,30,30);
}
.navcont a:active {
background-color: rgb(9,194,36);
}
.sticky {
position: sticky;
position: -webkit-sticky;
top: 0;
z-index:3
}
.dropdown:hover .dropbtn {
transition-duration: 0.3s;
background-color: red;
}
li.dropdown {
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown-content a {
color: black;
padding: 5vh 7.4vw;
text-decoration: none;
display: block;
text-align: left;
}
.dropdown-content a:hover {
background-color: #f1f1f1
}
.dropdown:hover .dropdown-content {
display: block;
}
#media screen and (max-width: 600px) {
.navcont a {
padding: 3vh 3vw;
}
.dropdown-content {
padding: 3vh 3vw;
}
a.dropdown-content {
padding: 3vh 3vw;
width: 100%;
}
.dropbtn {
padding: 3vh 3vw;
}
div.tr_about {
width: 60%;
}
div.tl_about {
width: 37.5%;
}
}
</style>
</head>
<body>
<div>
<ul class="navbar">
<li class="navcont">Home</li>
<li class="navcont">About</li>
<li class="navcont">Purchase</li>
<li class="dropdown" style="/* float: right; */">
Contact
<div class="dropdown-content">
Support
FAQ
</div>
</li>
</ul>
</div>
</body>
</html>
Can someone help me to align the search bar beside my icon? This is how it currently looks like.
Before expanding :
After expanding :
I want to have my search bar beside my image after expanding, can someone help me out here? Thanks!
function myFunction() {
var x = document.getElementById("myTopnav");
if (x.className === "topnav") {
x.className += " responsive";
} else {
x.className = "topnav";
}
}
.topnav {
background-color: transparent;
}
.topnav a {
display: inline-block;
color: black;
padding: 14px 16px;
text-decoration: none;
font-size: 16px;
}
.topnav .icon {
display: none;
}
.dropdown {
float: right;
padding-top: 5px;
}
.hehe {
float: right;
padding-top: 5px;
}
.dropdown .dropbtn {
font-size: 17px;
border: none;
outline: none;
color: black;
padding: 14px 16px;
background-color: inherit;
font-family: inherit;
margin: 0;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
}
.dropdown-content a {
float: none;
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.topnav a:hover,
.dropdown:hover .dropbtn {
background-color: transparent;
color: skyblue;
}
.dropdown-content a:hover {
background-color: #ddd;
color: black;
}
.dropdown:hover .dropdown-content {
display: block;
}
#media screen and (max-width: 900px) {
.topnav a:not(:nth-child(-n+2)),
.dropdown .dropbtn {
display: none;
}
.topnav a:not(:nth-child(-n+2)),
.hehe {
display: none;
}
.topnav a.icon {
float: right;
display: block;
}
}
#media screen and (max-width: 900px) {
.topnav.responsive {
position: relative;
}
.topnav.responsive .icon {
position: absolute;
right: 0;
top: 0;
}
.topnav.responsive a {
float: none;
display: block;
text-align: left;
}
.topnav.responsive .dropdown {
float: none;
}
.topnav.responsive .hehe {
float: none;
}
.topnav.responsive .dropdown-content {
position: relative;
}
.topnav.responsive .dropdown .dropbtn {
display: block;
width: 100%;
text-align: left;
}
.topnav.responsive .hehe {
display: block;
width: 100%;
text-align: left;
}
}
<div class="topnav" id="myTopnav" ng-controller="searchController">
<img ng-src="" />LOGO
<input type="text" class="searchFeature" ng-model="selected" ng-keyup="$event.keyCode == 13 && searchFunction()" uib-typeahead="value for value in themename | filter:$viewValue | limitTo:7" placeholder="Start your search here...">
<div class="hehe">
Developer
Data Enquiry
</div>
<div class="dropdown">
<button class="dropbtn">Categories <i class="fa fa-caret-down"></i></button>
<div class="dropdown-content" >
<a ng-click="pickCate(x)" ng-repeat="x in selectCate">{{ x }}</a>
</div>
</div>
☰
</div>
Try adding, position: relative; to the nav, and an absolute for .searchFeature
.topnav{
position: relative;
}
.searchFeature{
position: absolute;
top: 15px;
left: 65px;
}
Here you have a codepen!