Ensure that the page is optimized for mobile devices

After creating 5 stars for my page, I realized that it is not mobile-friendly as the stars stack vertically when the screen size is reduced. Is there a simple way to make this design responsive while keeping the stars in a horizontal layout?

I attempted to add more divs to maintain the horizontal alignment of the stars regardless of the screen size.

body {
  background-color: #FFFFFF;
}

.flex {
  display: flex;
  /*14vm*/
  width: 16vw;
  margin: 0 auto;
  justify-content: space-between
}

.rate {
  position: relative;
  /*46vm*/
  height: 65vm;
  padding: 0 10px;
}

.rate:not(:checked)>input {
  position: absolute;
  top: -9999px;
}

.rate:not(:checked)>label {
  float: right;
  width: 1em;
  overflow: hidden;
  white-space: nowrap;
  cursor: pointer;
  font-size: 35px;
  color: #ccc;
}

.rate:not(:checked)>label:before {
  content: '★ ';
}

.rate>input:checked~label {
  color: #9d0505;
}

.rate:not(:checked)>label:hover,
.rate:not(:checked)>label:hover~label {
  color: #9d0505;
}
<div class="flex">
  <div class="rate">
    <input type="radio" onclick="rate1_scr5();" id="star10" name="rate1" value="1" />
    <label for="star10" title="text">5 stars</label>
    <input type="radio" onclick="rate1_scr4();" id="star9" name="rate1" value="2" />
    <label for="star9" title="text">4 stars</label>
    <input type="radio" onclick="rate1_scr3();" id="star8" name="rate1" value="3" />
    <label for="star8" title="text">3 stars</label>
    <input type="radio" onclick="rate1_scr2();" id="star7" name="rate1" value="4" />
    <label for="star7" title="text">2 stars</label>
    <input type="radio" onclick="rate1_scr1();" id="star6" name="rate1" value="5" />
    <label for="star6" title="text">1 star</label>
  </div>
</div>

Answer №1

Is there a simple way to ensure that this layout is mobile-friendly without compromising the horizontal alignment of the stars?

Absolutely! Just adjust the parent container's width to max-content to prevent any wrapping issues. Check out the code snippet below for reference:

body {
  background-color: #FFFFFF;
}

.flex {
  display: flex;
  /*14vm*/
  width: max-content;
  margin: 0 auto;
  justify-content: space-between
}

.rate {
  position: relative;
  /*46vm*/
  height: 65vm;
  padding: 0 10px;
}

.rate:not(:checked)>input {
  position: absolute;
  top: -9999px;
}

.rate:not(:checked)>label {
  float: right;
  width: 1em;
  overflow: hidden;
  white-space: nowrap;
  cursor: pointer;
  font-size: 35px;
  color: #ccc;
}

.rate:not(:checked)>label:before {
  content: '★ ';
}

.rate>input:checked~label {
  color: #9d0505;
}

.rate:not(:checked)>label:hover,
.rate:not(:checked)>label:hover~label {
  color: #9d0505;
}
<div class="flex">
  <div class="rate">
    <input type="radio" onclick="rate1_scr5();" id="star10" name="rate1" value="1" />
    <label for="star10" title="text">5 stars</label>
    <input type="radio" onclick="rate1_scr4();" id="star9" name="rate1" value="2" />
    <label for="star9" title="text">4 stars</label>
    <input type="radio" onclick="rate1_scr3();" id="star8" name="rate1" value="3" />
    <label for="star8" title="text">3 stars</label>
    <input type="radio" onclick="rate1_scr2();" id="star7" name="rate1" value="4" />
    <label for="star7" title="text">2 stars</label>
    <input type="radio" onclick="rate1_scr1();" id="star6" name="rate1" value="5" />
    <label for="star6" title="text">1 star</label>
  </div>
</div>

This Stack Overflow post can provide further insights on the functionality of max-content value.

Answer №2

Revise your flex style. While it's a solid beginning, consider tweaking the width to ensure compatibility with mobile devices. A width of 16vw may appear too small on mobile screens. You might want to try using values like 300px, or utilize @media screen queries (such as

@media screen and (min-width: 900px) { ... }
) to dynamically adjust the width based on the screen's size. The suggestion to set the width to max-content is also worth considering.

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

Using jQuery to store the last selected href/button in a cookie for easy retrieval

Recently, I've been working on a document that features a top navigation with 4 different links. Each time a link is clicked, a div right below it changes its size accordingly. My goal now is to implement the use of cookies to remember the last select ...

What could be causing the drop-down menu to have such a jerky transition?

After trying numerous approaches, I am seeking help again. I have managed to create a dropdown menu, but now I'm wondering how to add a transition effect to it. Any suggestions on what changes I should make are greatly appreciated. Below is the code s ...

