CSS Relative versus Absolute Placement

My current website design involves using CSS relative and absolute positioning to place a div of links within an image. However, I'm facing an issue where the links shift left or right when zooming in/out or viewing the site on a mobile device. How can I ensure that the links remain fixed in position on the image?

Check out my website at: www.cclandscaping.org

CSS Code:

.header-links {
        position: absolute;
        z-index: auto;
        right: 25%;
        top: 43%;
        font-size: x-large;
    }
    .header-pic {
        position: relative;
    }

Image and Links Code:

<div class="header-pic"; style="text-align: center">
        <asp:Image ID="Image2" runat="server" ImageUrl="~/Images/Header.png" />
        <div class="header-links">
                <asp:HyperLink ID="HyperLink5" runat="server" NavigateUrl="~/Default.aspx">Home</asp:HyperLink>
                &nbsp;|&nbsp; 
                <asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl="~/Pages/About.aspx">About</asp:HyperLink>
                &nbsp;|&nbsp; 
                <asp:HyperLink ID="HyperLink3" runat="server" NavigateUrl="~/Pages/References.aspx">References</asp:HyperLink>
                &nbsp;|&nbsp; 
                <asp:HyperLink ID="HyperLink4" runat="server" NavigateUrl="~/Pages/ContactUs.aspx">Contact Us</asp:HyperLink>
    </div>

Answer №1

.header-pic should be styled with a specific width and centered:

.header-pic {
    margin: 0 auto;
    position: relative;
    width: 1100px;
}

Answer №2

Make sure your relative links are contained within an absolute structure.

For example, switch out relative for absolute in your stylesheet.

.nav-links {
        position: relative;
        z-index: auto;
        right: 50%;
        top: 30%;
        font-size: large;
    }
    .nav-pic {
        position: absolute;
    }

By using absolute positioning, the links will stay constrained within the specified div.

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

Can you explain the purpose of Microsoft.DependencyValidation.Analyser and the reason why Visual Studio 2017 automatically installs the package?

Recently, I installed Visual Studio 2017 on a brand new Windows 10 virtual machine as part of the upgrade process from 2015. Our current project is built on .Net 4.5.2 (ASP.NET classic, not Core). Oddly, every time I open my current solution in VS 2017, i ...

Tips for personalizing the color, font style, background color, and alignment of the WhatsApp share button I designed using HTML

Currently, I am working on adding a WhatsApp share button to a webpage. I would like to customize it using some CSS code. Could someone kindly provide me with the code for customizing this button? <a href="whatsapp://send?text=https://vcard.score ...

How can we adjust the flex values to ensure the label displays properly on a narrow container width?

The labels in the left column of the form are initially sized correctly, but shrink when there is not enough room. However, there's a discrepancy in label size between rows with 2 items and rows with 3 items. body { font-family: Arial; font-siz ...

Get notified about the number of cells you've selected by simply dragging on a table

Is there a way to display the number of selected cells in a table when dragging with the mouse? I have a table set up, and I'd like to create an alert that shows how many cells are selected while dragging. Here is the link to my fiddle: http://jsfiddl ...

How can recursive data be displayed in a template?

I am working with a model in Django that has a ForeignKey pointing to itself, and I need to display all the data from the database using lists and sublists: Below is my model definition: class Place(models.Model) name = models.CharField(max_length=1 ...

Automate the verification of access to a specified path using FormsAuthentication in a programmatic way

Is there a way to automate the testing of whether the current user has permission to access a specific path? This would involve restricting access to a resource accessed through a handler instead of directly by its path. For instance, considering these co ...

Choose all elements that share a common class

I want to create a hover effect that highlights all elements on a page with the same class. This is the code I currently have: $(document).ready(function () { $('p.myclass').mouseover(function () { $(this).addClass('hover'); }); $( ...

The background image is not displaying correctly

I've been struggling to add a background to the menu section at the top of my webpage. I uploaded the image to www.ra3manifesto.co.nf and want the logo, h1, and menu bar to be placed on top of it. I attempted to set this background using the following ...

Notifying Users through ASP.Net using System.Net.Mail

My code is shown below: protected void Unnamed_Click(object sender, EventArgs e) { try { System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage(); mail.To.Add(ConfigurationManager.AppSettings["Emai ...

The navigation menu links that are meant to stay fixed at the top of the page are not functioning

On my website, I implemented Foundation's Magellan sticky menu at the bottom. Strangely, when I view the site in Firefox, the menu functions properly. However, when I try to open it in Google Chrome, the links don't work (and the cursor pointer d ...

use angularjs directive to position a div absolutely aligned with the right edge of another div

I am attempting to use an angularjs directive to align the right side of an absolute div with another div. The code is working, but I am encountering an issue where the children divs are slightly wider than their parent, causing the offsetWidth value to be ...

Table on the absolute position within an overflow scroll container

I'm encountering an issue with a custom select list within a table. The absolute position of the select list is not working properly within the table, causing it to fill the height of the table. My desired outcome is for the select list to overlay the ...

"Troubleshooting vertical tab inconsistencies in Jquery: addressing unexpected gaps and alignment

After spending a considerable amount of time on this, I'm still struggling to make it work properly. The main issue is the gap between the tabs and the content area. I've tried adjusting the positioning, but it ends up affecting the overall layo ...

Is there a way to eliminate the button's background color when clicking on an area outside of it

I recently designed a search bar with a category dropdown button, and managed to successfully customize its hover, active, and focus states to remove the background color. However, I encountered an issue where clicking outside the button to close the dropd ...

Which specific CSS stylesheet do LinkedIn, Facebook, and Quora utilize for their websites?

I've been curious about how websites like Linkedin, Facebook, or Quora design their sites. When I view them in responsive mode in my browser, I noticed that the content stays fixed at 1000px or 1100px and doesn't change. However, when I access th ...

Strategies for adjusting text size to fit within a resizable div container

I'm facing an issue with a resizable div that has text inside. When I resize the div, the last line of the text goes beyond the boundaries of the div. How can I ensure that all the text fits within the resizable div while maintaining the appropriate f ...

How do you access System.DirectoryServices assemblies in Visual Studio Code?

Currently, I am trying to utilize System.DirectoryServices in an ASP.NET web application. My goal is to implement the guidelines provided in this tutorial regarding active directories (https://msdn.microsoft.com/en-us/library/ms180890(v=vs.90).aspx). Howev ...

What is the best way to adjust for additional spacing created by a scrollbar using CSS?

Is there a way to maintain alignment between two elements on a webpage, even when a scrollbar disrupts the layout? This challenge arises when one element needs to be aligned with another, but the appearance of a scrollbar throws off the alignment. How can ...

Why does the hamburger menu appear below the div when I open it?

I had a vision to create a web app that would be fully functional on all devices, so I designed a navigation bar for full-screen display and a hamburger menu for smaller screens. However, I encountered a problem with my skills page. When I open the menu, i ...

What is the method for incorporating a dotted line preceding the menu options?

I am currently working on an asp.net menu that looks like this: <div id="left"> <div id="menus" runat="server"> <div id="left_menu"> <div class="abc"> < ...