What is the best way to arrange my links side by side in CSS/HTML?

I've been working on a coding assignment and struggling to get my links in the navigation bar to appear next to each other. They currently display as blue, underlined links stacked on top of one another. Below are my HTML and CSS codes. If anyone could assist me, I would greatly appreciate it.

HTML:

<!doctype html>
<html class="no-js" lang=""> 


    <head>


       <style>

body{ background-image: url("js/images/htmlbackground.jpeg");      
}
 </style>




        <meta charset="utf-8">
        <meta http-equiv="x-ua-compatible" content="ie=edge">
        <title>Courtney Geller</title>
        <meta name="The works of Courtney Geller" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <link rel="apple-touch-icon" href="apple-touch-icon.png">
        <!-- Place favicon.ico in the root directory -->

        <link rel="stylesheet" href="css/normalize.css">
        <link rel="stylesheet" href="css/main.css">
        <link rel="stylesheet" href="css/custom.css">



        <!--the information cascades down to the classes below! -->
        <!-- you have to put all your styles and things into this so that the file can find it in this folder! This is where it looks for everything!-->

        <script src="js/vendor/modernizr-2.8.3.min.js"></script>

    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/phaser/2.4.4/phaser.js"></script>



           </head>



    <body>
        <!--[if lt IE 8]>
            <p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
        <![endif]-->

        <!-- Add your site or application content here -->   

<div class= "maincontainer">
    <div class="navBar">
    <div id="nav_wrapper">
       <div><ul><li><a href=" ftp://locomoku.com/courtney-geller/Project%201-Home/index.html">About Me</a></li></ul>
  <li><a href="courtneygellerphotography.tumblr.com">My Work</a></li>
        </ul></div></div>
    </div>
    <div class= "mainpicture">     
     <img src="js/images/frontimage.png" alt= "Front image" height="200" width= "350">     
 </div>    

    <div>
        <p class="more"; text-align: center;>I'm Courtney, I'm from Maine and I'm a certified weather spotter. My major is Art, Technology and Culture at the University of Oklahoma, and my minor is Meteorology.<br>I like baking, knitting, weather, and mozzarella sticks.<br>For more about me and some of my work, click the links above.</p>

     </div>   



     <script type="text/javascript" accesskey="" ></script>



        <image: src = "js/images/htmlbackground.jpeg">



        <script src="https://code.jquery.com/jquery-1.12.0.min.js"></script>
        <script>window.jQuery || document.write('<script src="js/vendor/jquery-1.12.0.min.js"><\/script>')</script>
        <script src="js/plugins.js"></script>








        <!-- Google Analytics: change UA-XXXXX-X to be your site's ID. -->
        <script>
            (function(b,o,i,l,e,r){b.GoogleAnalyticsObject=l;b[l]||(b[l]=
            function(){(b[l].q=b[l].q||[]).push(arguments)});b[l].l=+new Date;
            e=o.createElement(i);r=o.getElementsByTagName(i)[0];
            e.src='https://www.google-analytics.com/analytics.js';
            r.parentNode.insertBefore(e,r)}(window,document,'script','ga'));
            ga('create','UA-XXXXX-X','auto');ga('send','pageview');
        </script>



    </body>


</html>



CSS:


body {

    background-color: #ffffff;
    margin: 0;
    font-family: sans-serif;
    font-size: 18px;
    display: inline-block;
}
    .more { 
    margin-left: 430px;
    margin-right: 300px;
    margin-top:265px;
    color: #ffffff;
    font-size:15px;
    text-align:center;  
}


    .navBar{
     background-color: #222;
     display: inline-block;
}

    #nav_wrapper{
    width: 960px; 
    margin: 0 auto;
    text-align: left; 
    display: inline-block;
}

#nav ul{
list-style-type: none;
padding: 0;   
margin: 0;
position: relative; 
display: inline-block;
}    

#nav ul li{
 display: inline-block;  
}

#nav ul li:hover{
  background-color: #ccc;  
}

#nav ul li a, visited{
background-color: white;
    color: #ff903f;
    border: 2px solid none;
    padding: 10px 20px;
    margin-left:460px;
    margin-top: 100px;
    text-align: center;
    text-decoration: none;
    position:relative;
}

#nav ul li a:hover{
  color: #ccc; 
  text-decoration: none;
}




.mainpicture{
position: absolute;
top: 135px;
left: 430px;   
}

Answer №1

Here is some CSS code you can add to your stylesheet:

ul li{
 float:left;
 display:inline;

}

Alternatively, you can use the following code for styling links within list items:

ul li a{
  display:inline-block;
  width:100px;}/*or adjust the width as needed*/

Additionally, make sure to specify #nav ul li a:link and a:visited instead of just #nav ul li a, visited.

