Header with a list and an accompanying image using HTML and CSS

Struggling to incorporate a header featuring a list and a small logo in the top right corner of the page, seamlessly integrated with the header lines. The first image link reflects my desired result while the second image shows where I'm encountering challenges.

Answer №1

This should do the trick:

Utilizing paddings and floats, you can effectively align the elements within your header.

/* Customize the header with a gray background and some padding */
            .header {
              overflow: hidden;
              background-color: gray;
              padding: 10px 10px;
            }

            /* Design the header links */
            .header a {
              float: left;
              color: black;
              text-align: center;
              padding: 12px;
              text-decoration: none;
              font-size: 18px;
              line-height: 25px;
              border-radius: 4px;
            }

            /* Style the logo link (ensuring consistent line-height and font-size to prevent header expansion) */
            .header .logo {
              float: right;
              height: 50px;;
            }

            /* Adjust background color on hover */
            .header a:hover {
              background-color: #ddd;
              color: black;
            }

            /* Style the active/current link*/
            .header a.active {
              background-color: dodgerblue;
              color: white;
            }

            /* Float the link section to the left */
            .header-left {
              float: left;
            }

            /* Implement media queries for responsiveness - stack links when screen width is 500px or less */
            @media screen and (max-width: 500px) {
              .header a {
                float: none;
                display: block;
                text-align: left;
              }
              .header-left {
                float: none;
              }
            }
<div class="header">
          <div class="header-left">
            <a class="active" href="#home">Home</a>
            <a href="#contact">Contact</a>
            <a href="#about">About</a>
          </div>
          <img src="https://www.vectorlogo.zone/logos/stackoverflow/stackoverflow-tile.svg" class="logo" alt="logo"></img>
        </div>

Answer №2

Create a HTML structure with a main wrapper, inner wrapper, and 2 blocks using display: flex; instead of inline-block for better efficiency.

This method allows you to accomplish the task more quickly and effectively.

Sample HTML:

<div class="wrapper">
  <div class="inner-wrapper">
    <div class="sectionA">
      <p>Content Here</p>
    </div>
    <div class="sectionB">
      <p>More Content Here</p>
    </div>
  </div>
</div>

Sample CSS:

.wrapper {
  width: 100%;
  padding: 25px;
  background: #666;
}

.inner-wrapper {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 25px;
  max-width: 768px;
  margin: 0 auto;
}

.sectionA,
.sectionB {
  color: #fff;
  padding: 10px;
}

VIEW DEMO FIDDLE

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

Decoding HTML with Python

My current project involves creating a program that can find the definition of any given word and return it. I managed to achieve this using RegEx to search for text between specific tags where the definitions are stored. However, I am now seeking a more ...

Choose an element by its specific data attribute

