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

When I type text into the form field, JavaScript causes a disruption in the form

I'm attempting to implement a dual-stage user onboarding procedure. Initially, users will input the industry they belong to and then provide a description. Upon clicking submit, my intention is to conceal that portion of the form and reveal the "Creat ...

Encountering an Error 405 Method Not Allowed while attempting to send a PUT AJAX request to a PHP server using

I am currently working on implementing a REST-like application using PHP and jQuery. During my initial attempt, I encountered the following error: PUT http://... 405 (Method Not Allowed) To address this issue, I added the following lines at the beginn ...

Coinciding titles within flot pie chart

I am facing an issue with overlapping labels in my pie charts generated using jquery flot, especially when the chart pieces are very small. Is there a recommended solution to prevent this overlap? Below is the configuration for my current pie chart: ser ...

Activate the overflow feature within native-base cards

I have a unique design element on a website that showcases an image overflowing off a card. The image has a negative margin-top of -50, creating this effect. Now I'm trying to replicate this design in react-native using native-base components. Here i ...

Is it possible to programmatically hide the Textarea and submit button for each row in a PHP-generated database table?

After spending a considerable amount of time on this project, I'm looking to incorporate a JavaScript effect (hide/unhide) into a basic submit form. Although the functionality is successful, it seems to be limited to only one row in the database tabl ...

AJAX requires manual updating by clicking on a button

I've created a chat system where two individuals can communicate with each other. An AJAX function has been implemented to update the message container every 2 seconds. However, I have noticed that the AJAX call doesn't run immediately after a u ...

Trigger the animation of a Div element when the cursor hovers over a different Div

I am interested in creating an animation where one div moves when the mouse hovers over another div elsewhere on the page. Here is an example... CSS #blue-box { position:absolute; margin-left:50px; margin-top:50px; height:100px; width:100px; background-c ...

The property 'innerHTML' cannot be assigned to null, as stated in Vue

I am dealing with two components that allow for editing JSON objects. Additionally, I have a button that toggles between these two components. Below is the HTML code snippet: <v-btn @click="switchConfigClicked">Switch config</v-btn> <h4 cla ...

Capture screenshots of the web page URLs within the Chrome browser by utilizing PhantomJS

Looking for a way to capture screenshots of various URLs and display them in the Chrome browser using PhantomJS. How can I achieve this? Any assistance would be greatly appreciated, as nothing is currently showing up on the webpage. This is how my code a ...

Ways to consistently return to the main home URL/directory within an HTML document

Greetings to all! Currently facing a challenge with HTML pathing. I want to ensure that every time I log out from Dynamics CRM Portals, I am redirected back to the "SignIn" page. The issue arises when I am in various URLs. For example, logging out from d ...

The communication feature using jQuery and PHP is not saving information to the database

I'm currently in the process of setting up a chat page using jQuery and PHP. However, I've encountered an issue where although the Added echo statement appears after submitting data on my simple form, the information is not actually being added t ...

The error detected in the W3Schools validator pertains to CSS for audio elements that do not contain

Could somebody kindly explain why this code is being flagged as an error on w3schools? audio:not([controls]) { display: none; height: 0; } ...

Issues with Swiper functionality in Jquery Mobile

I have implemented the Swiper plugin by idangero.us along with jQuery Mobile... In this case, I am utilizing the Scroll Container Swiper for a content slider... However, I am encountering several difficulties when trying to integrate the code... You can ...

Experiencing difficulties with transferring a variable within a Jquery function

I need help with this function function procData(a) { $('#loading' + a).show(); $.post("ajax.php?talk=" + a, { slot: $('#slot' + a).val() }, function (response) { $('#talkdesc' + a).fadeOut(); ...

Utilize Flask and Python to make data predictions on a CSV file

Hello there, Just starting out with Python and Flask API, I'm currently working on importing a CSV file and exporting another CSV file with predictions. The INPUT CSV file is structured like this experience test_score interview five ...

Ensuring Email Authenticity in React Native

I'm currently working on email validation and have a specific condition in mind. If the email textbox is empty, I want to return true When the email textbox is not empty, I need to check if the input is a valid email address If the email is n ...

A step-by-step guide on dynamically updating the placeholder attribute of an element using a fed id

I'm completely new to jQuery and I have a feeling that I'm making numerous mistakes in my code. As part of a project, I am creating a small search page for esports teams. The user selects their team from the homepage, which is then transferred t ...

How can you use JQuery to assign a single function as an onClick handler for multiple radio buttons?

I have a custom function named handleOnClickRadio(i, j);, and multiple radio buttons with the IDs in the format of id="something-radio[i][j]". These radio buttons are all contained within a table labeled "bigtable". Is there a way to link the function han ...

Stopping the WordPress gallery at the end without looping using Elementor

Is there a way to make my gallery stop at the end of the last picture without having to add any jQuery code? I inserted this gallery using elementor widgets and would appreciate your help on this matter. Additional information: Upon clicking on an image, ...

Issue with Mat-AutoComplete arising while utilizing a formArray

After adding a form array to account for multiple rows, I had to modify my definition from: shoppingCartList Observable<any[]>; to shoppingCartList: Observable<any[]>[] = [];. However, this change resulted in an error in my filter function whic ...