What specific width range would be best for my needs?

I used to have the default font style of Myriad Pro Light and a padding setting for my main menu on my website as follows:

.menu > li > a { padding: 17px 15px 15px 15px; }

Recently, I changed the default font style to Montserrat. However, this change caused an issue with the display of the main menu on my laptop screen. The combination of the right padding of 15px and the Montserrat font made the menu too wide, causing it to extend beyond the container's width and pushing the last menu item onto a new line. Here it was shown that my screen width is 1366px.

To address this problem, I adjusted the padding to:

.menu > li > a { padding: 17px 7px 15px 15px; }

This solution worked on my screen, but it posed a challenge on larger screens with widths like 1538px and 1600px where a padding of 7px was insufficient, resulting in the menu only extending halfway across the container. For such bigger screens, the ideal padding should be:

.menu > li > a { padding: 17px 35px 15px 15px; }

Although this corrected the issue on larger screens, simply using a fixed padding value could potentially disrupt the layout on other screen sizes.

The best approach here would be to utilize CSS media queries by stipulating:

@media only screen and (min-width: X) and (max-width: Y) {
    .menu > li > a {padding: 17px 7px 15px 20px}
}

@media only screen and (min-width: Z) {
    .menu > li > a {padding: 17px 35px 15px 20px}
}

While this method effectively solves the issue, determining the correct values for X, Y, and Z can be challenging.

For reference, the responsive stylesheet being used can be found at this link, which contains style rules for various screen sizes including the Base (1180 Grid) and Desktop (960 Grid) layouts primarily geared towards computer screens. After analyzing these styles, I settled on X as 960px (minimum width for computers), Y as 1366px (my screen width), and Z as 1367px (minimum width requiring a padding adjustment).

Despite feeling comfortable with X, I am uncertain about whether Y and Z are correctly designated. Concerns arise regarding potential issues on slightly wider screens like 1380px, where a padding of 7px may be more appropriate, indicating errors in my chosen Y and Z values.

If you have any suggestions on what values to assign to Y and Z to ensure optimal display across all computer screen sizes, please feel free to share your insights.

Answer №1

The main menu became too wide and didn't fit in the container due to padding on the right side and the use of Montserrat font, causing the last main menu item to be pushed to a new line.

To adjust the padding for the last element, you can use this code snippet:

.menu > li:last-child > a { padding-right: 0; }

However, keep in mind these important points:

  1. Web fonts may appear differently across various browsers and devices, so avoid designing based on one specific view.

  2. If your menu spans more than one line at certain resolutions, consider switching to a different type of menu like a single drop-down or full-screen menu activated by a menu icon click.

  3. You can easily determine the viewport width and height using Chrome Developer Tools or browser extensions without relying on external websites.

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

Python Flask login application failing to redirect to login page

Currently, I'm building a login application with Python Flask and MongoDB integration at the backend. While everything else seems to be running smoothly, there's an issue with redirecting to the login page upon login. # See below for my code @ap ...

Span Element Not Triggering Jquery Click Event

I'm having trouble with the click event not triggering for either the span or the <i> when I move the id to the <i> tag. $("body").on("click", "#btnClear", function() { alert("Clicked"); }); <script src="https://ajax.googleapis.com ...

Tips for swapping out a div tag with another div tag in the same spot without needing to redirect to a different page by utilizing bootstrap

Currently, I am developing a JSP project that utilizes Bootstrap for the frontend. I have come across a question regarding HTML design. Is there a way to replace one div tag with another div on the same page without navigating to a new URL using Bootstrap ...

Discovering the center of an element and implementing a left float

I'm looking for a way to dynamically position the element #ucp_arrow in the middle of a div using float: left. Here is an illustration: https://i.stack.imgur.com/nzvgb.png Currently, I have hard-coded it like this: JAVASCRIPT: $("#a_account").cli ...

The request response was a JSON object that started with the keyword "POST"

