Tips for adjusting HTML and CSS for mobile devices

When implementing a countdown on my website, I encountered a formatting issue when accessing it from a mobile device. The countdown is displayed on two lines instead of one, making it look strange and difficult to resize.

The current code I am using:

    body{
      text-align: left;
      background: #ffffff;
      font-family: sans-serif;
      font-weight: 100;
    }
    
    h1.customclass{
      color: #032g71;
      font-weight: 50;
      font-size: 40px;
      margin: 0px 0px 10px;
    }
    
    #clockdiv{
    font-family: sans-serif;
    color: #fff;
    display: inline-block;
    font-weight: 100;
    text-align: center;
    font-size: 30px;
    }
    
    #clockdiv > div{
    padding: 10px;
    border-radius: 3px;
    background: #055678;
    display: inline-block;
    }
    
    #clockdiv div > span{
    padding: 0px;
    border-radius: 3px;
    background: #055678;
    display: inline-block;
    }
    
    .smalltext{
    padding-top: 5px;
    font-size: 16px;
    }
 <h1 class="customclass">TEST COUNTDOWN</h1>
    <div id="clockdiv">
      <div>
        <span class="days"></span>
        <div class="smalltext">Days</div>
      </div>
      <div>
        <span class="hours"></span>
        <div class="smalltext">Hours</div>
      </div>
      <div>
        <span class="minutes"></span>
        <div class="smalltext">Minutes</div>
      </div>
      <div>
        <span class="seconds"></span>
        <div class="smalltext">Seconds</div>
      </div>
    </div>

In order to address this issue, I'm considering using:

@media only screen and (min-device-width : 320px) and (max-device-width : 480px) {

However, I'm unsure how to specifically apply this to the #clockdiv element when accessed from a mobile device. Is there a way to target and resize #clockdiv only for mobile users?

Any assistance with this matter would be greatly appreciated!

Answer №1

If you have fluid sizes for your DIVs and spans, meaning their size is based on the content inside them, adjusting font-sizes and padding in a media query can help maintain a cohesive design across different screen sizes.

@media only screen and (max-width : 480px) {
  #clockdiv {
     font-size: 18px;
  }
  #clockdiv > div {
     padding: 4px;      
  }
   .smalltext{
     padding-top: 2px;
     font-size: 12px;
  }
}

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

Is there a bug with Kendo UI? The Kendo grid pager seems to be misaligned with the bottom

Recently, I've been experimenting with Kendo UI and encountered a specific issue: The pager for my Kendo grid is not aligning properly at the bottom of the grid. Although I've attempted to adjust the CSS styling for k-grid-pager, the issue persis ...

What steps should I take to achieve this specific style for my WordPress website post?

Check out the image link here I'm looking to position the share and read more buttons at the bottom of the div, similar to "Sample Post 14". The trick seems to involve using excerpt or dummy text. Is there a way to achieve this styling with the skele ...

I'm having trouble with the colors not displaying correctly on my NextJS Tailwind navbar

I've encountered an issue with my navbar where none of the specified colors are being displayed. The code snippet for the navbar is as follows: Codes: 'use client' import Head from 'next/head'; import Link from 'next/link&apo ...

Managing sessions and cookies for Firefox forms

On my webpage, there is a poll form where users can vote and see the results through an ajax request. When a user votes, a cookie is created to prevent them from voting again upon returning to the page. However, I have encountered an issue with Firefox wh ...

Eliminating hidden boundaries in a table by using CSS styling

I currently have a div container with a table embedded within. HTML: <div id='ribbon'><table id='topMenu'> <tr> <td><a href='index.php'>Home</a></td> <td><a href='links ...

What is the reason for the improper setting of the div position?

Welcome to the interactive Pointer Pin application! The red-bordered box is where you can drop your Pointer Pins. This area has a background image set. The blue-bordered box is where you can drag various Pointer Pins from. These pins can be dropped into ...

No animated scrolling occurring

I have been struggling with this problem for a while now and despite having gone through 100 questions, I still can't find a solution as to why my code snippet is failing. Here is the jQuery code I am using: $("#readmore").click(function(event){ ...

Customizing the input placeholder for password fields in IE8 using jQuery

Currently, I have opted to use jQuery instead of the HTML5 placeholder attribute <input type="text" name="email" value="Email" onfocus="if (this.value == 'Email') { this.value = ''; }" onblur="if (this.value == '') { this. ...

Having difficulties in expanding my input bar to 100% width and center aligning it

Creating a webpage in a jsp file with the help of spring boot, I've utilized bootstrap for the design. I'm facing some challenges as I'm unable to widen my input box to width:100% on both the login and new registration pages. Additionally, c ...

What causes jQuery's append function to trigger a redraw of my Div?

I have a unique function that incrementally increases the date by one day every second. Once the date matches specific dates, I aim to update my #newsDiv with extra text content. The #newsDiv will display all historical "news" and will be set to scroll to ...

creating a random integer and seamlessly transmitting it to the header

When a user enters an incorrect email or password in the login form, I redirect them to login.php?Err=284613 using header ('Location: login.php?Err=284613');. Then, I use Javascript to detect this error code on the page with if (window.location.s ...

What are the steps to effectively cultivate an isometric rectangular box using HTML and CSS?

Starting at the top in isometric grids, like this, can be quite convenient: https://i.sstatic.net/YFh0SRmx.jpg The code below is used to create a "3d" isometric box: body { display: flex; justify-content: center; align-items: center; } .plane { ...

What could be causing the content to disappear when switching from flex: column to flex: row?

In the code snippet provided below, you may notice that when the screen size is less than 768px, the video and content underneath it are visible. However, as soon as the screen size exceeds 768px, the video disappears. Have you ever wondered why the video ...

Tips for showing an image in a PHP document

UPDATE: Successfully resolved the issue by avoiding absolute file paths (../Images\City of Bath College Logo.jpg). 2nd UPDATE: Also implemented the same fix for the CSS file and now it functions "the HTML way". I'm encountering a problem displa ...

How to centrally position an image within a div using Bootstrap

I am a fan of using bootstrap and I recently encountered an issue with applying max-width to an image. It seems that when I do this, the image does not center properly despite using text-center. The solution I found was simply removing the max-width to ...

Adjust the height of the dropdown list in react-select (React Material UI)

I recently added a dropdown feature using react-select to my project. However, I encountered an issue where the dropdown list was initially too large and taking up the entire page. I am looking for a solution on how to style the react-select dropdown list ...

Issue with MUI Grid item not functioning properly when using overflowY: "auto"

I am encountering an issue while using MUI with React. I have a <Paper> element wrapping a <Grid> with 3 children elements. The problem arises when I set the overflowY property of the bottom grid item to "auto" - instead of showing the scroll b ...

The updated version of Angular from 13 to 16 has implemented a new default value for primary colors

I recently upgraded my angular (+material-ui) system from version 13 to 16, and encountered an issue with the primary color of my custom theme. It seems that the value is no longer being recognized and defaults to blue. After updating the angular version, ...

CSS tip: Keep the bottom of the screen always visible in an overflow window

My webpage has a continuously updating element where new data is added to the bottom. I currently have 'overflow: scroll' enabled for users to manually scroll down and view this new information. However, I am looking for a way to display these up ...

Having Issues with JSFiddle: Difficulty with executing a basic onclick event to display a string

Having trouble with an onclick event: Simply click the button to run a function that displays "Hello World" in a paragraph element with id="demo". <button onclick="myFunction()">Click me</button> <p id="demo"></p> <script> ...