Tips for aligning two objects next to each other

Check out this code snippet:

<div class="headmenus">
    <ul>
    <li><a href="index.php">HOME</a></li>
    <li><a href="about.php">ABOUT US</a></li>
    <li><a href="search.php">COURSES</a></li>
    <li><a href="vacancies.php">VACANCIES</a></li>
    <li><a href="contact.php">CONTACT US</a></li>  
    <li></li>           
    </ul>
 </div>
 <div class="searchform2">
    <form action="search.php#goto1" method="get" id="headersearch">
       <input type="hidden" name="p" value="0" />
       <input type="text" name="keyword" id="headerkeyword" placeholder="Search any keyword" value="" />
       <input type="submit" value="SEARCH" class="but1" />
    </form>
 </div>

I want the headmenus and searchform2 to appear next to each other, but currently the searchform2 appears on a separate line.

Below is the CSS for searchform2:

.searchform2 {
    float: right;
    display: inline;
    clear: left;
    width:auto !important;
    border:2px solid #616566;
}
.searchform2 input {
    border:2px solid #616566;
    float: left;
}
.searchform2 .but1 {
    background: url("images/search.png") no-repeat scroll 8px 9px #89AB20;
    border: 0 none !important;
    color: #FFFFFF !important;
    float: right !important;
    display: inline;
    font-weight: bold;
    padding: 6px 12px 6px 23px !important;
    width: auto !important;
    font-family: Arial;
    font-size: 12px;
    height: 30px;
    margin-right: 0 !important;
    cursor:pointer;
}

And here's the CSS for headmenus:

.headmenus {
    background: none repeat scroll 0 0 #0086B2;
    display: inline;
    float: left;
    margin: 0;
    width: 100%;
}
.headmenus ul {
    border-bottom: 1px solid #FFFFFF;
    border-top: 1px solid #FFFFFF;
    display: inline;
    float: left;
    font-family: 'texgyreadventorregular';
    font-size: 14px;
    margin: 0;
    padding: 0;
    width: 100%;
}
.headmenus ul li {
    border-right: 1px solid #FFFFFF;
    color: #FFFFFF;
    display: inline;
    float: left;
    list-style-type: none;
    padding: 0;
    text-align: center;
    width: 13.35%;
}

.headmenus ul li a {
    color: #FFFFFF;
    display: inline;
    float: left;
    font-family: 'texgyreadventorregular';
    font-size: 14px;
    list-style-type: none;
    text-align: center;
    width: 100%;
    padding:5px 0px;
}
.headmenus ul li:last-child {
    border-right: 0 none;
    float: right;
    width: auto; !important
}

.headmenus ul li:hover {
    background: #89ab20;
    cursor: pointer;
}
.headmenus ul li.active {
    background: #89ab20;
}

Answer №1

To make a simple adjustment to the layout, add the "float:left;" class to the headmenus and remove "clear:left" from .searchform2. Follow the instructions below:

.searchform2 {
float: right;
display: inline;
width:auto !important;
border:2px solid #616566;
}
.searchform2 input {
border:2px solid #616566;
float: left;
}
.searchform2 .but1 {
background: url("images/search.png") no-repeat scroll 8px 9px #89AB20;
border: 0 none !important;
color: #FFFFFF !important;
float: right !important;

display: inline;
font-weight: bold;
padding: 6px 12px 6px 23px !important;
width: auto !important;
font-family: Arial;
font-size: 12px;
height: 30px;
margin-right: 0 !important;
cursor:pointer;
}

.headmenus { float:left} 

Answer №2

To style your navigation menu, apply the CSS property display: inline-block to the elements with the class name headmenus.

Check out this JSFIDDLE for a live example.

Answer №3

Try modifying the CSS by adding display:inline-block. This should help solve the issue

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Utilize CSS for Sticky Headers to Create Full Page Scrollbars for Table Control

Here is a code sandbox showcasing the use of Material UI's Table within a Paper component with a sticky header: https://codesandbox.io/s/2n40y I am looking to have the scrollbars appear at the edges of the browser page, bottom and right, while still ...

Swimming Left and Right Arrows

I am struggling to create a layout where images are stacked horizontally, with small arrows centered vertically on the left and right sides for scrolling. However, the arrows are currently centered relative to the page, rather than to the center image. I ...

Understanding how to activate a React navbar button is essential for creating a seamless user

How can I make my sidebar button change color when I navigate to the page it links to? ...

