Multiplying values with different units in CSS calc() function

In my SASS code, I have created a mixin for responsive-self-resizing font size. Here is the code:

@mixin fluid-text($min-screenwidth, $max-screenwidth, $min-fontsize, $max-fontsize){
    font-size: calc( (#{$min-fontsize}) +
    (#{$max-fontsize} - #{$min-fontsize}) * 
    (100vw - #{$min-screenwidth}) / 
    (#{$max-screenwidth} - #{$min-screenwidth}));
}

To keep things organized, I defined some variables:

//text variables
$min-screenwidth: 480px;
$max-screenwidth: 1260px;
//heading
$min-landingheading-fontsize: 42px;
$max-landingheading-fontsize: 65px;

Finally, I apply this mixin to an h1 headline like so:

@include fluid-text($min-screenwidth, $max-screenwidth, $min-landingheading-fontsize, $max-landingheading-fontsize);

Even though there are no syntax errors, the result is not as expected. I have come across articles suggesting that 'calc' may not be ideal for such calculations. However, I find it hard to believe as I based my code on a presentation (https://youtu.be/Wb5xDcUNq48?t=1085)

Thank you in advance for your assistance.

MS

Answer №1

font-size: calculate( (#{$min-fontsize}px) + (#{$max-fontsize} - #{$min-fontsize}) * (100vw - #{$min-screenwidth}px) / (#{$max-screenwidth - $min-screenwidth}));

//setting variables for text
$min-screenwidth: 480;
$max-screenwidth: 1260;

//heading font sizes
$min-heading-fontsize: 42;
$max-heading-fontsize: 65;

This code will work like a charm, huge thanks to everyone involved!

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

Despite utilizing the .img-fluid class, the image remains incompatible with the parent div and does not fit properly

So, I'm currently working on a test code where my aim is to fit an image into the parent div using Bootstrap 5. However, I'm facing a challenge where the image leaves a noticeable gap width-wise, despite using the .img-fluid class. You can see th ...

Maximize the efficiency of your layout by using Flexbox to evenly distribute

I am trying to create a layout with two columns inside a bootstrap row using only CSS/flexbox and I want to achieve the design shown in this image: View Result Specifically, I want the left column's space to be distributed so that the two input field ...

Generating Speech from Text using jQuery API in HTML

Can a website be created to detect textbox text upon longClick by the user, and function across various browsers? The site should also have mobile compatibility. Appreciate any help! ...

Techniques for transferring the CSS value of a dynamically generated hyperlink to a different page

As a newcomer to web development, I find myself facing a challenge in passing dynamic values to another page when a hyperlink is clicked. All I need is to retrieve the value of the clicked hyperlink on the subsequent page. Can anyone provide guidance on ho ...

Embedding a styled list item within a list

How can I customize the style of list items within a list? HTML code <span class=bbb> <ul> <li>Preparing archive inquiries about study periods or work experience at LLU: <ul> <li>Within seven days - 5 ...

Questions regarding the navigation bar

I am currently working on designing a navigation bar featuring a dropdown menu. I envision HOME, FIXTURES, RESULTS, LEADERBOARD all appearing on the same line. Specifically, I would like UPCOMING WEEK, MONTHS to be the dropdown children of FIXTURES, and G ...

Bootstrap form validation solution

Utilizing bootstrap validation to validate a jsp page. The folder structure is as follows: WebContent ├── bootstrap-form-validation ├── js └── pages All three folders are under the web content. If I create another folder called teacher ...

JavaScript and jQuery Conceal and Reveal

I'm having trouble with my jQuery hide and show functions. They seem to be working, but the items are not appearing on the page. I suspect it could have something to do with a parent element being positioned relative or having a display of none, but I ...

Adjusting HTML/JSX in Response to Screen Size

I want to update the text inside a <p> tag depending on the screen size. There are two approaches that come to mind: Include the text like this: <p> <span className="one">text one</span> <span className="two ...

Tips on inline password field placement for a better user interface experience?

While creating a registration form, I ran into a user interface problem. There are two specific changes I'd like to make: The label for Confirm Password should be inline on the same line. The password input should have an eye icon embedded within it ...

Which web browsers are compatible with the input attribute "multiple"?

I am currently incorporating this particular plugin, and its file input does not support multiple file selection. To address this issue, I have added the 'multiple' attribute. However, I am curious if there are any browsers or other platforms (su ...

Trouble concealing a div within PHP code

.dq { display: none; } #s:hover~ .dq { display:block; } This PHP code snippet displays information from a MySQL table: echo " <div class='span3 tiny'> <div class='pricing-table-header-tiny'> <h2>" . ...

Utilizing JQuery within dynamically loaded files through JQuery tab functionality

My initiation into the world of JQuery tabs has begun. I have a basic setup where clicking on a tab loads 3 different PHP files. <div id="info"> <ul id="info-nav"> <li><a href="tab1.php">Tab 1</a></li> ...

What are some ways to enhance mobile browsing with CSS?

I'm facing a challenge with optimizing my webpage for different mobile resolutions in my beginner HTML/CSS course. Whenever I use a website resolution simulator to test, the layout doesn't look right on certain settings. Is there a method to aut ...

Expanding the content in Bootstrap Navbar

I am working with a bootstrap navbar and need to customize it by adding a SignOut button and a Welcome message to the menu bar. I also want to adjust the positioning of the logo and company/city name within the navbar. Here is the current setup of my navba ...

Align the content vertically in two adjacent divs

I have a logo and a menu in two separate divs side by side. The logo is on the left and the menu is on the right. I am trying to vertically align the menu in the right div with the logo in the left div. Here is the code snippet: <div id="header"&g ...

Encountered a parsing error while attempting to include the navigation bar page

<?php echo <<< END <!DOCTYPE html> <!-- --> <html> <head> <title>Nav</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0 ...

Unable to view the line number of a CSS style in Chrome Dev Tools while inspecting an element anymore

Today, a strange issue arose that has me puzzled. I can't seem to figure out what caused it. If you take a look at this picture here: This screenshot is from Twitch where I had a tab open. You can see the CSS file and line number displayed as usual. ...

Neglecting images on Zoom

Looking to scale up the elements on an HTML page by 50%, without affecting the resolution of images. Despite trying zoom: 150% in CSS3, it ends up zooming pictures as well, resulting in blurry visuals. Is there a way to enlarge all HTML components while ...

Text is overflowing from the table cell due to its length

UPDATE: I have included a screenshot for reference. My goal is to ensure that the text within the grid container does not scroll horizontally and instead fits within the available space. https://i.stack.imgur.com/CfFuy.png In my React Material-UI table, ...