Troubleshooting Media Queries in HTML, CSS, Bootstrap: Why Aren't They Applying as Expected?

I am still fairly new to web programming and just starting out with bootstrap.

After creating a section of my page that worked well on larger screens, I realized it wasn't responsive enough on smaller devices. The height was set at 400px, causing horizontal squishing on phones. To address this, I tried wrapping half of the content to the bottom, but it created other layout issues. I decided that setting the height to 800px for smaller screens would be a solution.

My search led me to media queries as a potential fix for this problem.

Initially, I had the following code where the height is fixed at 400px:

.addon {height:400px;}

While this worked fine for screens equal to or larger than 'md', it didn't provide the desired responsiveness for smaller screens.


This is my attempt at solving the issue:

@media (min-width: @screen-md-min) 
{
    .addon {height:400px;}
}

@media (max-width: @screen-sm-max)
{
    .addon {height:800px}
}

Unfortunately, this code doesn't seem to have any effect regardless of the screen size. Despite researching and double-checking my approach, I'm unable to figure out why it's not working as expected.

If anyone can offer some guidance or point out what mistakes I may be making, I would greatly appreciate it.

Answer №1

It seems that I was not utilizing the LESS variables @screen-md-min and @screen-sm-max. Instead, by replacing them with specific pixel values, the code now functions correctly.

@media (min-width: 992px) 
{
    .addon {height:400px;}
}

@media (max-width: 991px)
{
    .addon {height:800px}
}

Answer №2

Utilizing Twitter Bootstrap classes such as col-xx-12 is recommended as it divides the specified container into 12 columns, adjusting automatically when the screen size changes. Keep in mind that this functionality will not be effective unless the view-port = 1.0 meta tag is properly applied.

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

Transmit a communication from a customer to the server

I have created a NodeJs server that is listening on port 1234. I am looking to send requests from my HTML client to this server and receive responses. I attempted to use XMLHttpRequest: var http = new XMLHttpRequest(); var url = "127.0.0. ...

Guide to calculating word count in javascript while excluding words with only one character

How can I create a JavaScript function to count the words in a textarea, but exclude all single letter words? For example, if the input is "This is a word count," the count should be 4 since the word "a" is excluded. Although I have a basic understanding ...

Configuring the color of the active page link in the navbar using Python Flask

In order to highlight the current page that the user is on, I want the link of the current page to have a different color compared to the other page links. This will help the user easily identify which page they are currently viewing. I am implementing thi ...

Rotating Cursor during AJAX loading process

I utilize a WebGrid across many of my pages to showcase various products. Within the code snippet below, you can see how an item is added to the database when a user clicks on it: public bool ToCart(int userId, string partNumber, ...

What is the best way to incorporate a fresh array into the existing array element stored in local storage?

I stored a group of users in the local storage: let btnSignUp = document.getElementById("btnSignUp"); btnSignUp.addEventListener('click', (e) => { let existingUsers = JSON.parse(localStorage.getItem("allUsers")); if (existingUsers == null ...

How can you use Dart to uncover the content within an H1 element on an HTML webpage?

I'm currently self-teaching mobile development with Dart and Flutter, and my current project involves connecting a mobile app to a website. I want to extract the text from an H1 tag that is loaded through JavaScript on the website and display it in th ...

What steps should I take to correct the color selection of a button that has been pressed down

Here is the code snippet that I am currently working with: HTTP: <label class="instructions" for="hidden_x"> Insert X: </label> <button type="button" class="button" name="button_x" value="1" id="x_1" onclick="document.getElementById(' ...

Centered text in <td> with CSS aligned to the right

https://i.sstatic.net/UrB5f.jpg Is there a way to align the 3 input fields so that their right edges are all vertical? I still want the text+Input to be centered within the column but aligned vertically... Using Bootstrap 3.3.7 HTML: <link href="h ...

Utilizing jQuery to display labels only for selected checkboxes while concealing the ones that are not checked

I currently have the following setup: <style>.selectit{display:none;}</style> <div id="foo"> <label class="selectit"> <input type="checkbox" name="one" id="one" checked> One </label> <label class="selectit"> <i ...

CSS code that causes the animated photo banner to reset instead of continuously looping back to the first

I followed a tutorial and created this banner using HTML and CSS. However, I encountered an issue where instead of the banner continuing in loops, it keeps resetting. Since we haven't covered JavaScript yet in university, I'm looking for help to ...

Insert placeholder text without access to the input field

Is it possible to activate a placeholder in a component that is outside of the current context? For example: <foreign-component [config]="someConfig" placeholder="somePlaceholder"></foreign-component> The <foreign-compo ...

The Bootstrap table is not adhering to the specified width when the display is set

I encountered an issue starting yesterday. I am utilizing Bootstrap 4 and tables. Whenever I set a width greater than 13.5vw, the table does not adjust accordingly. You can view the fiddle here Below is the code snippet: HTML <table cl ...

PHP file secured to only accept variables posted from HTML form

This is a basic HTML/AJAX/PHP script I have implemented. <form id="new_user" action="" method="post"> <div class="col-md-3 form-group"> <label for="username">Username</label> <input type="text" class="form-control" name ...

Ensure that the user remains within the current div when they click the submit button, even if the textbox is

For the past 48 hours, I've been grappling with an issue on my HTML page that features four divs. Each div contains three input fields and a button. The problem arises when a user leaves a text box empty upon submitting - instead of staying in the sam ...

Can you please provide the selector needed to extract the first image from the infobox of a Wikipedia page using the Wikipedia API?

I am attempting to extract the first image from the infobox table on Wikipedia pages using the Wikipedia/Mediawiki API. Here is my current approach: $.getJSON("http://en.wikipedia.org/w/api.php?action=mobileview&format=json&page=mumbai&redire ...

Having trouble accessing a jQuery function in the componentDidMount() of a React component from a separate .js file

I have been diving into the world of jQuery for quite some time now and it has been a rewarding process. However, there is one particular challenge that I am currently facing. Despite my efforts to find a solution on my own, the answers I came across were ...

Unable to retrieve data for the initial keystroke in jQuery autocomplete

I'm currently working on setting up jQuery autocomplete with a specific method involving a separate source function and an intermediary variable for data storage. My main goal right now is to successfully pass the data to the source part of the autoCo ...

"Click to view the latest data visualization using the Chart.js

I am exploring ways to enhance the animations in Chart.js for a new web project. The content is organized in tabs, with the chart displayed on the third tab out of four. Currently, the chart animates upon loading. How can I make it so that when #chartTrig ...

Executing the onSuccess callback in Ajax without any ability to manipulate the ajax requests

My dilemma lies in needing to execute a JavaScript function upon the successful completion of an AJAX call. Unfortunately, I am unable to directly manage the AJAX calls as they are handled by the DNN5 framework. Is there a way for me to trigger my functio ...

Execute a jQuery ajax request to a specific variable

For my Phonegap/Cordova project, I have implemented functions to handle all ajax calls in the following way: function requestData(action, id ) { var data = { user_id: localStorage.getItem('user_id') }; if( action == 'fee ...