Locating an Image and Adding it to a Different Image Source

Here is the HTML markup that I am working with: <div id="main"> <div id="slider"> <img src=""/> </div> <div class="clear slider"></div> <div class="slider ndslider"> <a href="# ...

Chrome experiencing conflicts with backstretch when using multiple background images

In order to dynamically apply fullscreen background images in a WordPress site, I am utilizing Backstretch.js along with a custom field. Everything is functioning properly for the body's background image. However, there seems to be an issue with anot ...

Looking to retrieve HTML elements based on their inner text with queryselectors?

I am looking to extract all the HTML divs that contain specific HTML elements with innerText = ' * ' and save them in an array using Typescript. If I come across a span element with the innerText= ' * ', I want to add the parent div to ...

How about: "Insert a line break inside a div element"

My goal is to have 3 icons positioned side by side that will float left if the window shrinks. Under each icon, I plan to include some text. Below you can see that I've made progress on this layout. .icons { BORDER-TOP: black 1px solid; HEIGHT: 10 ...

Click to close the dropdown menu

I am working on a problem where I want the dropdown to close when clicking anywhere in the document, instead of just closing when clicking on the dropdown menu itself. Below is a snippet of the HTML and JQuery code that I currently have: HTML: <div cl ...

complete collection of sass and scss website templates

Are there any comprehensive sass/scss templates or mixins similar to what you get with compass, but designed for an entire website? For example, can you define 2 columns, width, color, etc. and have it generate a full site/template? Thanks, Rick ...

Is your margin not functioning correctly? Is padding taking on the role of margin?

One issue I'm encountering is that the margin isn't behaving as expected in this example. The padding seems to be working like margin should. Why is that? Print Screen: https://i.stack.imgur.com/N1ojF.png Why is it that the margin in the h3 ta ...

What is the best way to create divs that can close and hide themselves when clicked from inside the div itself?

I have a situation in my code where clicking a link reveals a div, and then the same link must be clicked again to hide it. However, I want to modify this so that any link within the div can also hide it when clicked. I currently have eight divs set up lik ...

What is the best way to create a scrollable nested div?

Link to Image My goal is to keep the red section fixed while allowing only the blue section to scroll when there is overflow. The red section consists of two divs. I have attempted using position: fixed to achieve this, but encountered issues such as ove ...

The event is being triggered on two separate occasions

Hey there! I'm trying to bind the onclick event to both a parent and child element using the same method. However, I'm running into an issue where the event is being fired twice. Any suggestions on how to prevent this from happening? <div id= ...

Hide only the table that is being clicked on, not all tables

Essentially, I am using document.querySelectorAll() to retrieve an array of div elements. In my function, handleClick(), each time the button is clicked, I want to hide the table associated with that specific button. This is the current situation: https:/ ...

Sharing data between different JavaScript files using Knockout.js

I am working with two JavaScript files named FileA.js and FileB.js. Within FileA.js, there is a function called Reports.CompanySearch.InitGrid: function InitGrid(viewModel, emptyInit) { var columns = [ { name: 'CompanyName', ...

Changing the size of an input field in Bootstrap 4 by utilizing the input-group-append class

Currently, I am working on setting up a pay rate feature that includes two input boxes for numbers. However, I am facing an issue where the input boxes are stretching too much, causing the cents field to drop down to the next line. The Maxlength property ...

Animating the starting angle of an arc using d3.js

I'm looking to animate the starting angle of an arc using D3.js. If anyone has any tips or helpful links, I would greatly appreciate it! Here's what I've already attempted: http://jsfiddle.net/87e3d4tj/ d3.select('#my-path').da ...

Can we keep a portion of the input placeholder content?

The input box below accepts values in percentage form. To indicate this, I have set a placeholder that says Percentage (%). https://i.sstatic.net/LJ1ee.png My goal is to automatically add a % symbol to the value as soon as it is entered into the input fi ...

Hamburger must be used in order for the menu to be displayed

Whenever I visit the site, the menu remains hidden. However, when I resize the page and use the hamburger icon, the menu appears as expected. Even after resizing the page back to its original size, the menu continues to be visible. Refreshing the sit ...

What is the best way to showcase my background image using html and css?

I've come across a similar topic addressing my problem, but I am still unable to resolve it. I am attempting to add a background image to my portfolio, but for some reason, it is not working. Can anyone offer any suggestions or ideas? Here is the cod ...