Can you explain the process of implementing @media queries in SASS?

I am having some trouble understanding the syntax for media queries in SASS. I attempted to use this particular line of code, but it resulted in an error:

@media screen (max-width: 1550px) 
  #server-name
    left: 80%

Answer №1

Don't forget to include the and keyword in your code snippet. More information can be found here

@media screen and (max-width: 1200px)
    #title
        right: 50%

Answer №2

Here's a glimpse at how SASS can be used effectively. Keep in mind that this example follows the SASS syntax, not SCSS. To begin with, define your width variables:

$mobile: 568px
$tablet: 768px
$desktop: 1024px

Next, create your mixins:

=desktop
  @media screen and (min-width: $desktop)
    @content

=tablet
   @media screen and (min-width: $tablet) and (max-width: $desktop - 1px)
    @content

=mobile
  @media screen and (max-width: $tablet - 1px)
    @content

You can now apply these mixins wherever needed, whether it's on containers, the body element, or other elements:

.m-boxes-box
  max-width: 500px
  flex: 1 2
  min-height: 250px
  background-color: $soft-peach
  margin: 10px 0

  +tablet
    min-width: 50%
  +mobile
    min-width: 100%

Answer №3

This issue is not related to SASS but rather a pure CSS problem. There seems to be a type error as the and keyword is missing in the media query.

In pure CSS, this is what you have:

#server-name {
  position: absolute;
}

@media screen and (max-width: 650px) {
  #server-name {
    left: 80%;
    color: red;
  }
}
<div id="server-name">My name</div>

When converting this to SASS, it should look like:

@media screen (max-width: 1550px) 
  #server-name
    left: 80%

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

Playing back an Audio object using JavaScript

I'm facing an issue with replaying an audio sound every time the game starts in my Cocos2d javascript code. The sound plays correctly the first time, but subsequent attempts to play it result in no sound being heard. Below is my code snippet: var my ...

The SVG element's width is set to 100%, but it does not expand

Here is the SVG code snippet I am currently working with: <div className="behaviorPatternsItem" key={item.id}> <div className="behaviorPatternsItemStyled"> <svg height="25" width="100%" preserveAspectRatio="non ...

Why does the pound symbol in z-index always show up in Angular?

Having an issue with my code where I set a z-index in the CSS like this: .mat-mini-fab { position: absolute; right: 5px; top: 4px; z-index: 999; box-shadow: none !important; } However, whenever I visit my site, the z-index is not being appl ...

Tips for saving the JSON data from a directive so it can be accessed on a different HTML page using Angular

One of my requirements is to retrieve data from an Excel file located anywhere and display it on a separate HTML page. Initially, I managed to display data from multiple sheets on the same page. Now, however, I need to select the file on the first page and ...

The Tabbed Panel Bug: Incorrect HTML ID Causing Tab Change Issues in Bootstrap

I've been working on a tabbed panel feature for my website. However, I've run into an issue where clicking on the second, third, and other tabs doesn't change the content displayed - it always stays the same. I'm pretty sure I wrote th ...

What is the best way to apply styles to a particular ul element without impacting the appearance of other lists on

I am facing an issue with the styling of ul elements on my web page. The latest ul I added is affecting the appearance of other lists on the page. How can I ensure that the styling for this ul only affects this specific one? I have attempted multiple solut ...

What is causing this image to be off-center both vertically and horizontally on the table?

Currently, I have a small 20px by 20px image displaying in the top left corner of an empty table: <table width="100px"> <tr> <td width='100%' align='center' valign='center'> <img i ...

How can I turn off the animation for a q-select (quasar select input)?

I'm just starting out with Quasar and I'm looking to keep the animation/class change of a q-select (Quasar input select) disabled. Essentially, I want the text to remain static like in this image: https://i.stack.imgur.com/d5O5s.png, instead of c ...

Guide to centering a Material UI Table on a webpage

Is it possible to center the <Table> within a fixed width <div>, and have a scrollbar appear when the browser is resized, while maintaining the fixed width of the <Table>? Thanks in advance. This is my current setup: <div> ...

Can you explain why this unexpected bootstrap positioning is happening?

On my website, I have two large buttons (btn-lg) - one is placed at the top of the page with a hidden form beneath it (initially set to display: none), and the other button is below that with another hidden form. When clicked, the buttons reveal their resp ...

Problem: Implementing a horizontal scrolling feature using Skrollr

I'm interested in creating a horizontal animation controlled by skrollr. As I scroll down, I want the elements on my page to move from left to right within my container. When all elements have the same width, setting the scrolling data from 100% to 0 ...

Add a container element resembling a div inside a table without implementing the table layout

I am working with a table that is rendered by DataTable, and I have the requirement to dynamically append new elements inside the table like this: The dark grey area represents the new DOM elements that need to be inserted dynamically. The first row cont ...

Connecting queries in php

I am looking to connect searches from a checkbox form together. For example, if I select checkboxes a and b, I want the search results to display two different outcomes. <form role="form" action="R.php" method="post"> <div class="form-group"&g ...

The background image and svgs are not displayed on laravel localhost/public/index.php, but they appear when using "php artisan serve"

I've created a beautiful Laravel project on my PC. The welcome.blade.php file in the project has a background image located in the: public/images/ directory. To display the images, I've used the following CSS: html, body { color: #f4f6f7; ...

Bootstrap does not display unordered lists (<ul>) or ordered lists (<ol>)

I'm having trouble with my code that should display ordered and unordered lists. Even though I am using Bootstrap, I can't seem to get any list styling - no numbers or bullets are showing up. <ul> <li>test1</li> <li>test2 ...

While continuing to input text, make sure to highlight a specific element from the search results list

Currently, I am using a customized search feature in my React.js application. I am looking for a way to focus on an element within the search results so that I can navigate using arrow keys. At the same time, I need to keep the input field focused to conti ...

Permanent Solution for HTML Textbox Value Modification

I'm currently working on a GPS project where I am attempting to capture the altitude (above sea level) value in textbox1 and convert it into a ground level value displayed in textbox2. In this scenario, the GPS Altitude (ASL) value is dynamic. For ex ...

Is it possible to swap out images using srcset attribute?

Currently, I am facing an issue regarding changing the img on mobile and tablet devices to display different images. As a beginner with jQuery, I couldn't resolve it using that framework, so I am exploring options with html5. I am wondering if there ...

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 ...

The autocomplete attribute for "current-password" in React is failing to display the form fill option

Encountering an issue with the autocomplete="current-password" attribute not displaying the current password in a form, even though it is saved in Chrome. The input field is enclosed within a form. Is anyone else experiencing problems with the autocomplete ...