Is there a way to keep the spotlight/shadow position fixed in relation to the horizontal center, regardless of the zoom level?

After working on the following code snippet, I've managed to keep the spotlight centered horizontally, except when the zoom factor is too high. This means that when I zoom in, the spot light no longer remains centered in the horizontal view port.

It's important to note the use of .spotlight-2:before to fill the left portion of the shadow on the viewport. This was necessary to avoid any non-shaded regions from appearing.

Any suggestions on how I can ensure the spotlight stays centered horizontally and doesn't shift to the right when zooming in closely on the browser?

Fiddle:

https://jsfiddle.net/u0onf23y/

Resulting Output:

https://jsfiddle.net/u0onf23y/embedded/result/

CSS:

td .div{
  height: 400px;
}

.extend-full {
  padding-left: 3000px;
  margin-left: -3000px;
  padding-right: 3000px;
  margin-right: -3000px; }

    .spotlight-2{
        top: 0px;
        margin-left:-80px;
        float: left;
        display: block;
        background: radial-gradient(10px 10px at 560px 400px, transparent 0, transparent 150px, rgba(0, 0, 0, 0.5) 160px);
        background: -moz-radial-gradient(10px 10px at 560px 400px, transparent 0, transparent 150px, rgba(0, 0, 0, 0.5) 160px);
        background: -webkit-radial-gradient(10px 10px at 560px 400px, transparent 0, transparent 150px, rgba(0, 0, 0, 0.5) 160px);
        background: -o-radial-gradient(10px 10px at 560px 400px, transparent 0, transparent 150px, rgba(0, 0, 0, 0.5) 160px);
        margin-left: 0px;
        height: 100%;
        position: fixed;
        width: 100%;
        min-width: 100vw;
        min-height: 100vh;
        z-index: 10;
      };
      position: absolute;
      width: 100%;
      z-index: 10; }

    .account-settings-confirm-container-overlay {
      z-index: 10;
      background-color: white !important;
      height: 99px;
      position: absolute;
      margin-top: 10px;
      width: 250px;
      font-size: 12px;
      box-shadow: 0px 1px 1px 1px rgba(0, 0, 0, 0.1); }
    .spotlight-2:before {
      content: "";
      position: absolute;
      display: block;   
      left: -100%;
      height: 100%;
      width: 100%;
      background: rgba(0,0,0,0.5);  
    }

Answer №1

Consider using flexbox to create a responsive design. Here is an example with full code snippet: http://codepen.io/rhroyston/full/qadGgd/

html, body {
  height: 100%;
  margin: 0;
}

#viewport{
  height:100%;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1;
  background-color: rgb(0,0,0);
  background-color: rgba(0,0,0,0.4);
  
} 

.a{
  box-shadow: 0px 0px 5px grey inset;
    margin: auto;
    padding: 20px;
    background-color: #fefefe;
    border-radius: 50%;
}
<div id="viewport">
  <div class="box">
    <div class="a"></div>
  </div>
</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

How can the table header be displayed in a Vue JS application after receiving the server response?

On my Vue.JS web page, I am making an API call using the Http GET method. Currently, the table header is displayed before receiving the API response, which doesn't look good. Can someone help me modify my code so that the table header is only displaye ...

Is there a way to create an HTML popup that automatically opens a link and an image file side by side

Can a popup code be created to automatically open both a link and an image side by side? ...

CSS Challenge: How to crop an image without using its parent container directly

I'm currently facing a complex CSS challenge that I can't seem to solve. I want to create an image controller (two-by-two layout on two lines) that can display: The top-left image in full size, The top-right with horizontal scrolling, The botto ...

Tips for extracting the chosen value from a dropdown list within a table cell using JavaScript

Here is an example of an HTML element: <td> <select> <option value="Polygon 47">Polygon 47</option> <option value="Polygon 49">Polygon 49</option> </select> </td> I am looking for a ...

I require assistance in troubleshooting and repairing my HTML and JavaScript code

