Incorporating images with text in the navigation bar

Just dipping my toes into the world of HTML and CSS, but I need some guidance.

I'm trying to incorporate images and text (for the title) in my header using a navbar.

However, when I resize the window, the text doesn't move along with the image. It seems like it's due to the left: 480px; in the code, but without it, the text doesn't appear on the image at all.

Is there a way for the text to stay aligned with the image when resizing the window?

FULL-SIZE WINDOW VIEW: https://i.sstatic.net/jsw4D.png

SHRINKING THE WINDOW SIZE: https://i.sstatic.net/Wd8Tx.png

The text is centered with left:480px;. I'd like it to remain on the left side. What adjustments should be made in the code?

.navbar {
  display: block;
  align-items: flex-start;
  padding: 0;
}

.navbar img {
  width: 100%;
  height: 100px;
  display: block;
  position: relative;
}

.navbar span {
  position: absolute;
  z-index: 1;
  color: #fff;
  width: 200px;
  height: 28px;
  font-family: NanumGothic;
  font-size: 24px;
  text-align: left;
  font-weight: bold;
  font-stretch: normal;
  font-style: normal;
  line-height: 12.8px;
  letter-spacing: normal;
  top: 50px;
  left: 480px;
}
<!DOCTYPE html>
<html>

<head>
  <title> Change Member Info</title>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
  <meta name="format-detection" content="telephone=no">
</head>

<body>
  <form id="frm" name="frm">
    <div class="header">
    </div>
    <div class="container">
      <nav class="navbar">
        <div class="navbar__logo">
          <img src="/assets/images/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="503e3f243528240f2439243c350f60641063287e203e37">[email protected]</a>">
          <span>My Website</span>
        </div>
      </nav>
    </div>
  </form>
</body>

</html>

Answer №1

Here are two methods you can use to ensure responsiveness:

1. Utilizing Percentage-Based Margin

.navbar span{
            left: 30%
            }

This method adjusts the spacing based on a percentage of the screen size, allowing for automatic adaptation.

2. Implementing Media Queries

Media queries enable you to apply specific CSS styles depending on various screen sizes.

/* Styling for Full Screen Size */
.navbar span{
                left: 480px
                }


/* For screens 992px or smaller */
@media screen and (max-width: 992px) {
  .navbar span{
                left: 380px
                }
}

/* For screens 600px or smaller */
@media screen and (max-width: 600px) {
 .navbar span{
                left: 300px
                }
}

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

How can I modify the color of JavaFX text using CSS?

Looking to jazz up my JavaFX application with some custom CSS styling. Managed to link a stylesheet to my app using the following code: //Java code FXMLLoader loader = new FXMLLoader(MainApp.class.getResource("/path/to/fxml")); Scene sce ...

Hey there, I was wondering if it's possible to modify the color of the navbar when scrolling on a specific page

After the first 3 pages with a black background and a transparent navbar with white navigation items, I encounter visibility issues when scrolling to the colorful 4th page. Is there a way to change the navbar color on this specific page using ONLY HTML a ...

"Transitioning from jQuery to Vanilla Javascript: Mastering Scroll Animations

I'm seeking guidance on how to convert this jQuery code into pure Javascript. $('.revealedBox').each(function() { if ($(window).scrollTop() + $(window).height() > $(this).offset().top + $(this).outerHeight()) { $(this).addCla ...

Navigating to a webpage using a dropdown menu selection and a button press

I'm new to Angular and wondering if it's possible to select an option from a dropdown menu and then be redirected to a specific page based on that selection <mat-label >Login As</mat-label> <mat-select> ...

The appearance of my HTML is distinct on Chrome for Windows and Safari for OSX

I have designed a prototype of some HTML code, but my website appears differently on Safari compared to how it looks on Chrome. While it displays correctly on Chrome, on Safari (both on OSX and mobile phones) the alignment seems off and randomly centered i ...

