Maintaining the placement of an element in a fixed position while adding a border

Currently, I am in the process of developing an interactive online picture framing tool. My aim is to allow users to customize an image by selecting different border, mount, and frame sizes. These customizations will be reflected in real-time by adding corresponding elements around the image. I want to ensure that the image remains centered within the encompassing #preview div while the borders are applied around it. Can this layout and functionality be achieved solely using CSS, or will it require the implementation of JavaScript/jQuery?

For reference, here is an example:

I have attempted to set the image position as fixed initially, but this caused issues with the containing divs.

Here is a snippet of the code:

Layout:

<div id="preview">
<span id="frame-preview">
    <span id="mount-preview">
        <span id="border-preview">
            <span id="image-preview" class="id-number" ><img src="image.jpg" /></span>
        </span>
    </span>
</span>

CSS:

#preview {
    width:70%;
    min-height:300px;
    padding:20px 0;
    margin:0 auto;
    text-align: center;
}
#frame-preview {
    outline:0px solid pink;
    display:inline-block;
    position:absolute;
    top:60px;
}
#mount-preview {
    outline:0px solid green;
    display:inline-block;
}
#border-preview {
    outline:0px solid blue;
    display:inline-block;
}
#image-preview {
    display:inline-block;
}
#image-preview img {
}

JS:

        $('#border_size').change(function(event) {
            var value = $('#border_size').val();
            //alert(value);
            $("#border-preview").css({ outlineWidth: value });
        });

        $('#mount_size').change(function(event) {
            var value = $('#mount_size').val();
            //alert(value);
            $("#mount-preview").css({ outlineWidth: value });
        });

        $('#frame_size').change(function(event) {
            var value = $('#frame_size').val();
            //alert(value);
            $("#frame-preview").css({ outlineWidth: value });
        });

Thank you.

Answer №1

Here is an example you could consider

 #frame-preview {
   border: 0 solid #FFC0CB;
   display: block;
   margin: 0 auto;
}

Answer №2

#main-preview {
    width:70%;
    min-height:300px;
    padding:5px;
    margin:5px auto;
    text-align: center; 
    border:1px solid #000;
    }

#frame-display {
    border:0px solid pink;
    display:inline-block;
    position:relative;
    top:0px;
    margin:20px auto;}

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

Shifting the data label on a pie chart in ApexCharts - what's the trick?

I need help adjusting my data labels to make them more readable by moving them inward. It would be perfect if there is a way to dynamically center them within the slice. https://i.stack.imgur.com/bCelP.png Despite reading the documentation and trying dif ...

Having trouble with the functionality of JQuery drop feature?

As I delve into implementing drag and drop functionality with JQuery, I encounter a peculiar issue. I have set up 3 'draggable' divs and corresponding 3 'droppable' divs. The intended behavior is for each draggable element to be accepte ...

jQuery - Inserting Content at the End

As an example, I have the following chunk of HTML code: <div class="messageContainer"> <div class="message"> </div> </div> ---Here <div class="messageContainer"> <div class="message"> <here> :) &l ...

The sub-menu positioning feature functions properly in Chrome and Safari, but is not compatible with Internet Explorer and Firefox

Working on a website for a gaming community, known as http://www.quad-gaming.com/. All is running smoothly except for the dropdown menu under "Login" on the right side of the navigation bar. It behaves properly in Chrome and Safari, but in IE and Firefox, ...

Error in Bootstrap V5 Sass: Mixin not defined - when transitioning from @import to @use module system

Transitioning to the new SASS module system with @use from @import has presented some challenges, especially when working with bootstrap v5: https://i.sstatic.net/8Hy7W.png Old way: @import "~bootstrap/scss/bootstrap"; @import "~bootstrap/ ...

jQuery's click event on dynamically generated AJAX elements sometimes fails to trigger randomly

