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

What measures can be taken to safeguard this hyperlink?

Is there a way to conceal HTML code from the source code? For instance: jwplayer("mediaplayer").setup({ file: "http://example.com/Media.m3u8", autostart: 'true', controlbar: 'bottom', file: "http://exa ...

Is it possible to direct the user to a particular link upon swiping to unlock?

Hello everyone, I could use some assistance with this code. I am looking to redirect someone to a specific page when they swipe to unlock and automatically transfer them to another page when the swipe ends. Any help is greatly appreciated. Thank you! $ ...

Ways to automatically adjust the margins of my HTML body page

I'm currently working on a school project to develop a website. The challenge I'm facing is customizing the navbar and header background colors in such a way that they extend seamlessly to the end of the page. Despite my efforts, there seems to b ...

css: text not enclosed by a span tag

I created an HTML-CSS demo with two simple span tags. I added some content to each span, and applied the same CSS code to both. Surprisingly, the content of the right span goes beyond the border, while the content of the left span stays within the border. ...

In landscape mode on Safari for iOS, the final item in a vertical flexbox may be cut off

Describing my app: It is structured as a 3-row flexbox column. <div class="app" style="display: -webkit-flex; -webkit-flex-direction: column; -webkit-justify-content: space-around;"> <div class="question-header" style="-webkit-flex: 0 0 0;"&g ...

What is the method to obtain the content height of individual pages in Android, with or without the use of JavaScript?

I am facing an issue while trying to retrieve the content height of each webpage consecutively. When I load pages separately, I can successfully get the height of each page. However, when I attempt to fetch the content height continuously for webpages in a ...

Customize your file input with Bootstrap 4 using bs-custom-file-input and create a Symfony 5 collection with dynamic upload fields

The issue of not having a label for the chosen filename in a bootstrap 4 upload field has been resolved using the plugin https://github.com/Johann-S/bs-custom-file-input You can utilize "bs-custom-file-input" to showcase the selected filename in the boots ...

Is it possible to change the CSS styling of a specific DIV class that contains nested anchor tags using jQuery?

The HTML: <div id="main_menu"> <a id="menu_item_articles" href="articles">articles</a> </div> The CSS: #main_menu { float: left; padding-top: 10px; vertical-align: middle; text-align: center; width: 500px; ...

Creating a flexible grid layout with DIVs that share equal width dimensions

Struggling with my HTML and CSS code, I need a way to structure nested DIV blocks into a responsive grid where each block has the same width. Despite my efforts, nothing seems to work as expected. Currently, the nested DIVs are stacked vertically one on to ...

How come my image isn't cooperating with text-align and vertical-align?

Hey everyone! I'm a newcomer to this community and a newbie when it comes to HTML. :D I encountered a problem recently and discovered that Stackoverflow is full of amazing developers. That's why I've decided to share my problem here and am ...

What is the best way to use HTML and CSS to center images and headings on a webpage?

This task is really testing my patience... I'm attempting to create a layout that resembles the following: Logo img|h1|img The horizontal lines flanking the subtitle serve as a visual guide, like this --- Subtitle --- Below is the snippet of H ...

CSS animation: Final position once the vertical text has finished scrolling

I have designed a CSS-animated headline with a leading word and three vertically-scrolling/fading statements to complete the sentence, inspired by the style used on careers.google.com. The animation runs through three cycles and stops, leaving the third st ...

Take the attention away from the canvas

Is there a way to shift focus away from the canvas and onto input fields in my HTML code? Right now, the canvas is holding onto focus even when I'm clicking on text inputs. This prevents me from typing anything into them. Ideally, I'd like for t ...

What is the best way to eliminate extra space at the bottom of glide.js?

Looking for assistance to eliminate the whitespace at the bottom of an image or slider. Can anyone help? Here is a preview of the image: https://i.stack.imgur.com/mEYY3.png If you'd like to take a look, here is the project code link: I had to down ...

Paths of least resistance: Absolute URLs for assets in CSS

What could be causing the absolute path for this asset (the font) not to work while the relative path does? <body> hello friend </body> <style type="text/css"> @font-face { font-family: 'Gilroy'; /* src: ur ...

A common inquiry: how can one pinpoint a location within an irregular figure?

I have been studying Html5 Canvas for a few weeks now, and the challenge mentioned above has puzzled me for quite some time. An irregular shape could be a circle, rectangle, ellipse, polygon, or a path constructed by various lines and bezier curves... I ...

Animations with absolute positioning not rendering correctly in Safari

I recently created a basic animation that involves setting an element to "position: absolute" in order to translate it. Everything functions perfectly as intended on Chrome, however, when testing it on Safari, the absolute positioning seems to be completel ...

The CSS code conceals the icon within the background

Could someone please help me out? I am new to this and can't seem to figure out what's wrong. The phone icon seems to be hidden behind a white background. Everything else looks fine, but I really want the icon to be in the front with a border and ...

I am interested in displaying a tooltip when a button is hovered over

In my application, there is a button with the ID #download_setup. Currently, an AJAX call is triggered upon clicking this button. However, there are certain users for whom I need to prevent this AJAX download and instead display a tooltip saying "you don&a ...

Animating Angular ng-template on open/close state status

I am looking to add animation when the status of my ng-template changes, but I am unable to find any information about this component... This is the code in my report.component.html <ngb-accordion (click)="arrowRotation(i)" (panelChange)="isOpen($even ...