How can I create the reference lines (blue auxiliary lines) using CSS to resemble the ones seen in Firefox DevTools?

Guideline image https://i.sstatic.net/nQks3.png

Is there a way to create blue dashed reference lines using CSS similar to the ones seen in Firefox's development tools?

Answer №1

I have successfully created a reference line using the following method: I calculate the parent div's top, left, width, and height variables and then apply them to lines.

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      body {
        margin: 0;
      }
      :root {
        --left: 50px;
        --top: 40px;
        --width: 150px;
        --height: 80px;
      }
      .mydiv {
      
        width: var(--width);
        height: var(--height);
        left: var(--left);
        top: var(--top);
        position: relative;
        background-color: black;
      }
      .up {
        border-top: 1px dashed aqua;
        height: 1px;
        left: calc(0px - var(--left));
        line-height: 1px;
        width: 100vw;
      }
      .down {
        border-top: 1px dashed aqua;
        height: 1px;
        left: calc(0px - var(--left));
        top: var(--height);
        width: 100vw;
      }
      .left {
        border-left: 1px dashed aqua;
        width: 1px;
        top: calc(0px - var(--top));
        height: 100vh;
      }
      .right {
        border-left: 1px dashed aqua;
        width: 1px;
        top: calc(0px - var(--top));
        left: var(--width);
        height: 100vh;
      }
      .v-line {
        position: absolute;
      }
    </style>
  </head>
  <body>
    <div class="mydiv">
      <span class="v-line up"></span>
      <span class="v-line down"></span>
      <span class="v-line left"></span>
      <span class="v-line right"></span>
    </div>
  </body>
</html>

If you have any other great ideas, please share your answer with us!

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 to stop an AJAX request using Chrome developer tools?

Is there a way to cancel an initiated ajax request from Chrome Developer Tools? I want to test if my fallback message displays correctly without changing the code. Setting No throttling to Offline will make all calls fail, but I just need one API to fail f ...

Slow performance of Angular 4+ application on mobile devices

After running a test, I discovered that my angular app performs poorly on mobile devices due to slow javascript execution time compared to desktop. What could be causing this issue and how can it be resolved? Test results for Desktop: https://i.sstatic.ne ...

Creating a targeted jQueryUI tab focus

My jQueryUI tabs have a click function defined on a specific tab which works correctly with ajax calls: $("a[href='#tabs-1ua']").click(function (event, ui) { //ajax call }); Now I want to capture not just clicks but any type of focus on thi ...

Reduce the size of your CSS files using Gulp through the .pipe method

Is it feasible to incorporate a plugin like clean-css to minify CSS every time a page is refreshed or saved? How can I chain it through pipes to ensure that the minified file ends up in the dist folder? Thank you for any assistance! Presented below is the ...

How to center block buttons using bootstrap

I've been struggling with a Bootstrap bug since yesterday and I can't seem to figure it out. I have placed 2 buttons inside a div with flex display and align-items-center properties, but the second button is appearing lower than the first one and ...

Angular has been modified after being verified. The earlier value was 'null'

core.js:6162 ERROR Error: NG0100: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'null'. Current value: '{ When attempting to retrieve the {{dispositionDetails?.metricsData | json}} ...

What is the best way to utilize Link for navigation in React with Material UI?

const pages = ['home', 'menu', 'reservation']; <Box sx={{ flexGrow: 1, display: { xs: 'none', md: 'flex' } }}> {pages.map((page) => ( <Link component={Link} to='/'>Home</L ...

How can we convert props into state once they have been initialized using GetDerivedStateFromProps?

Presented here is a straightforward Component design: export default class Editor extends Component { constructor(props) { super(props); this.state = { field: "Some Initial Text" }; this.handleChangeField = this.handleChangeField.bind(this ...

Utilizing JavaScript for validation on an ASPX page within Visual Studio

After entering an email ID in a textbox, the email validation process is initiated. However, it seems that there is an issue where the entire function may not be executed properly. <head runat="server"> <title></title> ...

Nuxt/Vue poses a challenge as Jest struggles to locate a file within the src tag

Within my .vue file, I am loading a ts file like this: PasswordField.vue <script lang="ts" src="@/assets/ts/components/form/password-field.ts"></script> However, when I use yarn test to run Jest, I receive the following error message: ENOEN ...

Twitter Bootstrap does not trigger jQuery execution

Twitter Bootstrap is a new tool I am just starting to use and so far it's working pretty fine. However, I am currently attempting to implement some custom jQuery code. <script type='text/javascript' src='http://code.jquery.com/jque ...

Creating Bootstrap columns with equal height and a button

My HTML Code looks like this: <div class="row align-items-center" style="margin: 0; padding: 0;"> <div class="col-4" style="background-color: red; margin: 0; padding: 2px;"> <a href="#"><button style="width: 100%;">Test< ...

Ensure that subsequent content is displayed underneath a variable-height DIV

My CSS-driven tab control is functioning perfectly, with each page having a different height. However, I am facing an issue where the next control appears beside the tab control when I need it to be positioned below it. This becomes especially challenging ...

Guide to retrieving a user's current address in JSON format using Google API Key integrated into a CDN link

Setting the user's current location on my website has been a challenge. Using Java Script to obtain the geographical coordinates (longitude and latitude) was successful, but converting them into an address format proved tricky. My solution involved le ...

Using an AJAX call, you can update individual records in a MySQL database within a while loop. However,

Whenever I try clicking on the "Upisi" button, it seems to work fine for the first record, but for all subsequent records, it fails to work. ocitanja_custom.php: <?php include_once("headermeta.php"); require("connectdb.php"); if(!isset($_POST["stree ...

Why isn't my file being recognized post-multer middleware?

I am currently facing an issue with uploading a filename and a post (similar to 9GAG style) to my MySQL database, and storing the file in my project folder. The front end is able to retrieve the file without any problems (verified through console.log), but ...

Extending a border-bottom or underline to create a unique text highlight

I'm struggling to extend the border-bottom of this element to match the mockup. It currently only goes under the text part. How can I make it so that it extends to cover the entire box or underline half of the nav bar? This is what it should look li ...

Adjusting the font size within a container based on the mobile zoom level

My webpage contains highly visual content rather than text. I bring this up because mobile users typically use pinch-to-zoom to view the complete page or focus on specific details. <meta name="viewport" content="minimum-scale=0.3, maximum-scale=1.2"> ...

The word-breaking function is not functioning as anticipated

I am facing an issue with a container that holds multiple divs. I am attempting to prevent the contents of these divs from overflowing their parent element and breaking the text if it exceeds the parent's boundaries. However, my efforts are unsuccessf ...

Tips for bypassing the need to assign a variable within an if statement

Consider the following code snippet: let a; if (obj === undefined || obj.prop === undefined || (a = await getResultFromLongOperation(obj.prop)) === undefined) { // Perform actions to handle errors due to incorrect parameters } console.log(a) ...