What is the best way to add the header "MyRide" and a navigation bar to a webpage?

As I continue to learn HTML and CSS, I have explored various options but still haven't found the answer I need. In order to seek help, I am sharing my HTML and CSS code snippets here. Any assistance provided would be greatly appreciated.

Below is my HTML code:

<!DOCTYPE html>
<html>
    <head>
        <title>MyRide|Home</title>
        <link rel="stylesheet" href="../css/new.css"/>
    </head>
    
    <body>
        <div class="cover-image heading">
            <header>
                <img src="../images/headerLogo.png" alt="logo" width="25%" height="10%">MyRide
            </header>
            <nav>
                <ul id="ul1">
                    <li class="navbar"><a href="./home.html" class="li1">Home</a></li>
                    <li class="navbar"><a href="./fleet.html"class="li1">Fleet</a></li>
                    <li class="navbar"><a href="./services.html"class="li1">Services</a></li>
                    <li class="navbar"><a href="./about.html"class="li1">About</a></li>
                    <li class="navbar"><a href="./contact.html"class="li1">Contact Us</a></li>
                </ul>
            </nav>              
        </div>
    </body>
</html>

And this is my CSS code:

*{
    margin:0;
    padding: 0;
}
body{
    font-family: Arial, Helvetica, sans-serif;
    color:darkgray;
    flex: 10;
}

.cover-image{
    background-image: url(../images/headercover.jpg);
    background-repeat: no-repeat;
    background-size: cover;
    background-position-y: center;
    background-color: black;
    
    padding-top: 1%;
    padding-bottom: 1%;
}

.heading{
    color: red;
    font-size: 90px;
}

a.li1{
    text-decoration: none;
    color: gold;
}

header,nav{
    margin: 0;
}

.navbar{
    padding-right: 5px;
    display: inline;
    font-size: 28px;
    margin:0;
}
#ul1{
    list-style: none;
    display: inline-block;
    list-style-type: none;
    align-content: end;
    margin-top: 0;
    padding: 0;
}

Having shared the above code snippets, when I view my webpage, the link here is how I want it to appear (indicated by a green line). It appears that the UL element is causing an unwanted new line after the heading, but I'm struggling to find a solution to remove it.

Answer №1

If you're looking for a simple way to handle positioning, consider utilizing flexbox. It streamlines the process and offers flexibility. Take a closer look at properties like display:flex, align-items:, and justify-content:

*{
    margin:0;
    padding: 0;
}
body{
    font-family: Arial, Helvetica, sans-serif;
    color:darkgray;
    flex: 10;
}

.cover-image{
    background-image: url(../images/headercover.jpg);
    background-repeat: no-repeat;
    background-size: cover;
    background-position-y: center;
    background-color: black;
    
    padding-top: 1%;
    padding-bottom: 1%;
    display:flex;
    justify-content:space-between;
}

.heading{
    color: red;
    font-size: 30px;
}

a.li1{
    text-decoration: none;
    color: gold;
}

header,nav{
    margin: 0;
}

.navbar{
    padding-right: 5px;
    display: inline;
    font-size: 16px;
    margin:0;
}
#ul1{
    list-style: none;
    display: inline-block;
    list-style-type: none;
    align-content: end;
    margin-top: 0;
    padding: 0;
}

header{
display:flex;
align-items:center;
}
<!DOCTYPE html>
<html>
    <head>
        <title>MyRide|Home</title>
        <link rel="stylesheet" href="../css/new.css"/>
    </head>
    
    <body>
        <div class="cover-image heading">
            <header>
                <img src="http:\\placeholder.com/50" alt="logo" width="25%" height="10%">MyRide
            </header>
            <nav>
                <ul id="ul1">
                    <li class="navbar"><a href="./home.html" class="li1">Home</a></li>
                    <li class="navbar"><a href="./fleet.html"class="li1">Fleet</a></li>
                    <li class="navbar"><a href="./services.html"class="li1">Services</a></li>
                    <li class="navbar"><a href="./about.html"class="li1">About</a></li>
                    <li class="navbar"><a href="./contact.html"class="li1">Contact Us</a></li>
                </ul>
            </nav>              
        </div>
    </body>
</html>

Answer №2

https://i.sstatic.net/rIKcu.png

If you were thinking about achieving a layout like this, it can be done using the powerful combination of flexbox and grid. These CSS techniques make it easy to manage the positioning of child containers within a parent container.

.cover-image {
  background-image: url(../images/headercover.jpg);
  background-repeat: no-repeat;
  background-size: cover;
  background-position-y: center;
  background-color: black;
  padding-top: 1%;
  padding-bottom: 1%;
  /*flexbox trinity*/
  display: flex;
  justify-content: space-between;
  align-items: center;
}

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

Customizing the appearance of a JavaScript countdown timer's output on an individual basis

I am currently working on customizing the appearance of a JavaScript date counter. My goal is to style the days, hours, minutes, and seconds individually. Ideally, I want each unit to be right-aligned within its own div, with specific left and top absolute ...

