I'm struggling to make my div display inline

My div elements are not displaying inline, I'm thinking maybe I shouldn't use the nav and div structure like this. But starting over again seems like a lot of work. How can I fix this issue?

Just so you know, I'm only on my 4th day of learning CSS and HTML.

.body {
  margin: 0 auto;
  width: 100%;
  clear: both;
}
.mainHeader nav {
  background-color: #DC143C;
  height: auto;
  width: 1264px;
  display: inline-block;
  border-radius: 5px;
  -moz-border-radius: 5px;
  -webkit-border-radius: 5px;
  margin: 0px 0px 0px 0px;
}
.mainHeader nav ul.left {
  list-style: none;
  display: inline;
  position: relative;
  float: left
}
.mainHeader div.right {
  list-style: none;
  display: table-row;
  position: relative;
  float: right;
  margin: 18px 20px 10px 0px;
}
.mainHeader nav ul li {
  float: left;
  display: inline;
  padding-left: 10px
}
.mainHeader div.border {
  width: 0px;
  height: 50px;
  float: left;
  border: 1px inset;
  color: #DC143C;
  margin: 25px 0px 0px 150px;
}
<html>

<head>

</head>

<body class="body">
  <header class="mainHeader">

    <nav>
      <ul class="left">
        <li>
          <a href="#">
            <img style="width:150px;height:70px" src="img/1.gif">
          </a>
        </li>
        <li>
          <a href="#">
            <input type="text" name="search" placeholder="Search..">
        </li>
        </a>
        <li><a href="#"><h2>1</h2></a>
        </li>
        <li><a href="#"><h2>1</h2></a>
        </li>
        <li><a href="#"><h2>1</h2></a>
        </li>
      </ul>
      <div class="border">
        <ul class="right">
          <li><a href="#"><h3> 2</h3></a>
          </li>
          <li><a href="#"><h3> 2</h3></a>
          </li>
          <li>
            <a href="#">
              <img style="width:20px;height:20px" screen="img/16">
            </a>
          </li>
          <!-- bookmark-->
          <li>
            <a href="#">
              <img style="width:20px;height:20px" screen="img/17">
            </a>
          </li>
          <!-- history -->
    </nav>
    </ul>
</body>

</html>

Answer №1

You forgot to close the div tag.

<div class="border"></div>

Also, there is a mistake in your CSS at line:

 .mainHeader div.right{
    list-style:none;
    display:table-row;
    position: relative;
    float:right;
    margin:18px 20px 10px 0px;
}

The correct tag should be ul:

.mainHeader ul.right{
        list-style:none;
        display:table-row;
        position: relative;
        float:right;
        margin:18px 20px 10px 0px;
    }

Please review your code and make sure the /ul tag comes before nav element.

    .body{
        margin:0 auto;
        width:100%;
        clear:both;
    }
    .mainHeader nav{
        background-color:#DC143C;
        height:auto;
        width:1264px;
        display: inline-block;
        border-radius:5px;
        -moz-border-radius:5px;
        -webkit-border-radius:5px;
        margin:0px 0px 0px 0px;
    }
    .mainHeader nav ul.left{
        list-style:none;
        display:inline;
        position: relative;
        float:left
    }
    .mainHeader ul.right{
        list-style:none;
        display:table-row;
        position: relative;
        float:right;
        margin:18px 20px 10px 0px;
    }
    .mainHeader nav ul li{
        float:left;
        display:inline;
        padding-left: 10px
    }
    .mainHeader div.border{
      width: 0px; 
      height: 50px;
      float: left; 
      border: 1px inset;
      color:#DC143C;
      margin: 25px 0px 0px 150px ;
    }
<header class="mainHeader">

    <nav>
    <ul class="left">
        <li><a  href="#"><img style="width:150px;height:70px" src="img/1.gif"></a></li>
        <li><a  href="#"><input type="text" name="search" placeholder="Search.."></li></a>
        <li><a  href="#"><h2>1</h2></a></li>
        <li><a  href="#"><h2>1</h2></a></li>
        <li><a  href="#"><h2>1</h2></a></li></ul>
        <div class="border"></div>
        <ul class="right">
        <li><a  href="#"><h3> 2</h3></a></li>
        <li><a  href="#"><h3> 2</h3></a></li>
        <li ><a  href="#"><img style="width:20px;height:20px" screen="img/16"></a></li>  <!-- bookmark--> 
        <li><a  href="#"><img style="width:20px;height:20px" screen="img/17"></a></li>  <!-- history -->
    </ul></nav>

Answer №2

.body {
  margin: 0 auto;
  width: 100%;
  clear: both;
}
.mainHeader nav {
  background-color: #DC143C;
  height: auto;
  width: 1264px;
  display: inline-block;
  border-radius: 5px;
  -moz-border-radius: 5px;
  -webkit-border-radius: 5px;
  margin: 0px 0px 0px 0px;
}
.mainHeader nav ul.left {
  list-style: none;
  display: inline;
  position: relative;
  float: left
}
.mainHeader div.right {
  list-style: none;
  display: table-row;
  position: relative;
  float: right;
  margin: 18px 20px 10px 0px;
}
.mainHeader nav ul li {
  float: left;
  display: inline;
  padding-left: 10px
}
.mainHeader div.border {
  width: 0px;
  height: 50px;
  float: left;
  border: 1px inset;
  color: #DC143C;
  margin: 25px 0px 0px 150px;
}
<header class="mainHeader">

    <nav>
        <ul class="left">
            <li>
                <a href="#">
                    <img style="width:150px;height:70px" src="img/1.gif">
                </a>
            </li>
            
          <li style="display:flex; height:70px;">
                <a href="#" style="margin:auto;"> 
                    <input type="text" name="search" placeholder="Search..">
                </a>
            </li>

            <li><a href="#"><h2>1</h2></a>
            </li>
            <li><a href="#"><h2>1</h2></a>
            </li>
            <li><a href="#"><h2>1</h2></a>
            </li>
        </ul>
        <div class="border">
            <ul class="right">
                <li><a href="#"><h3> 2</h3></a>
                </li>
                <li><a href="#"><h3> 2</h3></a>
                </li>
                <li>
                    <a href="#">
                        <img style="width:20px;height:20px" screen="img/16">
                    </a>
                </li>
                <!-- bookmark-->
                <li>
                    <a href="#">
                        <img style="width:20px;height:20px" screen="img/17">
                    </a>
                </li>
                <!-- history -->
            </ul>
    
        
