Modifying the position of image fragments on the background

Currently, I am attempting to create a puzzle using a background image with numbered pieces that will eventually be movable through javascript. However, my progress has hit a snag as I am struggling to position the pieces correctly on the image. The HTML contains a div with an ID named puzzlearea, and I have used JavaScript to append children elements to it successfully. Despite this, the CSS is not cooperating in positioning the pieces relative to the background. As it stands, my test pieces are stubbornly stuck in the top left corner and seem to be ignoring the values set for background-position. Below is the snippet of the CSS code:

body {
   text-align: center;
   font-family: cursive;
   font-size: 14pt;
}

#puzzlearea {
   width: 400px;
   height: 400px;
   margin: auto;
   position: relative;
   background-image: url("planck-image.png");
}

.tile {
   font-size: 40pt;
   color: red;
   line-height: 70pt;
   width: 90px;
   height: 90px;
   border: 5px solid black;
   background-position: -200px -200px;
   position: fixed;
}

Update: Screenshot.

I am seeking suggestions or solutions as to why the positioning issue may be occurring. Any insights would be greatly appreciated.

Answer №1

In order to position the elements using the top/bottom/left/right parameters, it is necessary to apply position: absolute on the .tile class.

The fixed position is relative to the viewport, and not the parent element.

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

Shader Material in THREEJS has been replaced with new settings

I am facing an issue with my shader material setup. I have a shader material that is working properly and has a texture attached to it. Now, I want to create two meshes using this shader material but with different textures for each mesh. However, when I ...

Unable to display bar chart on PHP webpage showing database number volumes using JavaScript

I'm currently working on generating a bar chart to show the number of bookings per month. I have two separate SQL queries that retrieve the data correctly, as confirmed by testing. However, when I try to run the file in my browser, nothing is displaye ...

Running the npm build command generates JavaScript that is not compatible with Internet Explorer

After executing npm run build, the generated JavaScript code looks like this: jQuery.extend({ propFix: { for: "htmlFor", class: "className" }, Unfortunately, this format is not compatible with several versions of Internet Explorer ...

What is the best way to retrieve the ID of a <tr> or <td> element?

When working with JavaScript, I have created a dynamic table where each row is structured as follows: <td id="user[i]['id']">user[i]['name']</td> Within this structure, I am seeking to extract the value user[i]['id&ap ...

Ways to incorporate a reverse transition effect

I am encountering an issue with a sliding effect on a div. When it has a class hddn, the overlay will have right: -100% from the viewport. However, when the hddn class is removed, it should return to the viewport with right: 0. How can I animate this movem ...

Troubleshooting: Why is my console.log not working in JavaScript

Recently, I've been diving into the world of JavaScript, but for some reason, I can't seem to make console.log function properly. At the top of my HTML document in the head section, I added jQuery like this: <script type="text/javascript" sr ...

css displaying drop-down menu when hovered over

I've been trying to create a link that, when hovered over, displays a list of options. I've managed to make it work in Firefox and Google Chrome, but it doesn't display at all in Internet Explorer when hovering over the link. I'm also ...

utilize spans for generating dividers

I attempted to create a border by using the CSS property border: 1px solid #333 within an empty span, but unfortunately I did not see any visible separator. Could it be that there needs to be content inside the span for the border to appear? Is there a way ...

displaying a confirmation using jQuery in CodeIgniter

Hello everyone, I am a beginner in CodeIgniter and I am seeking assistance. I am attempting to create a confirmation message (div id="delmsg") using jQuery when deleting a record from MySQL database. The delete operation is functioning properly, but the me ...

It is not possible for AngularJS to retrieve values using ng-model when ng-repeat is being used

Is there a way to capture dynamically generated data using ng-model (data created with ng-repeat) so that I can send it as an object to Firebase, my flat database? Currently, the ng-model is only retrieving empty strings as values. Any ideas for a solution ...

How can you use ng-click to disable a div in AngularJS?

I'm looking to dynamically disable a div in AngularJS based on a certain condition. I know I can achieve this by adjusting the CSS (such as reducing contrast and color) but the div also has an ng-click property that I want to prevent from being trigge ...

Switching React Icons when Clicked

I'm struggling to understand this. I want the React icons below to be filled and remain filled when clicked, changing back to outlined when another is clicked. Here's the code: import { useState } from "react"; import { Link } from "react-router- ...

An issue occurred when attempting to modify bookings with the setState function

When working inside the deleteBaseBooking function, my goal is to use setState to set this.state.checkIndexStatus[key] = null. However, I am encountering an error: deleteBaseBookings(){ for(var key in this.state.checkIndexStatus){ if(t ...

Invalid action has been dispatched by the effect:

In my project, I am using Angular 7.1.4. This is an excerpt from my effect code: @Injectable() export class LoginEffects { constructor(private actions$: Actions, p ...

Combing external JavaScript with React functionality

Hey there, I've been working on merging two projects that I came across recently: https://github.com/danxfisher/MeetEasier and this awesome page https://tympanus.net/Development/Interactive3DMallMap/ After making some changes in the MeetEasier React ...

Tips for preventing the error message "The property 'map' is not present on type 'string | string[]'."

I received an error message stating Property 'map' does not exist on type 'string | string[]': const data = [ ['1', ['11']], ['2', ['21']], ['3', ['31']], ] data.map(top ...

What is the integration process for jTable and Symfony 2?

After creating a Datagrid using jTable, I have included my JavaScript code in twig: <script type="text/javascript> $(document).ready(function () { jQuery('#grid').jtable({ title: 'Table of products', ...

Transform your table into an ASCII-art masterpiece using CSS styling techniques

My vision is to style a table "ASCII art" using CSS, like the example below: +------+---------+----+ | Jill | Smith | 50 | +------+---------+----+ | Eve | Jackson | 94 | +------+---------+----+ | John | Doe | 80 | +------+---------+----+ <ta ...

Is it possible for $templateCache to preload images?

Is there a way to preload images in Angular without using a spinner after the controller is initialized? I've heard about caching templates with $templateCache. Can this be used to also preload images when the template contains <img> tags or sty ...

Dynamic Font Formatting in Rails Table Based on Conditions

I need to customize the font color of dynamic values based on the state_id. If incident.state_id = 1, the font should be red; if incident.state_id = 2, it should be yellow; and if incident.state_id = 3, it should be green. incident.state_id = 1 : state.na ...