Lastly, remember that a:hover should always come after a:link and a:visited in your CSS declarations.

Answer №2

<!doctype html>
<html class="no-js" lang="en"> 


    <head>


       <style>

body{ background-image: url("js/images/htmlbackground.jpeg");      
}
 </style>




        <meta charset="utf-8">
        <meta http-equiv="x-ua-compatible" content="ie=edge">
        <title>Courtney Geller's Portfolio</title>
        <meta name="description" content="The works of Courtney Geller">
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <link rel="apple-touch-icon" href="apple-touch-icon.png">
        <!-- Place favicon.ico in the root directory -->

        <link rel="stylesheet" href="css/normalize.css">
        <link rel="stylesheet" href="css/main.css">
        <link rel="stylesheet" href="css/custom.css">



        <script src="js/vendor/modernizr-2.8.3.min.js"></script>

    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/phaser/2.4.4/phaser.js"></script>



           </head>



    <body>
        <!--[if lt IE 8]>
            <p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
        <![endif]-->

        <div class= "maincontainer">
            <div class="navBar">
                <div id="nav_wrapper">
                    <ul>
                        <li><a href=" ftp://locomoku.com/courtney-geller/Project%201-Home/index.html">About Me</a></li>
                        <li><a href="courtneygellerphotography.tumblr.com">My Work</a></li>
                    </ul>
                </div>
            </div>
            <div class= "mainpicture">     
                <img src="js/images/frontimage.png" alt= "Front image" height="200" width= "350">     
            </div>    

            <div>
                <p class="more"; text-align: center;>I'm Courtney, I'm from Maine and I'm a certified weather spotter. My major is Art, Technology and Culture at the University of Oklahoma, and my minor is Meteorology.<br>I like baking, knitting, weather, and mozzarella sticks.<br>For more about me and some of my work, click the links above.</p>

             </div>   

             <script type="text/javascript" accesskey="" ></script>

                <image: src = "js/images/htmlbackground.jpeg">

                <script src="https://code.jquery.com/jquery-1.12.0.min.js"></script>
                <script>window.jQuery || document.write('<script src="js/vendor/jquery-1.12.0.min.js"><\/script>')</script>
                <script src="js/plugins.js"></script>

                <script>
                    (function(b,o,i,l,e,r){b.GoogleAnalyticsObject=l;b[l]||
                    function(){(b[l].q=b[l].q||[]).push(arguments)};b[l].l=+new Date;
                    e=o.createElement(i);r=o.getElementsByTagName(i)[0];
                    e.src='https://www.google-analytics.com/analytics.js';
                    r.parentNode.insertBefore(e,r)}
                    (window,document,'script','ga'));
                    ga('create','UA-XXXXX-X','auto');ga('send','pageview');
                </script>

            </body>


        </html>

            <style>
            body {

                background-color: #ffffff;
                margin: 0;
                font-family: sans-serif;
                font-size: 18px;
            }
                .more { 
                margin-left: 430px;
                margin-right: 300px;
                margin-top:265px;
                color: #ffffff;
                font-size:15px;
                text-align:center;  
            }


                .navBar{
                 background-color: #222;
                    text-align:right;
            }

                #nav_wrapper{
                margin: 0 auto;
                text-align: left; 
            }

            #nav_wrapper ul{
            list-style-type: none;
            padding: 0;   
            margin: 0;
            } 
            #nav_wrapper li{
                display: initial;
                padding:10px 10px;
            }
            #nav_wrapper ul li:hover{
              background-color: #ccc;  
            }

            #nav_wrapper ul li a: visited{
            background-color: white;
                color: #ff903f;
                border: 2px solid none;
                text-align: center;
                text-decoration: none;
            }

            #nav_wrapper ul li a:hover{
              color: #ccc; 
              text-decoration: none;
            }

            </style>

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

Automatically expanding PrimeNG Turbotable rows

I am using a PrimeNg turbotable that has a row expansion feature enabled. I am looking for a way to automatically expand the rows by default when the table loads. Shown below is my code: HTML <p-table [columns]="cols" [value]="cars" dataKey="vin"> ...

What is the process for activating a button after a checkbox has been selected? Additionally, how can a value be dynamically transferred from a checkbox to the rezBlock_1 block?

What could be the reason for my code not functioning properly? How can I enable a button once a checkbox is selected? Also, is there a way to dynamically move text from a checkbox to the rezBlock_1 block? CODPEN https://codepen.io/RJDio/pen/RwPgaaZ doc ...

In order to show the responses underneath, we must first identify the parent comment

Currently, I have two different forms for comments - one is the "parent" comment form and the other is a response form. I am looking for ways to: Capture which response corresponds to which parent comment in the script Maintain the hierarchy of response ...