Saving an Echo Command in a Variable

I've set up an eye exam program and now I'm trying to figure out how to display the results only after the exam is completed. The issue is that when I echo the stored SESSION variables containing the results, they are displayed even on page refre ...

Is there a way to display data in a checkbox field using PHP and JQuery Mobile?

I am currently working on a challenge in viewsessions.php. My goal is to retrieve multiple values from a database and group them into checkbox fields (such as typeofactivity, employer, date, time, amount as one combined checkbox field) using <input type ...

Determine the total number of active links on an HTML webpage using F#

Currently, I am working on developing a basic F# function that will be able to count the total number of links present in a given HTML website URL. I understand that this can potentially be achieved by counting the occurrences of the "<a" substrings, b ...

Having trouble with the Semantic UI popup not showing div content correctly? Need to display table row data as well? Let's troub

Having trouble with this semantic-ui code popup error. Can anyone provide a solution? $(document).on('click', 'table td', function() { $(this) .popup({ popup: $('.custom.popup') }); }) ...

Making a CSS table fit perfectly inside a container

After reading numerous recommendations on the subject, none of them seem to be effective in my particular situation. The issue lies with a table that is nested within a container ('div' element) as shown below: <div class="container"> ...

Is there a way to direct to a specific URL upon clicking a button using PHP?

In my PHP code called registerprocess.php, it executes after clicking a submit button on another page named userregistration.php. If a user tries to register with an email that already exists in the database, I want registerprocess.php to redirect back to ...

HTML5 allows users to play a extended video for a set duration without the need for any video editing. Users are encouraged to utilize any approach

I have a video file named myvideo.mp4 that is 3 minutes long (or any length). <video width="320" height="240" controls="controls"> <source src="myvideo.mp4" type="video/mp4"> </video> Is there a way to play this myvideo.mp4 for only 20 ...

Guide to positioning an anchor tag in the middle of a container, ensuring the anchor fills the entire space of the container

I'm currently working on making an anchor element expand to cover 100% of its parent element, allowing the entire area to be clickable while also centering the text both vertically and horizontally within the parent. I need some guidance on what CSS c ...

Creating Dynamic Visibility in ASP.NET Server Controls: Displaying or hiding a textbox based on a dropdown selection

Is there a way to dynamically show/hide a textbox or an entire div section based on a user's selection from a dropdown menu? Can this be achieved using client-side HTML controls instead of server controls? Would utilizing jQuery provide the best solut ...

-=:Heading with a decorative vertical line=:-

Currently, I am working on a CSS project that requires page titles (headings) to be centered with horizontal lines positioned vertically on both sides. Additionally, there is a background image on the page which means the title's background must be tr ...

Troubleshooting: Jquery show effects not functioning as expected

Currently, I am facing an issue where I am attempting to display a fixed div using the show function of jQuery. Although the show function itself is working properly, when I try to include an effect from jQuery UI, it does not seem to work as expected. Bot ...

A step-by-step guide on deleting an element within a div using jQuery

I am attempting to delete an HTML element using JQuery like this $('#' + divId + ' .settings_class').remove('.print_settings'); This code does not result in an error or remove the specified html element, however, the selecto ...

Ways to expand the border horizontally using CSS animation from the middle

Currently, I am experimenting with CSS animation and I have a query regarding creating a vertical line that automatically grows in length when the page is loaded. I am interested in making the vertical line expand from the center in both upward and downwar ...

Expanding image in table data to full screen upon clicking using jQuery

I am trying to display an image in my table and then use jQuery to pop up a modal with the full-screen image. However, the image only pops up at the top of the table data. This is the code I have so far: <tbody> <tr> <td><?php ...

What causes the gap between a parent div and inner div in react components?

I have a relatively simple React component that I'm working on. Even though I am quite new to React, I have tried various methods to eliminate the white space issue but so far have been unsuccessful in determining what is causing it. Negative margin s ...