What is the best way to upload a profile picture to the header of my website?

Looking to customize my home page by adding a profile picture on the left side of the navigation panel. Can anyone guide me on achieving this using only HTML and CSS, without the need for JavaScript?
I want the image to be displayed at the top left corner of the webpage, but I've been struggling to make it work after multiple attempts.
Thank You
--------------------------------------------------------------------------------------
Code:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>PS 2</title>
    <style>
        *{
            padding: 0;
            margin: 0;
        }

        header{
            background-color: black;
            color: white;
            position: sticky;
            top: 0;
        }
        ul{
            padding: 19px;
        }
        li{
            list-style: none;
            display: inline;
            padding: 0 53px;
            font-size: 33px;
        }
        .container{
            display: flex;
            flex-wrap: wrap;
            flex-direction: row;
            justify-content: space-between;
        }
        .left{
            background-color: red;
            height: 80vh;
            width: 40vw;
        }
        .right{
            background-color: blue;
            height: 80vh;
            width: 40vw;
        }
    </style>
</head>
<body>
    <header>
        <nav>
            <ul>
                <li>Home</li>
                <li>About</li>
                <li>Contact Us</li>
            </ul>
        </nav>
    </header>
    <div class="container">
        <div class="left">
            <p>
                Lorem ipsum dolor sit amet, consectetur adipisicing elit. Reiciendis consequuntur porro recusandae beatae, debitis sapiente, adipisci nostrum voluptate pariatur veniam, aliquid iusto consequatur nemo quidem. Quia eveniet fugit mollitia tempora harum eligendi modi natus?
            </p>
        </div>
        <div class="right">
            <p>
                Lorem ipsum dolor sit amet consectetur, adipisicing elit. Enim, totam sapiente unde quos, quia dolor et natus tenetur, nesciunt tempora cum. Facilis laboriosam quas consectetur, placeat adipisci consequuntur consequatur cupiditate deserunt veritatis odit natus delectus tempore possimus, aspernatur ex amet quaerat vero sequi praesentium inventore. Facere distinctio magni, praesentium modi nemo sit quibusdam laudantium molestiae. Provident.
            </p>
        </div>
    </div>
</body>
</html>

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

Answer №1

I have transformed your navigation into a flex container and utilized a div element to position your image on the left-hand side of the navbar. The image is centrally aligned within the div using grid and place-items:center.

* {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}

header {
  background-color: black;
  color: white;
  position: sticky;
  top: 0;
}

nav {
  display: flex;
  padding: 1rem 2rem;
}

.image {
  flex: 0 1 auto;
  display: grid;
  place-items: center;
}

.image>img {
  width: 4rem;
}

ul {
  padding: 19px;
}
  
li {
  list-style: none;
  display: inline;
  padding: 0 53px;
  font-size: 33px;
}

.container {
  display: flex;
  flex-wrap: wrap;
  flex-direction: row;
  justify-content: space-between;
}

.left {
  background-color: red;
  height: 80vh;
  width: 40vw;
}

.right {
  background-color: blue;
  height: 80vh;
  width: 40vw;
}
<header>
  <nav>
    <div class="image"><img src="https://www.fillmurray.com/500/500"></div>
    <ul>
      <li>Home</li>
      <li>About</li>
      <li>Contact Us</li>
    </ul>
  </nav>
</header>
<div class="container">
  <div class="left">
    <p>
      Lorem ipsum dolor sit amet, consectetur adipisicing elit. Reiciendis consequuntur porro recusandae beatae, debitis sapiente, adipisci nostrum voluptate pariatur veniam, aliquid iusto consequatur nemo quidem. Quia eveniet fugit mollitia tempora harum eligendi
      modi natus?
    </p>
  </div>
  <div class="right">
    <p>
      Lorem ipsum dolor sit amet consectetur, adipisicing elit. Enim, totam sapiente unde quos, quia dolor et natus tenetur, nesciunt tempora cum. Facilis laboriosam quas consectetur, placeat adipisci consequuntur consequatur cupiditate deserunt veritatis odit
      natus delectus tempore possimus, aspernatur ex amet quaerat vero sequi praesentium inventore. Facere distinctio magni, praesentium modi nemo sit quibusdam laudantium molestiae. Provident.
    </p>
  </div>
</div>

Answer №2

Revamp your website's header with these CSS modifications:

header {
        background-color: black;
        color: white;
        position: sticky;
        top: 0;
        display: flex;
        align-items: center;
    }
    

Additionally, incorporate this new class into your stylesheet:

.header-img {
        width: 50px;
        height: 50px;
        background-color: red;
        margin: 10px;
    }

To finalize the changes, insert the following HTML snippet within your header section:

<img class="header-img" src=""/>

You can specify the image path by filling in the src attribute.

Answer №3

Include a bullet point list in the header section.

            <ul>
                <li><img src="https://smaller-pictures.appspot.com/images/dreamstime_xxl_65780868_small.jpg" alt="Girl in a jacket" width="50" height="50"></li>
                <li>Home</li>
                <li>About</li>
                <li>Contact Us</li>
            </ul>

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

Creating a default option of "please select" on an Angular select element with a null value for validation

