Adjusting the desktop view through media queries for mobile devices

As someone with no coding experience, I've been working on my portfolio using Cargo. Currently, I'm trying to adjust the mobile view of an article on my homepage through media queries. However, the code is unintentionally changing the layout on desktop as well. Below are reference pictures of the desired mobile and desktop views, along with the current code I'm dealing with. Any assistance would be greatly appreciated, thank you!

**(disregard the borders in the code, this was mostly for visibility purposes when making changes)

Here's my code:

<style>
    .tiffany {
    /*border: solid green 3px;*/
    width: 100%;
    height: 100%;
  }
  
  .tiffany img {
    width: 100%;
    height: 100%;
    position: relative;
  }
  
  .tiffany .textbox {
    /*border: solid red 3px;*/
    position: absolute;
    margin: 32px;
    font-weight: bold;
    text-align: left;
  }
  
  .resize_tiffany {
    font-size: 5vw;
  }
  
  .tiffany .gradient {
    /*border: solid red 3px;*/
    left: 0px;
    top: 0px;
    z-index: 1000;
    position: absolute;
    width: 100%;
    height: 100%;
    /* other styles (left, top, right, and padding) */
    background: linear-gradient(to bottom, rgba(0, 0, 0, 0.85), transparent);
  }
  /* read-here */
  
  .read-here {
    position: absolute;
    bottom: 4vw;
    left: 50px;
    background-color: rgb(0, 68, 11);
    color: rgb(0, 68, 11);
    padding: 16px;
    font-size: 16px;
    border: none;
    font color: rgb(255, 255, 255)
  }
  
  @media only screen and (max-width: 480) {
    .tiffany .textbox {
      border: solid blue 3px;
      position: absolute;
      margin: 15px;
      font-weight: bold;
      text-align: left;
    }
    @media only screen and (max-width: 480) {
      /* read-here */
      .read-here {
        position: absolute;
        bottom: 4vw;
        left: 10px;
        background-color: rgb(0, 68, 11);
        color: rgb(0, 68, 11);
        padding: 8px;
        font-size: 16px;
        border: none;
        font color: rgb(255, 255, 255)
      }
    }
</style>

<div class="tiffany">
  <img class="background-image" src="https://freight.cargo.site/t/original/i/49f84023695066f70817f10d5164bfc85e438f33abd59b9c50a439f6a22f0454/Featured-Page_Tiffany_Alfonseca_Latina_Edit.jpeg">
  <div class="gradient">
    <div="" class="textbox full-pointer-events-none">
      <h1> <span class="resize_tiffany">Tiffany Alfonseca Pays Homage in Painting</span></h1>
      <br>
    </div>
    <div="" class="read-here">
      <bodycopy> <b><a href="https://latina.com/tiffany-alfonseca-pays-homage-in-painting/" target="_blank">Read here</a></b> </bodycopy>
    </div>
  </div>
  <br></div>

Answer №1

Make sure to include the px unit in your media queries like this:

@media only screen and (max-width: 480px)
{
}

In addition, I recommend using rem instead of vw for defining font sizes. You can find more information about this at: https://www.freecodecamp.org/news/what-is-rem-in-css/

Just remember that if you don't specify a font-size, the default is 16px. Therefore, 1rem is equal to 16px, 2rem equals 32px, and so on.

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

spill the elements from one div into another div

I'm facing a situation where I have 2 divs on a page, with the first div containing text content only. The issue is that when the content of the first div overflows, it gets cut off due to the CSS applied to it: .one { overflow: hidden; width: 1 ...

Add a border to the element if its height exceeds 300 pixels

My web page has a dynamic element with an unpredictable height. As more content is added, the element grows, but I have restricted it with a max-height: 300px;. However, I would like to add a hint to the user when the element reaches its maximum height by ...

Creating dynamic text bubble to accommodate wrapped text in React using Material-UI (MUI)

I am currently developing a chat application using ReactJS/MUI, and I have encountered an issue with the sizing of the text bubbles. The bubble itself is implemented as a Typography component: <Typography variant="body1" sx={bubbleStyle}> ...

Instructions on integrating iframe into Slides on material-auto-rotating-carousel

Looking to swap out the carousel slide image with a loom video. Any ideas on how to replace the media img with an iframe in material-auto-rotating-carousel? const AutoRotatingCarouselModal = ({ handleOpen, setHandleOpen, isMobile }) => { return ( ...

Image showcasing the background

I'm facing an issue with adding a background image to my project Even after trying to add it globally, the background image is not showing up on the Next.js index page. import { Inter } from 'next/font/google' const inter = Inter({ subsets: ...

Struggling with jquery's addClass method when trying to apply a class to

Below is a sample tr: <tr> <td><input type="text" class="ingredient required" name="ingredient"></td> <td><input type="number" class="amount required" name="amount" ></td> <td><input type="number" c ...

Steps to create a toggle feature for the FAQ accordion

I am currently working on creating an interactive FAQ accordion with specific features in mind: 1- Only one question and answer visible at a time (I have achieved this) 2- When toggling the open question, it should close automatically (having trouble with ...

Confusing Vaadin Component Styling Dilemma

I've been struggling to access the individual parts of elements that require navigating through the shadow DOM. I've been following a guide for assistance: https://github.com/vaadin/vaadin-themable-mixin/wiki/1.-Style-Scopes When I add this code ...

What is the best way to define the relative path and folder paths in HTML and CSS when working in Visual Studio 2012?

Working on a basic HTML project that includes css and javascript. Within the project folders named css, scripts, and images are used for organization. The project structure can be seen in the provided image. https://i.sstatic.net/OwCSL.jpg The issue that ...

Modify content or display picture within accordion panel based on its identifier

In my view, I have a model representing a list of items. Each item has a unique ID, which is included in the H2 header tag. The details of each item are displayed in a div below the header. Initially, there is an image within the header that is set to disp ...

A margin is set on a div element that occupies 100% width and 100% height, nestled within another div element also occupying 100% width and

As I work on constructing a website with a video background, my goal is to ensure that all divs are centered and responsive by setting the width and height to 100%. Additionally, I have implemented an overlaying div that fades in and out upon clicking usin ...

What is the best way to use absolute positioning in React Native to align an element with its grandparent?

I am trying to position a Font Awesome icon in a React Native project using absolute positioning relative to the grandparent element, rather than its direct parent. After some research, I came across the following information on this page: https://reactna ...

Setting the height of an element based on the height of its background image

Hey there! I'm currently working with this component in my app, and right now, the height of the ButtonBase element is fixed. I fetch an image from the backend and use it as a backgroundImage for the ImageImagine component. I want to dynamically adjus ...

Transform black and white image to vibrant colors and add various hover effects

There are three images displayed on this webpage: This website is built on WordPress and utilizes the WP Bakery plugin for designing layouts. The images here are set to change from color to grayscale, and back to color upon mouseover. The following CSS c ...

Trouble with displaying list bullets in jQTouch framework

I'm currently experimenting with jQTouch for a web app designed for iPhones. However, I am facing an issue where I want the content on the pages to display normal bullet lists instead of being styled as bars in the jqt theme. To achieve this, I am att ...

Creating a layout with an image positioned on the left and text on the right within a block using CSS

Can anyone provide guidance on how to design a layout similar to the one shown in this image: https://i.sstatic.net/RYAuA.png? I want the image on the left and text on the right, with responsiveness. Any help would be greatly appreciated. Thank you! < ...

Issue with uneven spacing on both ends of the screen on mobile devices

I have successfully used a <div style="margin:0 auto; "> tag with the specified property, working perfectly. However, I added another <div> above and set the float as follows: .gallery-div{ background:url(images/gallery-bg.png) repeat-y; ...

In Bootstrap 4, the positioning of :after is different compared to Bootstrap 3

Our bootstrap nav-tabs have a unique default look with an 'indicator' icon below the selected tab. This is achieved by styling the active anchor element as follows: https://i.sstatic.net/UQos5.png However, when migrating to bootstrap 4, we noti ...

Getting rid of the empty spaces between the lines of cards in Bootstrap 4

I want to eliminate the vertical space between the cards in my layout. Essentially, I want the cards to maximize the available space. I am open to using a plugin if necessary, but I have not been able to find any relevant information online (maybe I used t ...

Is it possible to use CSS to separate divs into distinct subgrids?

Is there a way to use CSS subgrids to display different divs in two columns, with all the .title's in the left column and the .card's in the right column? Here is a dynamic example for reference: https://codepen.io/dancanuck/pen/eYMLqzR body { ...