Adjust the size of bootstrap buttons based on the width of the screen

Is there a way to dynamically change the size and number of columns a bootstrap button spans based on the screen width? I have figured out how to adjust the number of columns, but changing the size (from btn-xs to btn-lg) is posing a challenge. Is it possible to inherit a class and then apply a media query for this purpose?


@media only screen and (orientation: landscape) and (max-width:1024px) {

.my-button{
.btn-lg
    }    

}

Answer №1

Utilize selective display options from Bootstrap for better responsiveness:

<div class="d-block d-sm-none">
    <div>
        <button class="btn-xs">Click Here</button>
    </div>
</div>

This code snippet will only show the button on extra small screens. For more display combinations, visit https://getbootstrap.com/docs/4.0/utilities/display/.

Answer №2

Instead of using .btn-lg and .btn-sm classes, try adding padding with p-2 and adjusting the font size based on screen size using media queries.

Answer №3

Have you considered utilizing vh/vw units for your button text's font-size, since the button size adjusts with the text's font size?

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

Adding a CSS class to an HTML element using JQuery

I have a collection of tabs, and I want to dynamically add an <hr> element with the class "break-sec" when a certain class is active. This element should be placed within a <span> element with the class "vc_tta-title-text" after the text. Here ...

How can I customize the appearance of a disabled radio button within spans?

While attempting to make my radio button square using CSS by incorporating spans and before and after elements, I encountered a new client request. The client now wants the radio buttons to be disabled with a unique style when in this state. Unfortunately, ...

Using unicode characters to style your Angular application

Hey there! I have an Angular 5 app on StackBlitz that implements table sorting. You can check it out here: https://stackblitz.com/edit/angular-rxdzom. The code for this app is based on the example from . In the app, I've used a stylesheet at ./app/sor ...

Tips for deleting all content within a designated html tag (including the tag itself)

Imagine you are dealing with a string like this: text = """<p>Bla bla bla.</p><p>Blo blo blo<a href="http://www.example.com">bli bli</a>.</p><p>blu blu<br> <span style="font-size: x-small;"><br> ...

Unusual problem encountered with Chart.js bar chart, image dispersion

On my HTML page, I have integrated a stacked bar chart using the Chart.js library to visually represent data for users. The data changes based on user selection, and the JavaScript function that enables this onclick feature is: function aggLav(){ [... ...

Align the emoji in the center of the absolute div horizontally

I'm currently working on a project involving placing emojis at different coordinates within a webpage. At times, the emoji is larger than its container. For instance, here is an example of HTML code that positions a house with a font size of 100px ins ...

jquery event for horizontal scrolling - Update

Hello, I am working on a project with a horizontally scrolling gallery and I would like to add dynamic captions that toggle on and off as the user scrolls past each image. The captions are currently static on the page. Here is a mock-up of the page: htt ...

Create a dynamic feature that allows users to easily add text fields within a form in

I'm looking to create a form that adds another input text field automatically when the user fills out one. Here is an example of the HTML structure: <form method="post" action="http://localhost/save" class="save"> <fieldset> <div&g ...

Updating the material-ui checkbox state to reflect the checked, unchecked, or indeterminate status, can be achieved in reactjs without relying on state

I am currently using Material-UI checkbox components and I have a requirement to programmatically change the state of checkboxes to be checked, unchecked, or indeterminate based on the click of another checkbox. This action needs to be applied to a list of ...

Ensuring the positioning of input fields and buttons are in perfect alignment

I've been struggling to align two buttons next to an input field, but every time I try, I end up messing everything up. I managed to align an input field with a single button, but adding a second button is proving to be quite difficult. Here is ...

Shift visual elements using measurements

Let's say my image size is 960x960, but the height of the img element is set to 720px. <img class="imgs" src="~/test.jpg" /> Here are the styles for .imgs: .imgs { width: 100%; height: 45rem; object-fit: cover; } ...

HTML / CSS: Ellipsis is Failing to Show

I'm trying to implement ellipsis on my website but the following HTML / CSS code isn't working as expected. CSS: .oneline { text-overflow:ellipsis; white-space: nowrap; width: 50px; overflow: hidden; } HTML: <div class="oneline">Testing ...

Styling with CSS to create a visual countdown display

I'm trying to replicate the format shown in the image below. https://i.sstatic.net/lnW2C.png Currently, this is the code I have: https://codepen.io/Brite1/pen/wvPrggj (it seems like I just need to adjust spacing and center all numbers/text). I'm ...

Material UI categorizing iPads with a width of 768px and a height of 1024px as belonging to the small

I am facing a challenge with the layout of my app on different screen sizes. To address this issue, I am utilizing Material UI's breakpoints to control the layout based on the screen size. According to the documentation, screens categorized as small ...

Combining the Powers of Magento and Wordpress: Can I manually edit a page or the CSS?

I am currently faced with the challenge of editing a webpage that was not originally created by me. I have been tasked with understanding someone else's code in order to make alterations. Specifically, I am attempting to change the font color on the h ...

Is it possible to adjust the left property following the concealment of an element with JQuery?

My goal is to move an image element using the 'left' property after hiding a div. To achieve this, I am using JQuery's '.promise()' function. Here is my code: HTML code: <div id="outerContainer"> <div id=" ...

A continuous loop of text is displayed in a slideshow format, with different image files used for the navigation buttons "back", "stop", and "forward"

I am in need of a unique slide show that displays text exclusively attached to CSS, with image files for the navigation buttons. I have been searching for days without success, as most options available are for image slideshows and not suitable for my text ...

Issue with window.localStorage.setItem not functioning properly on mobile devices

Currently, I am developing an HTML5 mobile application with jQuery Mobile. Below is a snippet of my code: $(document).on("click","#send_mobile_number",function(){ var mobile = $('#mobile_number').val(); var user_id = sessionStorage.get ...

I am experiencing issues with React Bootstrap's responsive mode not functioning as desired

As a new developer for bootstrap, I created a product that collapses automatically from either the right or left side of Chrome in a responsive manner. However, when I manually choose an absolute width using the inspect tool, it does not display the same a ...

Position the vertical bar directly adjacent to the form input field

Looking for assistance with creating a unique webpage layout that includes a form where the employee ID is visually separated from the rest of the content by a vertical bar extending across the entire page. However, my attempts to achieve this using a gr ...