Ensure that both the top row and leftmost column are fixed in a vertical header using JQuery DataTable

Check out the implementation of vertical header flow in Datatables by visiting: https://jsfiddle.net/2unr54zc/ While I have successfully fixed the columns on horizontal scroll, I'm facing difficulty in fixing the first two rows when vertically scroll ...

What is the best way to interpret content within a span using aria-hidden?

I've been attempting to solve this problem for the past two hours, but I haven't had any success in finding a way to extract text from a span element that is hidden with an "aria-hidden=true" tag. The structure of the website's code looks li ...

The Yii form does not show the save message

One of my forms shows the save message, but the other one doesn't display it. The first view confirms the data is saved, while the second one does not show any confirmation message, even though the data is stored in tables. For the code snippets rel ...

Prevent child div from resizing along with parent div during a resize event by utilizing the .resizable()

Check out this example here I am able to resize the div using jQuery, but I don't want the #spacer to have a fixed width at first because the content of the could vary in size. Even if I remove: width:100px; and try setting it to a percentage or ...

Scrolling problems with numerous bootstrap modals on a Webpage

I am faced with an issue on a page where I have set the property overflow: auto. This page features a hyperlink to open the first modal, and within the first modal, there is a link to the second modal. My steps are as follows: Open Page 1 Click on the l ...

Styling Images on Your Blog with CSS

As a newcomer to CSS trying to start my own blog, I've hit a stumbling block that I can't seem to figure out. My code currently displays the picture, title, and descriptions of each post on the main page. However, I only want the picture to disp ...

Hiding divs toggle off when either all or only one is selected

In a certain page, there is a script that displays a div when a user selects an option. The script functions correctly, except for a scenario where if the user selects 'd' (which shows 'a', 'b', and 'c'), and then se ...

The efficiency of ASP.NET's rendering of HTML tables

I am working on generating an HTML report that includes a table with 265 rows and a varying number of columns (ranging from 1 to over 150). The issue arises when I attempt to display a report with more than 20 columns: while fetching data from the databas ...

The functionality of submitting an Ajax form is only successful on Firefox browser

My Ajax login form is functioning properly only on Firefox. However, in other browsers, it continues to submit the form and load the function page. I aim for it to send the two fields to a function page, validate them in the background, and display the res ...

Strategies for detecting changes in multiple HTML select elements with jQuery

I currently have three select HTML tags and I would like to filter my table using the selected values (group of selected tags) with an AJAX request. For example, filtering by Gender, Location, and Season. My question is how can I achieve this without dup ...

Having issues extracting information from easports.com due to difficulties with the <ea-elements-loader> element

Recently, I've been developing a Python WebScraper to extract data (such as wins and losses) from our FIFA ProClub by crawling various websites. While I successfully implemented it on a third-party website using BeautifulSoup and requests, I encounter ...

What steps should I take to repair the footer on this webpage?

Working on a footer using bootstrap and it's looking great, but I encountered an issue with blank space appearing at a specific resolution (see image below). Bootstrap Footer: https://i.sstatic.net/XifQe.png My Footer Design: <footer> < ...

CSS - when "start" is not 1, an alternative to the "nth-child" selector

Imagine a scenario where you have a list of questions that start at 0 and you want to apply CSS styling based on their value. For instance, consider the following list... <b>How are you feeling?</b> <ol start="0"> <li>Great< ...

Conceal the vertical scrollbar while enabling scrolling functionality on Firefox, Internet Explorer, and Edge browsers

Although this issue has been addressed multiple times, I am still unable to find a solution that works for me. The scrollbar continues to appear on Windows OS browsers such as Firefox, Edge, and IE. Please note: I do not want to adjust padding or margins ...

Angular Flot Chart Resizing: A Guide to Dynamic Chart S

I have successfully integrated a Flot chart into my HTML using an Angular directive. Here is how it looks: <flot id="placeholder" dataset="dataset" options="options" height="300px" width="100%" style="width:100%;" ng-disabled="graphLoading" ng-class="{ ...

implement some level of control within the ngFor directive in Angular

For instance, let's say I have an ngfor loop: <ng-container *ngFor="let setting of settings | trackBy: trackById"> <button mat-button [matMenuTriggerFor]="menu">Menu</button> <mat-me ...

Problem with white screen in Cocos2d-html5

I'm experiencing an issue with my cocos2d html5 game on the Tizen platform. While it runs perfectly on PC and all browsers without any errors, on Tizen it only displays a white screen. It seems like the update loop is functioning correctly, but there ...

Updating the class of a div based on a checkbox being checked or unchecked

I am attempting to apply the "isChecked" class to the parent div when a checkbox is checked, using the ngClass directive. Here is the HTML: <div ng-class="{isChecked: (isChecked_1 == 'true')}"> <input type="checkbox" id="check_ ...