I am trying to make my CSS divs remain in the exact same position on the background image, even when the browser is resized both horizontally and vertically. How can I achieve this?

I need the red dot divs to remain fixed on a world map, regardless of browser resize. Not sure if I should be adjusting div properties or background.

Here's my CSS code, any feedback is appreciated as I'm new to web design:

HTML:

<!DOCTYPE html>
<html lang='en'>
    <head>
        <meta charset="utf-8">
        <link rel="stylesheet" href="style.css">
        <title>My World</title>

    </head>

    <body>

        <div id="home" class="home">
            <div id="dallas" class="box dallas"></div>
            <div id="hongkong" class="box"> </div>
            <div id="capetown" class="box"></div>
            <div id="seoul" class="box"></div>
            <div id="mumbai" class="box"></div>
            <div id="northampton" class="box"></div>
            <div id="sanfrancisco" class="box"></div>
            <div id="newyork" class="box"></div>
        </div>

    </body>

        <script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
        <script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
        <script src="interactive.js" type="text/javascript" charset="utf-8"></script>
</html>

CSS:

/*****************
MAIN
******************/
body {
    background: url('worldmap.jpg');
    background-position: center center;
    background-attachment: fixed;
    background-size: cover;


}

#home {


}

/* Button Design */

.box {
    width: 15px;
    height: 15px;
    background-color: #FE2E64;
    text-shadow: 0 1px 0 rgba(255,255,255,0.2);
    border-radius: 100%;


}


/*****************
HOME BUTTONS (Placement only)
******************/

.home {
    position: relative;
} 

#dallas {
    margin-left: 22.5%;
    margin-top: 7%;

}

#hongkong {
    margin-left: 81.2%;
    margin-top: 1.5%;

}

#capetown {
    margin-left: 55%;
    margin-top: 15%;

}

#seoul {
    margin-left: 85%;
    margin-top: -22.5%;

}

#mumbai {
    margin-left: 69.5%;
    margin-top: 4.5%;
}

}

#northampton {
    margin-left: 29%;
    margin-top: -8.5%;


}

#sanfrancisco{
    margin-left: 15%;
    margin-top: 0%%;

}

#newyork {
    margin-left: 28%;
    margin-top: -2%;
}

/*****************
HOVER 
******************/

#dallas:hover {
    background-color: #F5A9BC;
    cursor: pointer;
}

#hongkong:hover {
    background-color: #F5A9BC;
    cursor: pointer;
}


#capetown:hover {
    background-color: #F5A9BC;
    cursor: pointer;
}

#seoul:hover{
    background-color: #F5A9BC;
    cursor: pointer;
}

#mumbai:hover{
    background-color: #F5A9BC;
    cursor: pointer;
}

#northampton:hover {
    background-color: #F5A9BC;
    cursor: pointer;
}

#sanfrancisco:hover {
    background-color: #F5A9BC;
    cursor: pointer;
}

#newyork:hover {
    background-color: #F5A9BC;
    cursor: pointer;
}

Answer №1

.main {
    position: relative;
}

It might be better if you change it to position: FIXED

Answer №2

To ensure that the dots remain stationary, consider implementing the following code:

position:fixed; 

This CSS property will fix the position of the dots on the page, preventing them from moving.

Answer №3

To ensure a consistent width for your .homepage container, you can specify a fixed value using CSS. Here's an illustration:

.homepage {
    width: 720px;
}

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

<div> issues with background display

I have created two different sections with distinct backgrounds. However, I am facing an issue where these two divs are not appearing on the webpage. My intention is to position the Navbar at the top and have another section below it that is not linked to ...

Toggle Visibility of Elements with Javascript and Html

I've been working on implementing a "Show All / Hide All" feature. Currently, clicking on the text opens the image and text individually. However, I am looking to add a functionality for expanding all divs at once. To see how it currently functions, ...

Neglect the styling of the element wrapper

Imagine I have two divs set up like so: <div name="parent" style="color:blue;padding:5px"> <div name="child" style="background:red"> Text that disregards the color:blue and padding:5px properties, yet still follows the background:red set ...

How to successfully implement ng-show with Html5's <dialog> tags

It's incredible how simple Html5 dialogs are. It feels like they should have been here 15 years ago! I'm having trouble getting ng-show to work with dialogs. Any tips on how to make it happen? <!DOCTYPE html> <html ng-app="project"> ...

