Ensure Bootstrap input maintains a fixed pixel width unless on a smaller screen, where it should expand to

With Bootstrap, I am trying to create form fields/inputs that are 200 pixels wide by default, but switch to 100% width when viewed on a smartphone with a screen width less than 768 pixels.

<form>
  <div class="form-group responsive200">
    <label for="email">Email Address</label>
    <input type="email" class="form-control" id="email">
  </div>
</form>

I applied this CSS styling, but the input fields remain 200 pixels wide even on smaller screens.

.responsive200 {
    width: 200px;
}

@media screen and (max-width: 768px) {
    .responsive200 { 
        width: 100%; 
    }
}

How can I ensure that my input fields are 200 pixels wide unless the screen width is less than 768 pixels, in which case they should be 100% wide?

Answer №1

Adjusting the @media query to this:

.responsive200 {
    width:200px;
}
@media screen and (max-width: 768px) {
    .responsive200 { width:100%; }
}

This modification should solve the issue

Answer №2

Actually, your media query is targeting devices wider than 768px when it should be the other way around.

Bootstrap's grid system first styles for mobile (the smallest devices) and then adjusts as the screen size increases.

Consider using this code snippet:

/* Styles for extra small devices (phones, less than 768px) */
.responsive200 {
    width:100%;
}

/* Adjustments for small devices (tablets, 768px and up) */  
@media screen and (min-width: 768px) {
    .responsive200 { width:200px; }
}

For more information, take a look at Bootstrap's documentation.

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

How to align an unordered list vertically in the center using Bootstrap?

Trying to figure out why the ul within this parent div is not centered vertically. Here is a screenshot of the issue: https://i.sstatic.net/ZOc9M.png <div className=" d-flex align-items-center bg-primary "> <ul ...

Fixed width layout in Bootstrap 3 with a footer that spans the full width of the

Currently, I am utilizing Bootstrap 3 with a fixed width set-up. The footer on my site consists of two columns, each with a different background color. In order to ensure that the content in the footer aligns properly with the rest of the website, I want ...

Using JQuery and Bootstrap: Adding an image from a selection of images to a carousel

As a beginner in the world of JQuery, I am currently working on creating a customizable carousel where users can select pictures to add to the carousel with just one click. On the left side of the page, there is a selection of images to choose from, while ...

Excess space located adjacent to primary content on website

When you scroll to the left of the page, next to the main content and outside of the browser width, there is additional space occupied only by the background of the Body CSS. Take a look at the site in action: . @charset "utf-8"; /* Custom CSS Styles * ...

Ensuring that the text input is perfectly lined up with the submit button

Is there a way to solve this discrepancy? Solution: https://jsfiddle.net/6q352ysx/59/ The elements are currently the same height, but not aligned properly. https://i.stack.imgur.com/ajVyJ.png Which alignment option should I use? Option 1: vertical-ali ...

Center an image vertically in an AdminLte content-wrapper division

I am currently utilizing an AdminLte template as the framework for my design. In the designated area where I need to insert the main content, it is structured in the following manner: <div class="content-wrapper"> <se ...

Exploring the implications of Content Security Policy in conjunction with mod_pagespeed evaluations

I am currently in the process of configuring CPS rules for my website. One issue I have encountered is that mod_pagespeeds often uses 'unsafe-eval' for scripts, which goes against my security settings. An example of code generated by mod_pagespee ...

Scoped Styles rarely stand a chance against more dominant styles

I'm facing a scope issue while learning Vue. Question: I am trying to make sure that the styles in profile.vue do not override the ones in sidebar.vue. I want the sidebar to have a red background and the profile section to be blue. Shouldn't usi ...

Guide on including an arrow to the right of a drop-down list button using CSS

I'm currently working on developing a drop down list using polymer. I am facing an issue with the CSS styling. Below is an example for reference: Access jsfiddle example here <div style="width:200px" class="button initial gray"> <div style ...

The div element is shifting as the page is being resized

When I increase the zoom level of my page to 110%, the div inside the larger one keeps getting bigger and eventually moves to a new line. Is there a way to stop it from shifting? If so, please provide guidance on how to fix this issue without criticizing m ...

What are some ways to utilize symbol fonts such as marvosym within a web browser?

Are you looking to use special LaTeX fonts like \Pluto from marvosym in your web development projects? Wondering how to display this symbol with HTML / JavaScript / CSS without relying on an image? You can download the font from This symbol corresp ...

Tips for adjusting the border-bottom line in real-time as text is selected from a dropdown menu

$('#select').on('change', function() { name = $('#select :selected').val(); //some code here }); . bdr-txtline { border-bottom: 1px solid black; } <div class="container"> <div class="row"> <div ...

How can I enhance the appearance of my custom field using CSS in Advanced Custom Fields?

Utilizing the Wordpress Advanced custom field plugin, I have successfully added a custom field to my site. Within this custom field, I have inserted images and now I am looking to center them on my page using CSS styles such as margin: 0 auto. If you&apo ...

Can the <br> tag affect the layout in terms of horizontal space?

I am perplexed by the fact that it displays two lines vertically separated with a br tag differently than two lines vertically separated with the first line acting as a block level tag. For example, see this code snippet: https://jsfiddle.net/qzgeassf/ ...

Comparing Flexbox Wrapping Behavior in Chrome and Firefox

Hey there! I'm currently grappling with ensuring that this (3-3) flexbox layout appears consistently on both Chrome and Firefox browsers. If you'd like to see a functioning example of what I'm trying to achieve (three columns and two rows) ...

issues with responsive mobile navigation

Greetings! I've been diligently working on a website project for a client, but I have a nagging feeling that I may have overlooked something important. If you'd like to take a look at the small design mockup preview I'm providing for the cl ...

Do colors appear differently on various screens?

I've noticed that the background color #1ABC9B appears differently on various monitors when viewing my website. On MAC systems and smart phones, it appears as a lighter shade of green compared to other laptops where it appears darker. What could be ca ...

Tips on positioning an element absolutely so that it stops right before another element as the screen width is adjusted

Imagine a scenario where there is a 'parent' block containing various elements, including a button. When the user clicks this button, a 'slide' element should appear and cover the parent block but only up to the button itself (as shown ...

Activate an event on a shadow DOM element that is covered by an element in the light DOM (not directly related)

I am currently facing a challenge in retrieving the coordinates of a table cell within a shadow DOM. This table cell may have overlay elements displayed above it, which could span over multiple cells and may not necessarily be direct children of the cell I ...

Ways to allow scroll events on top of an overlay without passing click events

My goal is to develop a unique map annotation tool with custom controls, not relying on the built-in features of map providers. Imagine something like this: https://i.sstatic.net/70Yj7.gif I had the idea of placing a canvas over the map for this purpose ...