How to position image to the right of a Bootstrap list-group

I'm struggling with getting the image to fill from top to bottom on the right side of the list-group. Despite several CSS overrides in my style section, I can't seem to figure out what I'm missing. Should I set a fixed height and width, or is there another way to have it fill the specified list height?

The attached image displays the current alignment issue, where it seems to be positioned below the label.

Some lists will already drop to the line below.

https://i.sstatic.net/IophU.jpg

    <style> 

// CSS styles here

</style>

HTML:

<a href="#acet" class="list-group-item" data-toggle="collapse" style="background-color: lightyellow;">
        <div class="checkbox">
            <label style="font-size: 1.5em">
             ACETAMINOPHEN
            </label>
            <div class="MyDrugPix" style="padding-right: 0px;"><img src="/images/IMG_0741.JPG" alt="DRUGS" class="img-responsive"></div>
        </div>
    </a>

Answer №1

If you're looking for a solution using only CSS, here's an approach to tackle your issue.

To start off, I've set the width of the div with the class checkbox to 100%.

Next, I've made the image div have a display:inline-block property so that it doesn't span the entire width. Then, I positioned it to the right using float:right;. However, this might cause the parent element to ignore the height of the elements inside it, so I've included a clearfix technique. You can learn more about clearfix here.

CSS:

.MyDrugPix {
  padding-right: 0px;
  display: inline-block;
  float: right;
}

.checkbox {
  width: 100%;
}

Clearfix:

.clearfix:after {
  visibility: hidden;
  display: block;
  font-size: 0;
  content: " ";
  clear: both;
  height: 0;
}

* html .clearfix {
  zoom: 1;
}


/* IE6 */

*:first-child+html .clearfix {
  zoom: 1;
}

.checkbox label:after,
.radio label:after {
  content: '';
  display: table;
  clear: both;
}

.checkbox .cr,
.radio .cr {
  position: relative;
  display: inline-block;
  border: 1px solid #a9a9a9;
  border-radius: .25em;
  width: 1.3em;
  height: 1.3em;
  float: left;
  margin-right: .5em;
}

.radio .cr {
  border-radius: 50%;
}

.checkbox .cr .cr-icon,
.radio .cr .cr-icon {
  position: absolute;
  font-size: .8em;
  line-height: 0;
  top: 50%;
  left: 20%;
}

.radio .cr .cr-icon {
  margin-left: 0.04em;
}


/*My changes*/

.MyDrugPix {
  padding-right: 0px;
  display: inline-block;
  float: right;
}

.checkbox {
  width: 100%;
}

/*Clearfix for floating elements*/

.clearfix:after {
  visibility: hidden;
  display: block;
  font-size: 0;
  content: " ";
  clear: both;
  height: 0;
}

* html .clearfix {
  zoom: 1;
}


/* IE6 */

*:first-child+html .clearfix {
  zoom: 1;
}


/* IE7 */
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<a href="#acet" class="list-group-item" data-toggle="collapse" style="background-color: lightyellow;">
  <div class="checkbox clearfix">
    <label style="font-size: 1.5em">
             ACETAMINOPHEN
            </label>
    <div class="MyDrugPix"><img src="http://via.placeholder.com/50x50" alt="DRUGS" class="img-responsive"></div>
  </div>
</a>

If you are open to trying out a CSS3 solution, you can achieve the same result by setting just 3 properties!

CSS3

.checkbox {
  display: flex !important;
  justify-content: space-between;
  align-items: center;
} 

.checkbox label:after,
.radio label:after {
  content: '';
  display: table;
  clear: both;
}

.checkbox .cr,
.radio .cr {
  position: relative;
  display: inline-block;
  border: 1px solid #a9a9a9;
  border-radius: .25em;
  width: 1.3em;
  height: 1.3em;
  float: left;
  margin-right: .5em;
}

.radio .cr {
  border-radius: 50%;
}

.checkbox .cr .cr-icon,
.radio .cr .cr-icon {
  position: absolute;
  font-size: .8em;
  line-height: 0;
  top: 50%;
  left: 20%;
}

.radio .cr .cr-icon {
  margin-left: 0.04em;

}