Expanding the content width of Bootstrap Nav Pills

I'm currently working with Bootstrap pills that feature two tabs. I would like to customize the width of the tab content container differently for each tab, but I'm unsure how to achieve this. The tab-content class currently sets the same width f ...

What is the best way to combine HTML and Django?

I need help with an HTML file containing a web page design featuring a form where users can enter their name. My goal is to create a six-entry array for each submission to store information for later use on another page. Would Django be the best tool for ...

I'm having trouble with using setInterval() or the increment operator (i+=) while drawing on a canvas in Javascript. Can anyone help me out? I'm new

I am looking to create an animation where a square's stroke is drawn starting from the clicked position on a canvas. Currently, I am facing an issue where the values of variables p & q are not updating as expected when drawing the square at the click ...

Guide: Implementing Bulma Button Styles in React Components

Looking to integrate a Filter Buttons component into a To Do List Application. Specifically, I want to add four buttons for filtering tasks (All, Active, Completed, Important). Can someone guide me on how to incorporate Bulma CSS Rules with this react comp ...

Incorporating jQuery into my HTML code

Struggling to integrate my jQuery script into my index.php file, seeking assistance. The script in question is called script.js $("#toggle-content").click(function () {$("#mel").slideToggle(); }); ...

Choosing a dynamic dropdown option using jQuery and AJAX

I am facing an issue with a select box that is dynamically populated and should display information about a single option. The problem I am encountering is that the browser does not trigger a ':selected' event when I click on any of the options. ...

Why @font-face doesn't display on older versions of Internet Explorer like IE 7 and IE

Our website has the following CSS code. The use of a smiley face is to ensure compatibility with IE 7 and IE 8. However, while the site's fonts display correctly on IE 9, Chrome, Firefox, etc., there seems to be an issue with IE 7 and 8. @font-face { ...

Creating a sleek animation with JQuery for a dynamic-width div

Here is a snippet from my latest project. Take a look at the demonstrationFIDDLE. In this project, I have created a list with buttons: <a href="#f1" class="bt">1 <div class="show">Computers Networking</div> </a> When you ...

Navigating to specific location on page following addition of dynamic elements

My website utilizes ajax for dynamically adding content, and I am attempting to make the page automatically scroll to the newly added content. However, despite my efforts, I am unable to get it to function properly. Below is the link I am currently using ...

Is it possible to center the image and resize it even when the window is resized?

My goal is to position an image in the center of the screen by performing some calculations. I've tried using: var wh = jQuery(window).innerHeight(); var ww = jQuery(window).innerWidth(); var fh = jQuery('.drop').innerHeight(); var fw = jQ ...

The master of the site instructs the pages to wait for loading...but the site somehow manages to partially come up

Despite the fact that it's not typically recommended, we had to implement this approach for a specific project. Essentially, I have a site master page that displays a "Please wait while loading..." message in a div to prevent the page from showing unt ...

How can I horizontally center an element in CSS/HTML if auto-margin does not produce the desired result?

This is a snippet of the CSS code I'm using for my menu: ul { text-align: left; display: inline; margin: auto; width: 50%; position: fixed; top: 0; list-style: none; } I've attempted to use auto-margin left and right ...

Advanced Image Upload using HTML5 and Ajax in the 'background'

As someone who is just learning HTML5 and Ajax, I'm curious to know if it's feasible to use these technologies to create a service that enables users to upload an image in the background while they navigate through different pages on the same sit ...

`A mistake occurred while building in the package.json file`

While attempting to run all build processes by using the command npm run build:css, I encountered an error indicated below. Even after running npm cache clean --force, the issue remains unresolved. https://i.sstatic.net/4edDo.png npm ERR! code ELIFECYCLE ...

What is the best way to prevent a single cell within a table from hovering?

Within a table cell, I have another table. The outer table has a hover effect applied to it, but I want to prevent the inner table with the id "table_I_don_not_want_to_hover" from inheriting this hover behavior like the rest of the cells and rows. I need t ...

Exploring the application of styles within the shadow DOM

I'm experimenting with applying styles to the shadow DOM. Consider the following example: const element = document.getElementById("bar"); const shadowRoot = element.attachShadow({ mode: "open" }); const greeting = document.createElement("p"); gree ...

What is the best way to design a div that includes two separate columns for text and an image icon?

Check out this code: <?php foreach ($data as $vacancy) { ?> <div class="vacancy"> <img src="<?php echo Yii::app()->request->baseUrl; ?>/images/vacancy_icon.jpg" /> <div class="name"> < ...

A method for setting a value from an HTML textbox to a variable and displaying it on the same page

How can I retrieve the value from a textbox and display it on the same page? The purpose behind this is that when the user enters their BTC wallet into the textbox, I want to store this value in a variable on the same page and then output the value. I at ...

Guide to vertically centering Font Awesome icons inside a circular div

Is there a way to perfectly center align font awesome icons vertically? I have tried using the line-height property when text is present, and even setting the line-height equal to the height of the div. Attempts with display:inline-block and vertical-alig ...