I am working on creating a feature where users can input their upcoming birthday date and receive an alert showing how many days are left until then. However, I encountered an issue where the alert displays NaN (Not a Number) before the birthday is entered ...

Embellishing Your Website with Unique Cursor Styles

Looking to add personalized cursors to my website using asp.net 4.0. On my master page, I aim to set a custom cursor as the default for the entire site and have different custom cursors for all links. Is this achievable? ...

Numerous anchor links are present

Is it possible to eliminate the red lines between "google links" while keeping the border color as red? How can I achieve this? Here is the code snippet provided: <!doctype html> <html> <head> <title>Website</title> </he ...

Can Wireframe be applied to a 3D gltf model within an HTML document?

I am currently working on achieving a specific design concept, which can be viewed at the following link: To guide me through this process, I have been following a tutorial available here: While I have successfully implemented the model and created mater ...

Creating an HTML5 input field with the type "datetime-local" that works seamlessly in Firefox

Currently, I am incorporating HTML5 date and time input fields within an AngularJS-based interface: <input type="datetime-local" ng-model="event.date_time.start" /> <input type="week" ng-model="event.date_time.start" /> However, my goal is to ...

Embed an HTML element within a DIV container

How can I add an HTML tag such as <p> to wrap around the text "Search"? <button id="ihf-quicksearch-submit2" class="btn btn-lg btn-block btn-primary btn-form-submit ihf-main-search-form-submit" type="submit"> Search </button> I am looki ...

The Asp.net MVC Navigation Bar

I'm facing an issue with the navbar in asp.net mvc https://i.sstatic.net/QJmPW.jpg Here is my code snippet <li class="nav-item nav-link" role="presentation"> <a class="nav-link" @Html.ActionLink("Cust ...

I cannot seem to receive the confirmation of success!

Trying to store user details in a database and display a success message that fades in. I have attempted some code, but unfortunately it's not working. Please help me out. Apologies if I am mistaken. Here is my register.php code: <?php require ...

centering headers using tailwind styles

I am facing a challenge with positioning my main title, logo, and subtitle. I want the subtitle to be centered regardless of the logo's width. Currently, the position of the sub title changes based on the logo's width, resulting in it not aligni ...

Avoid navigating through hidden tab indexes

Below is the HTML code that I am working with: <span tabindex="19"> </span> <span tabindex="20"> </span> <span tabindex="21"> </span> <span id="hidden" tabindex="22"> </span> <span tabindex="23"&g ...

Coordinate the timing of CSS animation with the loading of the page

Despite the abundance of similar questions, none have quite addressed my specific query. I've created a preloader using CSS animation and I want it to synchronize perfectly with the page load. While I can trigger the animation on page load, I'm s ...

Bootstrap link causing alterations to my CSS code

After incorporating Bootstrap into my HTML, I noticed that it caused some unexpected changes to my CSS code. Original CSS: https://i.stack.imgur.com/EsE6J.jpg Modified CSS after applying Bootstrap: https://i.stack.imgur.com/yH1r9.jpg Link to Bootstrap ...

Expansive Bootstrap division

I am seeking assistance in achieving a Bootstrap layout similar to the image provided below. My difficulty lies in ensuring that the yellow bar spans the full width of the Bootstrap container without disrupting the stacking order of columns on mobile view. ...

Switch up the font style of the title element

Is it possible to modify the font-family of the title attribute in an input field using either JavaScript or jQuery? <input type="text" title="Enter Your Name" id="txtName" /> ...

How to target and style multiple descendants of an element using CSS

Can you target multiple elements with a common ancestor in CSS using class, id, etc? For example: table.exams caption, tbody, tfoot, thead, tr, th, td If not, is there a method to select all nested elements within that particular element? ...

Issue with Bootstrap rows overlapping on smaller screens

Basically, the issue I'm facing is that when I reduce the size of my screen, the columns drop below and start overlapping with the row beneath them. I've been trying to figure out if there's a simple solution that I'm overlooking. But ...