.checkbox {
  display: flex !important;
  justify-content: space-between;
  align-items: center;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<a href="#acet" class="list-group-item" data-toggle="collapse" style="background-color: lightyellow;">
  <div class="checkbox">
    <label style="font-size: 1.5em">
             ACETAMINOPHEN
            </label>
    <div class="MyDrugPix" style="padding-right: 0px;"><img src="http://via.placeholder.com/50x50" alt="DRUGS" class="img-responsive"></div>
  </div>
</a>

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

Press the "show additional content" button on the nytimes.com website using selenium

I'm experiencing difficulty scrolling through this webpage. Once I reach the bottom of the page, I am unable to locate and click on the "SHOW MORE" button using selenium. self.driver.execute_script("window.scrollTo(0, document.body.scrollHeight);") ...

Having trouble accessing the value of an item in a dropdown box on a website

I am currently developing a webpage using HTML5 and Knockout Js. I am facing an issue where I am unable to retrieve the ID of the selected item from a dropdown box in order to insert a value into an SQL table. As an example, consider the following SQL tab ...

Bootstrap grid. Instead of moving to the next row, scroll horizontally when the content overflows

Here is the code snippet: <div class="row shochatgroup"> <div *ngFor="let message of messages" class="col-auto"> <button *ngIf="message.state.attributes.shochatpaid > 0 && message.state.at ...

Row in Internet Explorer 7

I have a function that reveals hidden rows in a table, which works perfectly in all tested browsers except for IE7. The function is written using Prototype.js. function showInactives(){ var row_list = $$('tr.inactive'); var ck =$('inactive_ ...

The HTML element does not expand to fill the entire page

I recently encountered a problem with my website. Everything was functioning smoothly until I decided to add some in-page links to a large page. After adding the links, the background no longer stretched the entire length of the page. When scrolling down, ...

Struggle with typescript integration with emotion and styled components

Issue Description: I encountered an issue while working with typescript and emotion/styled libraries. When attempting to specify the type of the parent component that wraps a styled component, I faced difficulties. The scenario involves a parent componen ...

Attempting to use window.open on a button created using jQuery will not yield the desired result

My webpage currently has the following HTML code loaded into a div: <style> #site h1{ margin: 1em 0; padding: 0; width: 100%; display: inline-block; font-size: 2em; } #site h2 { margin: 0; ...

The complexities of stopPropagation() causing further confusion

I have encountered an issue with my code. It currently allows a dropdown functionality for a <ul> element, but when a child <li> is clicked, it also closes other menus of the same type. To fix this, I used an if clause to check if the clicked ...

Searching for the precise draggable grid line position in rulerguides.js - tips and tricks!

Currently, I am utilizing rulerguides.js in my project. I have customized it for a specific div to display rulers and grid lines. You can refer to this FIDDLE. The rulers are functioning properly, but the draggable grid lines are being calculated based on ...

The radio button's size adjusts based on zooming in or out in Firefox

I'm facing an issue where the radio buttons on my HTML page change sizes when zooming in or out on Firefox only (this doesn't happen in Chrome). At the default size of 100%, they look like this. When the page is zoomed in beyond 100%, the radio ...

The FILE input type in HTML forms is not functioning properly on Safari Version 14.0.1 (14610.2.11.51.10)

After much testing and research, I have found a solution to the issue at hand. By adding the "accept=" option to the HTML code, the problem of not being able to submit files through HTML forms in Safari has been resolved. However, it is important to note t ...

HTML 5 Video VTT File: A must-have for optimal video playback

Having trouble getting the subtitle.vtt file to load on Chrome with this code. Can anyone offer any insights? <div id="videoKilledTheRadioStar"> <video id="Tutorial" width="420" autoplay controls> <source src="videos/shaco.mp4" type="vi ...

Creating MySQL inserts from various dynamic HTML tables generated using PHP

Currently, I am faced with a challenge while working on a PHP file that produces multiple dynamic HTML tables through the use of an included PHP library. To provide a glimpse, here is a snippet of the HTML output (with just two tables and reduced rows) ava ...

HTML: Hover effect does not work for icons when hovered alongside anchor elements within a list item

I wanted to add a special effect to my navigation list items: When the mouse hovers over the anchor tags of the list items (or even in the active state), I wanted the image in the <span> to be replaced with a colored version of the image. The color o ...

Employing an odd/even toggle for assigning class names

I need each this.state.title to be aligned based on a different classname. I attempted using css flex boxes/nth-of-type/nth-child, but it didn't work well with React. I'm utilizing this.state to access my objects. My failed strategy render: f ...

Expandable Bootstrap collapse and accordion open horizontally, not vertically

I want to use Bootstrap collapse but I want to keep my div-s with the content beneath each link, mainly because that's how i need it to work on mobile (the menu is a column and that the content opens under each link). Unfortunately, on website I have ...

Bottom-aligned footer that remains in place instead of sticking to the page

I am attempting to position a footer at the bottom of the page, without it being sticky. Instead, I want it to remain at the bottom in case the user scrolls down there. Although it technically "works," there appears to be some white space below the footer ...

"Create a responsive mobile navigation bar that stretches to 100% of the window height,

I've encountered an issue with the mobile version of my website. When users scroll to view content, clicking on an icon triggers a slide-in navigation bar from the left side and sets the body to have overflow: hidden;, effectively preventing further s ...

How come jQuery won't let me activate the 'change' event on a radio button?

Click the link below to access the page: Below are the original javascript codes that are functioning correctly: $(document).ready(function(){ $(".open_gene").on('change', function(event) { $('#Gene_field').show(); }); ...

What is the best placement for video content in a website development project?

Storing images in a folder named images is recommended for better website organization and SEO benefits. But what about local video content? Should it go in a folder labeled videos? ...