When I use the getData() function to retrieve ajax content, it dynamically adds elements based on the JSON response from the server. The code snippet below shows how the elements are added: $("#list").append('<div class="ui card fluid" id="' ...

Trigger the original function again once the other function completes in jQuery AJAX

I'm working on improving my skills in jQuery, AJAX, and JSON. Within my application, there is a dropdown select menu: <select id="serviceload" name="serviceload"></select> The OPTIONS in the select menu are populated dynamically by anot ...

How to Delete the Bottom Border on Selected Tabs in MUI Using React

I am attempting to customize the appearance of MUI Tabs to achieve a design similar to the image below: https://i.sstatic.net/tBS1K.png I have created a sample code example in a codesandbox environment. You can view it here: Codesandbox Example. In this e ...

simultaneous image hover effect for all images

I am experiencing an issue with my CSS and Bootstrap hover effect. The overlay tags are enclosed within a div class, but they all hover simultaneously. Each overlay belongs to a different Bootstrap grid, yet the effect extends even to the empty spaces betw ...

JSONP version of the JQuery method for loading content

I am currently developing a web page widget for my organization. The goal of this widget is to inject an HTML snippet from any domain (including our website or a customer's CNAME) into the customer's website, which could be hosted on various plat ...

Keystrokes may not consistently register in Firefox

I created a compact web application where users can interact by clicking on a button to trigger a modal dialog. Within this dialog, users have the ability to choose from various options. To enhance user experience, I implemented the utilization of the jQue ...

The CSS code ".btn btn-primary * { visibility: hidden; } is failing to work as intended

Trying to hide specific buttons for print using CSS, but it doesn't seem to be working. Here is the code snippet: .btn btn-primary * { visibility: hidden; } <div id="control" style="display: none"> <button class="bt ...

Changing the jQuery mobile side panel from push to overlay can be achieved by modifying the display settings when transitioning from a mobile view to a

I'm currently working on a project using jQuery Mobile (JQM) and jquery.mobile-1.4.5. My goal is to create a responsive side menu panel with a fixed header that works well on both mobile and tablet devices. For the design, I want the panel width to b ...

What's the deal with that negative index value?

This is the JavaScript code I am currently working with: let number = $(".linksMiniImages a").index(this); alert(number); Whenever I click on a link, the alert displays -1. I'm struggling to figure out what might be causing this issue. Any ideas? ...

Creating personalized widths for bootstrap classes with SASS

I am interested in enhancing the bootstrap source code by creating additional w-XX classes. Specifically, I aim to include both w-40 and w-60. According to the documentation, modifying the $sizes variable is necessary for this customization. In my custom. ...

Is there a way to prevent a Bootstrap x-editable from saving changes to a field if the ajax call fails?

How can I prevent a Bootstrap x-editable from updating a field if the ajax call fails? I am using a function as the URL for the editable field. $('.order-price').editable({ type: "text", title: "Order Price", url: function (params) ...

The Ajax function effortlessly receives the returned value and smoothly transitions to the error handling stage

When trying to retrieve data from an ajax request, my function needs to receive the returned data as an array of strings. During debugging, I am able to see the response, but at the same time, the error function is triggered. This is how my code looks: ...

Why is the Jquery console not displaying any values?

Hey everyone, I need some help with a small issue in my project. For some reason, the console.log() function in my project is not returning any values. <script> $('#search-box<?=$x;?>').blur(function() { var val = $("#search ...

Ways to display HTML elements depending on the width of the window

Is there a way to create visually appealing hexagon containers for text that work well across all window widths? Currently, the design is only satisfactory at certain window sizes. I am looking to implement a solution where specific code will be displayed ...

Is it necessary to mark all checkboxes in the initial column of the gridview?

I have encountered an issue with my code that checks all checkboxes in the first column of a gridview. It seems to work only for Internet Explorer versions 5.0 to 8.0, but gives a Javascript error when running on IE 9 and above stating "Function Expected ...