Issue with Mobile NavBar remaining visible after clicking on target element in HTML CSS

On my website, everything works perfectly with the Nav bar except for when I am on mobile. When I click on any href from my Nav Bar, it directs me to the correct location but does not close the Nav Bar afterward. I need it to function this way: After click ...

How can I retrieve all the data for the chosen item in a mat-select within a mat-dialog, while still preserving the code for setting the default selected value

In my modal dialog, I have a dropdown menu populated with various languages. The ID of the selected language is bound to the (value) property for preselection purposes when data is passed into the dialog. However, I am looking for a way to also display the ...

Difficulties arise when attempting to display an input within a Bootstrap modal

Upon clicking an icon, I aim to display a bootstrap modal prompting the user to input text and a date. I have adapted code from W3Schools to create the necessary form. Unfortunately, when the button is clicked, only the labels and text area are shown, not ...

Is there a way for me to replicate the reloading problem that occurs when a button is clicked within an HTML

Recently, I encountered a problem with our company's Web product where pressing a certain button resulted in the entire page being reloaded. This issue reminded me of a similar situation described on this website. Following the solution provided there ...

What is the best way to implement CSS in this JavaScript Fetch code in order to manipulate the text's position and font style

Hello, I am just starting out with JS. Is there a way for me to customize the position and font of text in this JS Fetch function using CSS? Any help will be greatly appreciated. let file = 'art.txt'; const handleFetch = () => { fe ...

How do I make toasts completely opaque in Bootstrap 4 by adjusting the transparency settings?

Currently, I am utilizing Bootstrap 4.6 and not able to make the switch to BS 5 just yet. Is there a way for me to modify the opacity of toasts to be completely opaque? This is how my toast appears: <div id="help" style="position: fixed; ...

The jQuery HTTP Post function suddenly stopped functioning properly, only working when lengthy strings are entered

Just starting out with web development. I have a bootstrap page featuring a form for users to input data. The form includes two text boxes, one radio button, and one dropdown menu. My goal was to collect this input data and create a JSON object to POST it ...

Alignment of Images in a Navbar According to Height

I am in the process of developing a website using Bootstrap 4 and I am trying to create a centered navbar with the navbar-brand. By placing navbar-nav on each side of the navbar-brand, I was able to achieve this layout. However, my issue is that the navb ...

Organize information before making a choice in the dropdown menu

Currently, I have a dropdown menu in HTML that allows you to order the data by different options: <select ng-model="sortOrder" ng-options="option.value as option.name for item in options"></select> In addition, I have implemented code using n ...

Can an element be positioned in relation to the border-box of its parent element?

Check out this jsfiddle for an example: http://jsfiddle.net/apmmw2ma/ <div class='outer'> <div class='inner'> Inner. </div> Outer. </div> div.outer { position: absolute; left: 10px ...

Exploring the world of HTML parsing with Node.js

When I try to launch my index.html page with nodejs, I keep encountering an Application error on Heroku. Can anyone help me troubleshoot what might be wrong with my code? #/!/usr/bin/env node var express = require('express'); var app = expr ...

How can the HTML input fields be adjusted to generate the specific array needed in PHP?

I have created an HTML form with the following structure: <form action="sample_test.php" method="post"> <input type="text" name="fileName" value="8.png" id="fileName[]"> <input type="text" name="fileLink" value="https://www.filepicker.i ...

Disable transparency on images in the Materialize carousel layout

I am currently using a 3d carousel that involves displaying images with some opacity. However, I would like to remove the opacity effect on the images. $('.carousel').carousel({ dist:0, shift:0, padding: ...

AngularJS issue, variable not updating in place of {{clientCount}}

I'm sorry about the formatting issue. I am seeing "{{clientCount}}" on my screen instead of the number '10'. Any suggestions? Thank you! var app = angular.module('metaDashboard', []); /**This code is for the meta-dashboard ...

Guide on making a hybrid bar chart using both stacked and grouped bars in chartjs

I'm looking to design a bar chart with a specific format in mind: After checking out the documentation provided on the website for creating stacked bar charts here, I attempted to replicate it but couldn't achieve the desired result. I've ...

Angular 10: Oops! An issue occurred stating that the mat-form-field needs to have a MatFormFieldControl inside

When attempting to set up a form group on a page, I encountered the following error: ERROR Error: No value accessor for form control with name: 'modalidade' at _throwError (forms.js:2431) at setUpControl (forms.js:2339) at FormGroupDirective.addC ...

Font that has been downloaded is not showing up on the HTML document

I recently downloaded a new font and ensured the file location is correct, but for some reason it's not working: <style> @font-face { font-family:"myfont"; src: url('fonts/Helvetica85Heavy_22449.ttf'); } h1 { font-family: ...