My frustration is growing as I encounter a strange issue with the stack template I purchased from envato market. Every time I attempt a simple ajax request, the json returned from my PHP script seems to be invalid. Interestingly, the exact same code works ...

Choosing the initial offspring of an element that do not share a common parent

My question might not be perfectly phrased, for which I apologize. Is there a CSS method to select only the first child of an element without affecting others that are not grouped under the same parent? For instance: <div class="parent"> <div ...

Steps to retrieve data (token) from developer tools and incorporate it into a fetch Post request

Is there a simple way to extract data using dev tools and insert it into a fetch request? I am trying to make a POST request through the console, but I am struggling to correctly copy a token. I attempted to use querySelector but instead of finding the t ...

concealing elements using negative margins on tablet devices

I have an animated element on the ipad, moving from -200px to 1500px and being hidden due to overflow-x:hidden in the browser. However, when viewing this on the ipad, I am able to scroll "off screen" and reveal the hidden items, despite setting the body a ...

"Customize Your CSS Dropdown Menu with Dynamic Background Color for div Elements

I recently put together a website dedicated to watches. Feel free to check it out at horology dot info. (Please refrain from sharing the direct URL of my site in your reply.) I'm curious as to why the dropdown menu, sourced from , is showing up unde ...

Steps for generating instances of an HTML page and dynamically adding them to a list on the main page

I have a main HTML page and I need to insert a dynamically generated list from a template in another HTML file that I created. The template for each item in the list is located on a separate HTML page. My goal is to create multiple instances of this HTML ...

"Error encountered with window.open function not launching the desired link

I've been attempting to create a new window with a share link using the code snippet below: $content .= "<div class='container-after-post'> <div class='sharing'> <a href='$sswc_ ...

Guide to adding an icon within an HTML `<input>` element

Is anyone able to help me successfully place my icon font inside the search input field? I've tried adjusting the margin and padding, but nothing seems to be working! If you have any insights or suggestions, please let me know. Your help is greatly a ...

Redirecting a CSS link on a website

I have a webpage with a "read more" option that redirects to the About Us page. When I click on "read more", the About Us page opens at the top, but I want it to redirect to the bottom of the About Us page. How can I achieve this? ...

Updating the background of a div in HTML through the power of JavaScript

I am having trouble changing the background of a DIV. I believe my code is correct, but it doesn't seem to be working. I suspect the error lies with the URL parameter, as the function works without it. Here is my code: <script language="JavaS ...

Retrieving the statuses of all checkboxes in a web form populated by a MySQL query

I currently have a webform that is filled with mysql objects. Here is the existing webform: if($statement_opc->execute()) { $option_number = 0; $option_result = $statement_opc->fetchAll(); foreach($option_result as $row_opc) { ...

Utilize generated styling data bindings when referencing assets

Currently, I am working with vue-cli 3 and trying to create background-image paths. To achieve this, I am utilizing the style data bind within a v-for-loop. Below is the component structure: <template> <ul> <li v-for="(tool, inde ...

What is the source of these additional pixels that appear when percentages are used for defining height?

I have been working on implementing a sticky footer that I've successfully used in the past for various websites. You can find the link to the original method here: However, this time I am facing a challenge as I want to make the footer more responsi ...

Tips for making Google search results include query strings in the returned links

I need help figuring out how to make Google search results show a URL containing a query string. Here's an example from the project I am currently working on: Instead of this link, Google search returns: If anyone has any suggestions for fixing this ...

Ways to vertically center an absolutely positioned element

In the code snippet below, there is a .square-container that is absolutely positioned and contains a square. The goal is to vertically center the .square-container within its parent div. .container { position: relative; background-color: blue; } ...

Is there a way to display the form values on the table once it has been submitted?

I'm struggling with my form input not showing up under the table headings after submission. I've reviewed the code multiple times, but can't figure out what's causing the issue. If you have any suggestions on how to write the code more ...