Within my Angular application, I am using a select element with an ngFor loop: <select formControlName="type" required> <option *ngFor="let type of typeList" [ngValue]="type.value">{{ type.caption }}</option> </select> When view ...

Spacious Bootstrap layout - 3 columns with the center column taking up the most space

I am in the process of designing a layout with 3 columns aligned in the same row: The first column should adjust to its content, such as a picture or avatar The third column should also adjust to its content, like a date or time. Meanwhile, the second col ...

What is the best way to manage a hover effect on devices such as iPads?

As a beginner in web development, I am currently facing a challenge when it comes to managing hover effects on devices like iPads. Initially, my solution was to remove the CSS for hover and replace it with click events, but my client prefers to keep the ho ...

Implementing a jQuery function to trigger window resize on window load

I'm facing an issue with my resize function where the contents within a window change when it reaches a certain width. I'm trying to achieve this same effect on window load but haven't been successful so far. Here's what I've attem ...

problem with the picture and wrapper expanding to fill the entire width of the screen

I'm having an issue with the image I added and its hover effect. The image seems to be leaving space on both sides of the screen, even though I've included background-size: cover and width:100% in my code. Could someone please point out where I ...

Adjust the size of the image within a designated container to decrease its proportions when there is an excess of text present

I am working on a project where I need to resize an image based on the available space within its container. When there is text in the description, the image should adjust its size accordingly without pushing the text upwards. I am using React for this pro ...

Use jQuery to place tags around the content of existing <li> elements

Using jquery, I have been able to successfully create a list by using the following code: $(list).append(item); (where list is the list reference and item consists of the $('<li>') elements being added). var item = $('<li>' ...

Struggling to find the solution for coding my css

Hello StackOverflow community, I'm a newcomer here and have been impressed by how friendly everyone is. So, I am taking the plunge and posting my question. My goal is to style an ASP.NET MVC2 form in a way where instead of having all the fields in a ...

Disabled text selection in Internet Explorer

I am in need of making one HTML element (Label) unselectable for IE. I have tried using the following methods: Unselectable=on onselectreturn=false; Unfortunately, none of these solutions are working for me. For Firefox and Chrome, I've successful ...

Creating a sleek Bootstrap 4 navigation bar featuring a trio of items

I am currently using Bootstrap 4 and trying to create a navbar with three items. I want the brand to be on the left and the navbar-nav items on the right. While this part is simple to achieve, I am facing an issue where I want an additional section to be ...

What is the method to programmatically trigger the highlight effect (similar to mouseover) in Javascript or JQuery?

In the process of creating an interface that features a list of large buttons, I am interested in implementing functionality to highlight a button based on the movement of the mouse. Essentially, I would like the button below the currently highlighted butt ...

I am experiencing difficulties with my custom font not functioning properly

I've experimented with the following code: @font-face { font-family: Jua; src: url('/fonts/jua.ttf'); } @font-face { font-family: Jua; src: url('..../fonts/jua.ttf'); } @font-face { font-family: Jua; src: url('.../fonts/jua.t ...

Launching a Bootstrap modal in Portrait mode through JavaScript

Is there a way to trigger the opening of a modal when the screen is in "Portrait" orientation and hide it when the screen is in "Landscape" orientation? I have tried implementing this functionality, but it seems to not work properly when the page initiall ...

Ensure that the select boxes are aligned in a horizontal manner

I am currently attempting to adjust the alignment of select boxes to reduce the staggered appearance. While not all need to be perfectly aligned, it would be ideal to have those that are close enough in alignment. I prefer using HTML to accomplish this tas ...

Conceal and reveal identities with the power of react hooks

I'm just starting to work with React hooks, In my app, I want all user names to be hidden by default. However, when I click on each user, their name should be displayed. To accomplish this, I am using the show and setShow functions. Although when I tr ...

Is it possible to alter the Bootstrap CDN in Django?

Starting out with Django and CSS, I've encountered an issue in my base.html file where I included a bootstrap cdn like this: <meta charset="UTF-8"> <link rel="shortcut icon" href="{% static 'favicon.ico' %}"> <meta http-equiv ...

Can someone help me locate the selector for using .click in Nightmare.js?

I am currently using Nightmare.js to automate the scraping of a webpage. As a sysadmin, my understanding of Node.js and CSS is limited. So far, I have been able to successfully use Nightmare to input and click on certain buttons in order to log in. I iden ...

In the process of transforming my JavaScript code into JQuery

I'm struggling to convert my JavaScript code into jQuery, especially when it comes to calling the function for radio elements by name. The original JavaScript works fine, but I can't seem to get the jQuery version to work correctly. Index HTML ...

Create a division that can alter the background image of a different division when hovered over, even if they are not

I am seeking a solution that will function seamlessly across all browsers to reach a wider audience. I am looking for a list where each "li" element changes the background of a specific "div." You can see the desired look here. My current code is as follo ...

Fixed div at the bottom of the page that will stick to the top

Currently, I have a holding page for my website that is functioning as desired. It features some Vegas-style background fades and a simple navigation bar at the bottom fixed to the page with the following CSS: Position: absolute; bottom: 0; You can view ...