leveraging the bootstrap grid system for a responsive layout that positions an image beside a div

I am working on incorporating an image next to a div as seen in Facebook comments. Here is the HTML code I currently have:

  <div className="row">
      <div className="col-sm-1">
          <img
              className="img-thumbnail"
              src="image.jpg" />
      </div>
      <div className="col-sm-11">
          <div className="bg-light rounded p-1 pl-2">
              <span className="font-weight-bold text-primary">content</span>
              <div>
                  //buttons
              </div>
          </div>
      </div>
  </div>

However, I have noticed that there is some space left in the first div (col-sm-1) due to the smaller size of the image compared to the width allocated for the div. The issue can be visualized below. Does anyone have any suggestions on how to address this?

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

UPDATE

After attempting to use col-sm-auto, I realized that a space is always present from the right because of col-sm-11. This can be observed in the image provided:

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

Answer №1

If you want the column to shrink to the width of the content (in this case, the image), try using col-sm-auto instead of col-sm-1. Also, make sure to remove any left or right padding on the columns.

Check out this link for more information

<div class="container">
    <div class="row">
        <div class="col-sm-auto pr-0">
            <img class="img-thumbnail" src="//placehold.it/40">
        </div>
        <div class="col-sm-11 pl-0">
            <div class="bg-light rounded p-1 pl-2">
                <span class="font-weight-bold text-primary">content</span>
                <div>
                    //buttons
                </div>
            </div>
        </div>
    </div>
</div>

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

Guide on showcasing SQL information in HTML using AJAX and JQuery for a dynamic table display

I have some data stored in a SQL file and I'm looking to present it as a table in HTML using AJAX JQuery. Although the data is correctly retrieved when inspected, I am struggling with displaying it on my HTML page. This concept is new to me and I&apos ...

Guide on displaying a welcoming error notification within a Bootstrap modal form

How can I display an error message within a modal after clicking on the update button? In this example, I have included a required attribute on the input field. I would like to modify the error message based on recommendations from Form Validation Best Pr ...

When the page is fully loaded, I am trying to utilize jQuery with functions like $(window).ready(), but unfortunately, it does not seem to be functioning as expected

Utilizing jquery to dynamically adjust the content on my html page based on the page width. Upon the page being fully loaded (using the $(document).ready(function({\\there is some code here!}));), I aim to execute certain functions. My objectiv ...

Change the color of the icon from white to blue in png format using html/css

Changing a White Icon.png to a Blue Icon.png Using HTML/CSS The original icon.png is white in color. How can we change it to a blue color version using only HTML and CSS? HTML: <img src="icon.png" class="icon1"> CSS: .icon1 { background: url(ic ...

Arrange the table in alphabetical order and categorize it

Hello there! I am currently working on creating a well-organized table list where names are sorted into specific categories based on their starting letter. For example, names beginning with 'A' will be placed in the 'A category', while ...

`Iframe displaying silverlight content is experiencing technical difficulties`

Within an ASPX page, there is an iframe set up like this: <iframe id="mapFrame" name="mapFrame" src="project/visioMap.htm" frameborder="0" width="100%" height="900px" runat="server" /> The content inside the project directory is Web page material e ...

Modify the appearance of a Javascript file that is parsing data from a text file

I am working on an HTML project where I have a JavaScript file that reads from a text file. Currently, the text from the file is displaying in my HTML file, but I would like to style it using CSS. Can anyone provide guidance on how to achieve this? I am st ...

The function document.querySelector(".class h1")

I am currently updating my school's website and facing an issue with selecting header elements inside a div with the class "text" using the querySelector(String) function. I want to change the background, border, and text color of these headers, but t ...

Every time an input field is clicked, an email is sent

I'm struggling with the contact form on my website. Instead of sending an email after clicking on each input field, I want it to send only one email after hitting the submit button. Currently, it sends a total of 5 emails - 1 with user inputs and 4 wi ...

What is the best way to include a new line or HTML code in this particular JavaScript function?

I am attempting to create a typewriter effect and I have everything working except for creating new lines. I've tried using the following: \n \r <br /> but it just types those characters instead of creating a new line. Here is my j ...

Navigation menu with collapsible horizontal sub-menu display toggle

I have set up a test page using Bootstrap 4.3.1 to create a menu bar with submenus. The menu should display a triangle pointer when hovered over, indicating the selection. The user should be able to move the mouse to the submenu bar to choose a submenu. Wh ...

Facebook-Clone Chrome extension that automatically displays "User is listening to..."

I'm currently developing a Chrome Extension that will replace the chat input box with the music I'm listening to by simply pressing "´". It's worth noting that the chat is designed using react and does not use the traditional input/textarea ...

What is the best way to integrate my custom JavaScript code into my WordPress theme, specifically Understrap?

I am looking to enhance my website with a sticky navbar positioned directly under the header, and I want it to stick to the top of the page as users scroll down. Additionally, I want the header to disappear smoothly as the user scrolls towards the navbar. ...

Why is there an excessive amount of white space on my Reactjs page?

This webpage (page URL -) displays well without any white space between two images when viewed on a laptop. However, when accessed on a mobile device, it appears to be taking up too much space as shown in the image below. Image of webpage on laptop- lapto ...

Angular Validators are behaving inconsistently, as they only work intermittently before stopping altogether once the application is

Why does my code sometimes behave differently after running for a while and then return to normal after restarting the Angular server without making any changes?The pop-up that says "please fill out this field" disappears when it shouldn't This is th ...

How to handle users with disabled Javascript? Considering redirection to alternate sites for users with script disabled?

I've dedicated today to strategizing the best approach for revamping our company's website, taking into consideration that less than 1% of web users have JavaScript disabled. Our management team strongly believes in ensuring that our website rem ...

What could be causing the audio to not function properly on the webpage I'm working on that has yet to be launched?

As I work on my webpage, I am attempting to incorporate an audio file from SoundCloud. However, it seems that the file is not playing when sourced directly from the SoundCloud website. It works fine when the source is a file stored on my computer. <aud ...

What is the best way to align child elements on the opposite side of their parent using flexbox in CSS?

I'm currently designing the header for a website project. I have my logo positioned on the right side, and I want to place the search bar on the left side. To achieve this layout, I am utilizing flexbox in CSS. I've experimented with various app ...

The collapse feature of a Bootstrap 4 checkbox within a list-group-item is not working properly

Having trouble with a bootstrap 4 list-group-item and collapse function interaction. The issue is that a checkbox within the list-group-item activates the collapse function when clicked, but it doesn't respond to being selected/unselected properly. ...

Tips on changing the selected option in a select element with the selectpicker plugin from bootstrap

Recently, I integrated the Bootstrap-Select plugin into my project and utilized it as shown below: HTML: <select name="selPopulation" class="selectpicker"> <option value="1">City 1</option> <option value="2">City 2</optio ...