Responsiveness of a div containing various content

I am currently working with Bootstrap 4 and my HTML code looks like this:

<div class="font-weight-bold col-12">
  <span>Filter :</span>
  <input type="text" class="form-control" />
</div>

Initially, my output appears as shown below:

https://i.sstatic.net/A5EHz.png

However, when I decrease the browser size, the elements shift to appear like this:

https://i.sstatic.net/2ootv.png

Is there a way for me to ensure that both elements remain on the same line even after reducing the browser size?

Answer №1

Give this a try:

<div class="font-weight-bold col-lg-12 col-md-12 col-sm-12"> // utilize full width for large, medium, and small screens
  <span>Filter :</span>
  <input type="text" class="form-control" />
</div>

To learn more about the bootstrap grid system, click here.

Answer №2

Here are a couple of options you can consider:

1) Remove the "form-control" class from the input field and replace it with your own custom class. You can then define the width of the input field using CSS.

HTML

<input type="text" class="custom-input" />

CSS

.custom-input {
  width: 150px; // or any other desired width
}

2) Override the default CSS style of the element within a media query.

In Bootstrap's CSS, there might be a selector for "form-control" inside a media query that sets a specific width for the input field. You can create your own media query and selector to override this style.

3) Another option is to use both approaches mentioned above. Add a custom class to the input field like this:

<input type="text" class="form-control custom-input" />

Then adjust the width of the input field based on screen size using CSS.

If necessary, you can also apply !important to the width property to prevent it from being overridden by other styles when the screen size changes.

For instance:

.custom-input {
  width: 150px !important; // although not recommended, it can be effective
}

Answer №3

Here is an example of writing CSS for styling input elements:

input {
  width: calc(100% - 55px)
}

In the following HTML snippet, a label with a width of 55px is allocated for the input field to adjust its size accordingly:

<div class="font-weight-bold">
  <span>Filter :</span>
  <input type="text" class="form-control" />
</div>

This setup allows the input field to dynamically adjust its width based on the available screen space and the specified label width without relying on Bootstrap or any other framework.

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

What is the best way to ensure consistent spacing between columns in a Bootstrap 3 grid layout, similar to the spacing on the left and right sides?

Is there a way to achieve equal spacing between all blocks in a row, similar to the left and right padding that Bootstrap automatically applies? Currently, Bootstrap adds padding to all columns on both sides, but does not render extra spacing on the left s ...

Trouble with Bootstrap 5 Dropdown Functionality

Currently, I am using Bootstrap 5 in conjunction with Django to create a website and I'm encountering difficulties with getting a dropdown feature to work properly. Despite copying the code directly from w3schools, it fails to function when I load the ...

Go through each row in a table and retrieve the value of a column only if the checkbox

Is there a way to extract only the values in the serial column if the checkbox is checked for that row using jquery? I am currently able to retrieve the serial value, but unsure how to incorporate the checkbox condition. HTML: <table id="usersTable"&g ...

adjusting the width of an HTML table cell

I'm struggling with the code below: <table> <thead> <th class='1'>Date</th> <th class='2'>Start Time</th> <th class='3'>End Time </th> <th class='4 ...

What is the best way to preserve the allocated space in the DOM while utilizing CSS display:none?

I have explored the functionalities of display:none and visibility:hidden. However, I need to utilize display:none for a specific reason while still preserving the element's allocated space in the DOM to prevent any impact on adjacent elements. Is thi ...

Turn off the ability to drag on an HTML page

Need help with creating an HTML etch-a-sketch! I have a div container with multiple div elements inside it, all set up with CSS grid display. HTML structure: <div id="canvas"></div> To populate the canvas with div elements, I'v ...

Ensuring the container height remains consistent with fluctuating content dimensions

Imagine a container with content, where the container's width is fixed but its height adjusts based on its inner content. Initially, when the content causes the container to be a specific height, the challenge arises in shrinking the inner elements w ...

Tips for retrieving the user-input value from an HTML text field

Exploring the world of JS, I set out to create a basic calculator after just one week of lessons. However, I hit a roadblock when trying to extract user-input values from my HTML text fields. Here's a snippet of my html: <div class="conta ...

Placing a div over a JavaScript element

Is it feasible to overlay a div(1) with a background image on top of another div(2) that contains JavaScript (like Google maps API v3)? I have experimented with z-index without success, and I am unable to utilize absolute positioning because I depend on t ...

What is the reason for having a space between the <body> and the <html> tags?

Can you explain why there is a gap between the top of the green box and the browser window in Chrome and Firefox? I've tried various CSS configurations to eliminate the apparent space between the html and body elements, but it seems that some padding ...

Struggling with CSS due to the INCLUDE Function

After downloading a Template + CSS File for the website I am working on, everything was going smoothly until I decided to break down the template into separate files for easier modification and editing in the future. However, once I cut out the head sectio ...

Is there a way to lead to a password-protected page without making it accessible through the URL?

I'm currently honing my skills in web development and embarking on a project to create an interactive puzzle website. The premise is simple - the homepage will feature just an answer input field where users can enter the correct solution to progress t ...

What is the best way to design a content page with linked boxes to various arrays in PHP?

How can I create a PHP menu template that navigates to different pages? I am new to PHP and still learning. I want to achieve something similar to this image: https://i.stack.imgur.com/ylfe8.jpg I have the code for the navigation bar, but I need help crea ...

Tips for effectively utilizing the page-break property within CSS

I am faced with an issue on my HTML page where multiple angular material cards are being displayed: ... <mat-card class="mat-card-98"> <mat-card-header> <mat-card-title>THIS IS MY TITLE</mat-card-title> < ...

Placing an image above text in a table cell and making it hover

Is there a way to display an icon on the right-hand side of a table cell using jQuery? I want it to overlap the td contents if necessary. I've searched for solutions online but haven't found anything helpful yet. My main concern is styling rathe ...

What is the best way to locate and extract the content of an HTML element using XPath in Selenium with VBA?

I am currently seeking a solution to extract the content of an element with the name "data-testid" from a website. This specific element appears approximately 35 times within various contexts in the HTML code. The particular element I am interested in look ...

What is the best way to access the form button inside a div element?

Here is the code snippet for my form: <form accept-charset="utf-8" action="https:example.com" method="get" name="test"> <div class="classy"><input type="button" class="buttonE ...

Locate button elements with the class "button" that do not have any images inside them

Below is the code I am currently using for buttons (I prefer not to change it): <a href="#" class="button"> Button text <img src="someimage.png" /> </a> This CSS styled code creates a sleek button with an icon. To round the left sid ...

HTML form for selecting shipping method in PayPal

In my shopping cart setup, I offer two shipping methods: 'express' and 'standard'. I'm wondering if it's feasible to transmit this data to PayPal using HTML variables? ...

Troubleshooting Issue with Importing File into CSS Document

I'm currently working on building a website and I've been trying to import an image to use as the header. I want to add this .png picture to my CSS file, but despite extensive research and double checking everything, I still can't figure out ...