</div>
    </nav>
</header>

Hope this information proves useful.

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

Create circular Styled components in React JS

Currently, I am attempting to create a component within a wrapped styled component. The Styled component has a circular shape, and I am seeking assistance in styling it accordingly. Can anyone provide guidance on how to apply the styles needed to achieve a ...

Gap in footer spacing on Internet Explorer is significantly large

The layout of the page is split into two main sections: A large header that takes up 100% of the browser height The main content area and footer When viewing the page in a browser, only one of these sections will be visible. The following code works wel ...

Responsive Design and Advertising with CSS Media Queries

For my application, I am utilizing Twitter's bootstrap (responsive) css. My goal is to incorporate banner ads in the sidebar section. However, due to different media query settings, the sidebar's width will vary, resulting in the need for the ban ...

What methods can be used to modify element attributes in Python?

I'm curious about how to utilize Python to modify an element in the HTML code of a webpage: In this case, I need to change it from: <input _ngcontent-mcp-c552="" type="number" name="bpm" placeholder="0" min= ...

Limit image size in Outlook when using Mailchimp

I'm currently working on coding a Mailchimp template for a client and I've run into an issue with image dimensions. The problem arises when images exceed the width of the template (usually 600px), as they are displayed at their original size in ...

Leverage the calc() function within the makeStyles method

const useStyles = makeStyles((theme) => ({ dialog: { '& .MuiTextField-root': { margin: theme.spacing(1), } }, address: { width:"calc(24vw + 8px)" }, })); <div> <TextField id="contact ...

Lower the placement of Glyphicons

I have recently implemented a custom font on my website. Unfortunately, this font is not standard and its alignment is off. As a result, when I use this font with Twitter Bootstrap glyphicon, they do not appear in the same line. Is there a way to adjust t ...

Locating the save directory with fileSystem API

I've been working on saving a file using the fileSystem API. It appears that the code below is functional. However, I am unable to locate where the saved file is stored. If it's on MacOS, shouldn't it be in this directory? /Users/USERNAM ...

Having trouble getting CSS media query to work in my Rails mailer template

Is it true that media queries do not work in email templates? I have a simple test template and a query BUT can't seem to get it to function properly. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DT ...

Displaying background images as list items on a web page outside of

I am facing an issue with an unordered list within a div where the list item images are floating outside the div. Does anyone have a solution for this? You can see an example of the problem on Any assistance would be greatly appreciated! ...

Pressing the button will allow you to select and copy the text within the

I am looking to incorporate a mock-chat feature into my website. The concept is to type something on the website, then click a button next to it which will move the text to a frame above. I attempted this using a textarea and even found a code for selectin ...

React: The row flex-direction is not being applied as expected

Although I know there are countless identical questions out there, mine lacks context and is as generic as they come. Why isn't the flex-direction row property working? React View return ( <Fragment> <h1>The About us page.</ ...

What is the method for accessing a selector within a foreach loop?

Whenever a user clicks on a date in the jquery datepicker, two ajax calls are triggered. The goal is for the second ajax call to populate the response/data into a paragraph with the class spots within the first ajax call, displaying available spots for th ...

What is the best way to maintain the formatting of a textarea in the database?

My HTML form includes a text area and a functionality to save the data into a database upon submission. The issue arises when the saved data is retrieved from the database, as the original formatting of the text gets altered. For instance: "This is a text ...

Error encountered in my JavaScript file - Unexpected Token < found on line 1 of the loadash.js script

I am right at the end of creating a sample dashboard with charts using dc.js, but I have hit a roadblock with one error remaining. This error is causing an issue. Unexpected token < on line 1 for loadash.js. The loadash.js file is valid, but for som ...

Exploring menu options in a responsive web design interface

Hey, I'm having an issue with my website header. It looks great on full-width screens, but I need to address low screen resolutions using @media queries. I have a checkbox that reveals the menu items when checked. However, I'm facing an overlay p ...

Strangely odd actions from a JavaScript timepiece

After answering a question, I encountered a problem with my JavaScript clock that displays the day, time, and date on three lines. To make sure these lines have the same width, I used the BigText plugin, which works well except for one issue. tday=new A ...

In Form view in Odoo, the field value appears on the following line when editing

When attempting to edit a value in the form view, I am experiencing an issue where the field's value is being pushed onto the next line. <div class="row"> <label string="Website" for="field_id" class="col- ...

Ways to utilize jquery script within a react component

<script> $(document).ready(function() { var source; var destination; var fn = function(event, ui) { toDrop = $(ui.draggable).clone(); if ($("#droppable").find("li[uniqueIdentity=" ...

Can fputs() or fwrite() encode HTML special characters at times?

I have encountered an issue where I am outputting HTML content as a string to an HTML file, but some servers are encoding special characters (for example " becomes \&quot;). Even after using the htmlspecialcharacters_decode function, the problem p ...