Modifying the image width in Bootstrap: A step-by-step guide

When the screen is lg or larger, I would like my image to be full width (w-100), and when the screen is md or smaller, I want it to be half width (w-50).

<div>
        <div class="container">
            <div class="row">
                <div class="col-md-10 offset-md-1 order-md-2"><img src='image.png' class="w-100 w-md-50"> 
                </div>                
            </div>
        </div>
</div>

Is there a Bootstrap class that can specify different widths for different screen sizes? I tried using w-md-5 similar to offset-md-1, but it didn't work.

Answer №1

Bootstrap 4 doesn't seem to offer width utilities based on breakpoints, only as a general setting (w-25, w-50, etc.).

If you need more customized width options, you can define your own styles like this:

@media (min-width:768px) {
    .w-md-50 {
        width: 50% !important;
    }
}

Answer №2

https://example.com/docs/layout/grid/

I haven't personally verified it, but you could potentially attempt to reverse the process -

<img src='image.jpg' class="w-50 w-md-100">

Meaning that w-50 would apply from extra small up to medium screens, while w-md-100 would take effect from medium size screens (768px) and larger.

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

Prevent the row height from fluctuating following the fadeOut() effect

Currently, I am facing an issue with two elements on my page: .start_over_button and .speed_buttons. In CSS, the .start_over_button is set to display: none, and in my JavaScript code, I have it so that when .speed_buttons are clicked, they fade out and the ...

What is the best way to update a stylesheet dynamically within an Angular project?

I have been attempting to modify my bootstrap.css file in order to change the theme of my application: $scope.changeStyle = function (style) { $scope.myStyle = style + '/bootstrap.min.css'; $scope.$apply(); } The 'myStyle' ele ...

Implementing CSS transitions across several elements simultaneously can enhance the user experience

There seems to be an issue with animating two elements simultaneously using max-height. The transition always occurs one after the other, with one element completing its transition before the other starts. setTimeout(function () { $(".b").css( ...

Using javascript, jquery, and html to direct to html pages

Hello everyone, I'm currently facing a challenge with my assignment which involves creating a table that has options for editing and deleting words. When the 'delete' option is clicked, an alert should pop up asking "Are you sure you want t ...

Modify the child element to hide overflow-x

Looking for a solution with my wrapper class that has specific CSS properties as follows: #wrapper { margin-left: -320px; left: 350px; width: 300px; position: fixed; overflow-y: scroll; overflow-x:hidden; top: 60px; bottom: 10px; transit ...

Adjusting the line height of an inline-block div causes surrounding inline-block siblings to shift downward

As I venture into exploring the line-height property, I came across information on MDN which stated: For non-replaced inline elements, it determines the height used in calculating the line box height. However, in this scenario, when I set the line-heigh ...

Implementing the disabled style for an ASP.net dropdownlist

Imagine I have an ASP.net dropdownlist set up like this: <asp:DropDownList ID="ddOwnershipDocumentType" class="msbdd" runat="server"> </asp:DropDownList> Let's take a look at the style definition for msdbdd: .msbdd { font-family: WM ...

jquery code to count the number of children in an html table

I'm struggling to grasp the behavior of the jquery method children. I can successfully count the number of <p> elements within a <div> using the following code: var abc = $("div").children("p"); alert(abc.length); However, when I a ...

Aligning an SVG within a container div

I am trying to display an SVG image inside a fixed-position div. Here is the HTML: <div class="main"> <svg class="svg" viewBox="0 0 180 100"> <rect height="100%" width="100%" fill="#003300"></rect> </svg> </div> ...

Is there a way to automatically close a created div by clicking anywhere outside of it?

I'm facing an issue with a dynamically created div that I want to close by clicking outside of it. However, when I try to achieve this functionality, the div closes immediately as soon as it is opened. closediv(); } function closediv() { d ...

As jQuery animates, the navigation bar gracefully descends

I've been immersing myself in learning HTML, CSS, and jQuery for the past ten days. Building my first website has been a fun challenge, allowing me to experiment with different elements. One of my recent experiments involved creating an animation for ...

Mastering Ajax: Frustrating issues with loading dynamic content

I recently started learning Ajax for a project, but I've run into some issues. Here's where I'm at so far: 1- I have a navigation bar with various buttons that are meant to display content. 2- There's a container div where the selecte ...

Don't forget to preserve the hover state of divs even after refreshing

I recently added a navigation bar that expands in width upon hovering over it. For an illustration, check out this example: http://jsfiddle.net/Gsj27/822/ However, I encountered an issue when clicking on a button within the hover effect area. After load ...

When trying to load a php page2 into page1 via ajax, the Javascript code fails to execute

Currently, I am in the process of learning PHP and JavaScript. I have encountered a particular issue with a webpage setup. Let's say I have a page called page1 which consists of two input fields and a button labeled 'Go'. Upon clicking the & ...

Challenges with Implementing Background Images on my Website with HTML and CSS

Being new to the world of coding, I recently created a website for a college presentation. However, after uploading the website onto the internet, I noticed that the background images from my files are not displaying on the website. It's likely that I ...

Sorting of tables does not function properly following an ajax request

I built a table that utilizes an AJAX response triggered by selecting a date from a drop-down menu. <!--datepicker--> <div class="col-md-4"> <input type="text" name="date_po_month_picker" id="date_po_month_picker" class ...

Use vertical gaps to separate items by applying the following technique:

One of my components is designed to act as a badge. The CSS for this component includes: https://i.sstatic.net/F0QZ6.png HTML: <div class="label label-as-badge"> {{ value.Termo }} <i class="fa fa-times"></i ...

What is the best way to incorporate an options tabbed menu into a mega drop-down menu?

I came across a useful code snippet on The code snippet offers users a choice of 3 options with tabbed menus. Take a look at the website to see how this tabbed menu functions. Here is the code for this snippet <div class="row-fluid"> <div ...

What is the best way to create a full-width gallery display?

I've been having some trouble making my image gallery full-width at any resolution. Oddly enough, the gallery only goes full screen when I click on the maximize button in the browser window. I can't seem to figure out what the issue is so far. ...

What is the best way to store objects in files using Node.js?

As I manage my Node server, a question arises - what is the best way to convert objects into a serialized format and save them to a file? ...