I have come across this html code and I am attempting to assign a new class to it using the data attribute: <p class="form-row form-row-wide" data-child-field="child_has_jacket"> </p> Even after trying with jQuery : jQuery( ...

Showing a tooltip in Angular when a button is disabled

<button [disabled]="(!dataConceptSummmaryFlag || dataConceptSummmaryFlag === false) && (!selectedLOBFlag || selectedLOBFlag === false) && (!adsListFlag || adsListFlag === false)" class="lmn-btn lmn-btn-primary" ...

The HTML checkbox is initialized as checked when the page loads

Is there a way to set the checkbox as unchecked in HTML? I have tried multiple ways, but it always loads as checked <input id="chkBox" checked type="checkbox" /> <input id="chkBox" checked=false type="checkbox" /> <input id="chkBox" checked ...

The submission of the form is not possible with jQuery

Here is my code: $(document).ready(function(){ console.log("jquery is functioning"); // **** Global Variables **** //starting ingredient number for new ingredients $ing_num = 3; var new_label; var new_input; $("#add_icon").click(funct ...

Struggling to apply size in percentage to several images used as a background

Displaying two background images with different positioning: html { background: top left no-repeat url(http://wallpapers.pupazzo.org/animals/Peek-a-Boo_Red_Fox_Kit.jpg), top right no-repeat url(http://www.dcwild.com/images/Fox-Kit-Rive ...

Troubleshooting: Bootstrap 5.0 Navbar Dropdown Issue Unresolved

My navbar dropdown isn't working when clicked. I've searched for solutions without success. Is there a script missing? layout.html: <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> ...

Problem with CSS/SASS dropdown navigation bar

Having trouble with a design issue, I have successfully recreated the Twitter navigation bar and now I want a dropdown menu to appear when hovering over the 'settings' text. However, I'm facing difficulties as the overflow is hidden in the n ...

How can you reset the chosen option in a Vue.js dropdown menu?

Within my dropdown menu, I have included a button that is intended to clear the selected city. Despite adding an event, the selected option is not being cleared. Can anyone provide insights on what I might be missing? Thank you in advance. Below is the bu ...

The AngularJS directive seems to be having trouble receiving the data being passed through its scope

Check out this HTML code snippet I created: <div ng-controller="ctrl"> <custom-tag title = "name" body = "content"> </custom-tag> </div> Take a look at the controller and directive implementation below: var mod = angular.mod ...

Turn off hover effect for MUI DataGrid

I'm having trouble figuring out how to disable the hover effect on a row in the MUI Datagrid. I've searched through the API documentation but couldn't find a straightforward solution. Any suggestions on how to achieve this? <DataGrid ...

The nested navigation bar is not displaying properly below the main navigation bar

Hey there! I'm having a bit of trouble with adding a nested nav within my main nav. The issue is that the nested nav isn't aligning properly under the main nav. Take a look at this screenshot for reference. The nested nav seems to be shifted abou ...

What is the best way to give a user the option to select the destination for file uploads?

I currently have a basic upload form set up. Here's the HTML code: <html> <head> <title>Upload a File</title> </head> <body> <font face=verdana size=2> <form enctype="multipart/form-data" method="post" act ...

Implementing a vertical tabindex change in Material UI Dialogue table

My material UI dialogue contains a table: <Dialog open={open} onClose={handleClose} maxWidth={'xl'} aria-labelledby='scroll-dialog-title' aria-describedby='scroll-dialog-description' disa ...

My form does not trigger a 'Save Password' prompt in any browser

I have been struggling to get the browser to prompt a 'Save Password' while using the form below. Despite trying various solutions from different forums, nothing seems to work. Can anyone point out where I might be going wrong? Any help would be ...

What is the best way to achieve this Bootstrap design without copying the content?

Trying to achieve a specific Bootstrap layout without repeating content is my current challenge. Essentially, I aim to divide some content into 2 columns at the sm/md breakpoints and then switch to 3 columns for the lg breakpoint. The layout for sm/md bre ...

How do I create more space in Vitepress to prevent the text from feeling cramped and allow it to display in a larger area?

Below is the content of my index.md file: --- # https://vitepress.dev/reference/default-theme-home-page layout: home hero: name: "TP2" text: "Analyzing the code of TP2 by Breno Mazzali Medeiros Tomazelli and Philippe Bouchard" ta ...

Receiving time slots on a bootstrap schedule

I recently developed a calendar using Bootstrap that allows users to select a start date and automatically sets the end date within a 7-day range from the chosen start date. However, I am facing a challenge in enabling users to also pick minutes along with ...

Beginning of my initial endeavor (seeking feedback, general advice, criticism)

Hey everyone! I'm looking for a forum-style platform similar to Stack Overflow where I can get some feedback on my first project. It's the first one I've built from scratch, so I'm open to any critiques or suggestions on what could be i ...

PHP submitting form saves zeros

I have encountered an issue with submitting a form entry provided by the user. Instead of storing the actual values entered by the user, the database is recording 0 as the input. I require assistance to rectify this problem. Below is my code snippet: & ...