The embedded iframe on YouTube is displaying the incorrect video

I am currently designing a website and I want to feature a video on the homepage. The video is hosted on YouTube and I need to embed it into my website. <html> <iframe width="560" height="315" src="https://www.youtube.com/embed/spPdelVEs_k?rel= ...

Safari browser not supporting CSS @property --rotate functionality

This card's animation is functioning well in Chrome, but it is not compatible with Safari and Mozilla Firefox. I suspect the issue lies with the @property --rotate, as it is no longer supported by Safari. Therefore, I am searching for an alternative ...

Steps to gather all the images within a directory

Take a look at this demo When you click on the "next" button, new images are loaded from the internet. In my application, all the images are stored in the img/image folder with names like 1.jpg, hi.png, etc. My question is, how can I display these image ...

Integrating fresh fonts into TinyMCE's font selection choices

I recently reviewed a thread regarding Google Fonts and TinyMCE, and I have successfully added new fonts to TinyMCE in the past. However, I am currently facing an issue where I am unable to add a new font called "Samman" that I obtained from MyFonts.com. ...

What causes a div to shift to the right when the margin-left is set to auto?

I am curious to understand why setting the margin-left of the div with id="pink" to auto causes the div to move to the right side. Take a look at the image below: HTML <div id="aqua">aqua</div> <div id="yellow">yellow</div> & ...

The CSS selector "not:nth-child" is failing to function properly within the template

Trying to apply a margin-top to all labels except the first one in a row using the :not() and :nth-child selectors. Having trouble with my selector, can anyone help? .form-group:not(:nth-child(1)) + .label { margin-top: 20px; } <div class="form- ...

Adjusting the width of columns in a flex layout using Bootstrap 4

On mobile, I am attempting to rearrange some elements in a different order. Currently, this is what I have: https://i.stack.imgur.com/fY3PQ.png Below is the HTML code: <main> <div data-color="yellow"></div> <div class="wrapper"& ...

Arrange data into columns on a website

In my project, I'm exploring the challenge of creating a square 2 x 2 grid alongside a rectangular column on the right-hand side. While attempting to implement a grid system for the 2 x 2 layout, I encountered issues with the alignment of the rectang ...

Challenges arising when transferring data from Django to HTML

I am trying to calculate the sum of elements in lista[] which consists of decimal numbers, but I keep getting this error message: lista[] is composed of decimal numbers ValueError at / argument must be a sequence of length 3 This is my code : views.py ...

Structure of Divs with Bootstrap

Looking to create a layout with two divs side by side like the image below: Example However, when the screen width increases, the layout changes to this: Current Here is the code: Is there anyone skilled in this area who can guide me through it? Your a ...

Using PHP variables in HTML frameset URL for dynamic content passing

Looking for help to pass a PHP variable through a frameset URL. I've been trying different techniques without success so far. Can anyone provide some guidance? Here is an example of my code and what I have attempted: <?php $var = 2+3 ?> < ...

What is the best way to invoke an HTML file using a jQuery function in a JavaScript file?

When I call an HTML file from a jQuery function using require(), I am encountering an issue where I am unable to link the CSS with the HTML file. After running the file, only plain HTML is displayed without any styling. The structure of my HTML file is as ...

Is it possible to implement formvalidation.io in a React project that is using Materialize-css?

Can the formvalidation.io plugin be used with React and Materialize-css in a project? My project consists of multiple input components that may or may not be within a form. I want to utilize formvalidation for input validation. However, I am unable to find ...

Move your cursor over a div element while utilizing NgClass

I'm currently working on implementing a hover effect on a div using an Angular ngClass directive. Within the template file, I have a div element with the class "list-item-container" that includes another div with the class "list-item." This "list-item ...

Executing PHP code on button click in HTMLThe process of running a PHP script when

I am currently working on a project that involves detecting facial expressions using Python. However, I need to pass an image to this code through PHP. The PHP code provided below saves the image in a directory. How can I trigger this code using an HTML ...

"Exploring the Dynamic Display of Ajax with HTML5 Canvas

This is my first time exploring the world of ajax, and I'm finding it quite challenging to grasp the concept and functionality. What I aim to achieve: I envision a scenario where I can freely draw on a canvas and simply hit save. Upon saving, the da ...