The issue with 100% minus pixels not functioning properly in jQuery and Chrome devtools is causing unexpected discrepancies

Having trouble with using CSS to make an element 100% minus pixels in jQuery and Chrome devtools,

The following code is not functioning correctly:

$(".mydiv").css({height: "calc(100%-50px)"});

This approach did not work in Chrome devtools, even though it was intended for responsive window resizing.

However, the code works fine when applied directly in a CSS stylesheet:

.mydiv {
    height: calc(100%-50px);
}

Answer â„–1

It is crucial to include spaces when using + (addition) or - (subtraction) in conjunction with calc().

According to information sourced from MDN:

The operators + and - need to be surrounded by whitespace. For example, calc(50% -8px) will be viewed as a percentage followed by a negative length—making it an invalid expression. On the other hand, calc(50% - 8px) signifies a percentage, subtraction operator, and a length. Similarly, calc(8px + -50%) represents a length, addition operator, and a negative percentage.

Your original code:

body>div {
  width: 100px;
  height: 100px;
  outline: 1px solid red;
}
div>div {
  width: 100%;
  height: calc(100%-50px);
  outline: 1px solid green;
}
<div><div></div></div>

Corrected code:

body>div {
  width: 100px;
  height: 100px;
  outline: 1px solid red;
}
div>div {
  width: 100%;
  height: calc(100% - 50px);
  outline: 1px solid green;
}
<div><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

Suggestions for enhancing the functionality of this code by incorporating an additional dynamic chained selection box

Currently, I am utilizing a plugin offered by CSS-Tricks to create two chained select boxes using PHP, jQuery, and MySQL. I am contemplating the idea of introducing an additional box that will be dependent on the selections made in the first and second box ...

What is the best way to enable horizontal scrolling for textarea overflow in a smooth manner like input, without any sudden jumps?

Currently, I am interested in utilizing a one-line textarea (with rows=1 and overflow-x:hidden;) similar to input type="text. However, I have encountered an issue where the content scrolls with "jumps" while typing inside it: https://i.stack.imgur.com/Rzf ...

Leveraging the .ajaxSubmit method from the jQuery form.js plugin

I've encountered an issue with the .ajaxSubmit function not triggering. I have utilized the jquery form plugin by Malsup multiple times before without any difficulties. Below is my current code snippet: <head> <script type="text/javascript" ...

Tips for concealing the edges of a scroll bar while utilizing scroll as overflow

Basically, I have a div that is positioned absolutely and has multiple children elements. This div can be scrolled horizontally to see all its content, but the scrollbar hangs off the bottom, hiding the bottom border radius. Here is the HTML code: <ul ...

Why is the checkmark still displaying red when it should be showing as green?

Are you struggling with password strength on your website? I faced a similar issue where the checkmarks remained red despite my attempts to turn them green. If you want to change the checkmark color, here is some code that may help: document.getElementBy ...

Take away the follow option on the embedded tweet

I need to customize the appearance of embedded tweets on a website by removing the follow button as well as the reply, favorite, and retweet buttons in the footer. Here is a simple HTML example: <blockquote class="twitter-tweet"> <a href="htt ...

Steps for including a caption in a Fancybox-Media box

I am using a fancybox-media box to display Vimeo and YouTube videos. I want to add a caption below the video with some content related to it. Is there a way to do this? Below is the JavaScript code I am using: Fancybox function: $("#clpbox").click(functi ...

How come my gifs appear tiny even though I've adjusted their width to 32% each?

I am trying to display three gifs in a row, each taking up one-third of the width of the page. However, when I preview the page, the gifs appear tiny. I have set the divs to 32% each and the gifs should fill 100% of their respective div. Here is the code s ...

The jQuery form validator doesn't seem to work with AJAX for me, but I've figured out how to make jQuery validate without using

I have been facing an issue with my code that involves the jquery validator and ajax. The code seems to validate properly and the serialize() function appears to be working as I can see the data in the browser. However, the problem arises when the data d ...

Tips on creating horizontally aligned buttons with full width

Currently, I am facing an issue while attempting to create three equal-sized buttons laid out horizontally. However, what I have accomplished so far is displaying three full-width buttons stacked vertically. Here's the code snippet: <section class= ...

Update the existing JSON object by incorporating a new property:value pair

I currently have a JSON object structured as follows: var data = {ID: 123, Name: "test"} My goal is to include an additional property and value in the data object based on a condition set by an inline if statement. The desired output should be: data = ...

Dynamically parsing JSON data with jQuery

I have some JSON data that looks like this: { "default": [ [ 1325876000000, 0 ], [ 1325876000000, 0 ], [ 1325876000000, 0 ], [ 1325876000000, 0 ] ], "direct": [ [ ...

What is the reason for $(this) being appropriately recognized for click events but not for hover actions?

Why does this work on an element-by-element basis? <script> $(document).ready(function(){ $("p").click(function(){ $(this).hide(); }); }); </script> </head> <body> <p>If you click on me, I will disappear.</p> &l ...

I duplicated a functional jQuery form and moved it to a different location, but I am only able to get the

I recently duplicated a jQuery form from one page to another, but encountered unexpected issues with the copied version. The original form functions as follows: An onclick function connected to an image triggers a confirmation modal window with an "OK" bu ...

Adjust the size of an image post-render with the help of Angular or jQuery

Below is my current HTML code: <img width="150" height="150" src="https://d.pcd/image/578434201?hei=75&amp;wid=75&amp;qlt=50,0&amp;op_sharpen=1&amp;op_usm=0.9,0.5,0,0" ng-src="https://d.pcd/image/578434201?hei=75&amp;wid=75&amp; ...

Use jquery to rotate the div and animate it to move upwards

Hey everyone! I'm having an issue with rotating and moving an image inside a div element. I've tried some code to make it work, but nothing seems to be happening. Any tips or suggestions on how to tackle this problem would be greatly appreciated. ...

Is jQuery automatically loaded in laravel 6? I keep encountering an uncaught type error

Everything was going smoothly with my project until I added authentication. Following the documentation here, I used composer to require laravel/ui and then did php artisan ui vue --auth. Prior to implementing authentication, the scripts were loading corr ...

What causes conflicts between CSS and HTML tables?

I'm currently working on designing an email ticket template that incorporates a small table for clients to easily view the subject and description of their ticket. The template was looking great until the table was inserted, causing a complete formatt ...

Incorporating CSS animations into Vue.js while an API call is being made

When a specific icon is clicked, an API call is triggered: <i class="fas fa-sync" @click.prevent="updateCart(item.id, item.amount)"></i> I am looking to add an animation to rotate the icon until the API call is complete or ...

How to incorporate a phone number input with country code using HTML

Can anyone help me create a phone number input field with a country code included? I've tried a few methods but haven't had much success. Here is the code I've been working with: <div class="form-group "> <input class= ...