Position the div so that it is aligned with the right edge of the

I'm attempting to create a button (div with background color) positioned just below an image that aligns with the right side of the image. Both elements are contained within a wrapper div. When I float the button to the right, it causes the wrapper div to expand and the button extends beyond the right edge of the image. It is not possible to set a fixed width for the wrapper div as it needs to be responsive.

Here's what I currently have:

<div class="col-xs-6">

   <div class="wrapper">

      <h2>Title</h2>

      <img class="responsive">

      <div class="button"></div>

   </div>

</div>


.button {
  float: right;
 }

Essentially, how can I make the wrapper div match the width of the image? Or is there another method to align the button div with the right edge of the image?

The image occupies about 70% of the width of the col-xs-6 div, and I cannot make it fill the entire div as there is another image next to it with spacing between them.

Note: Bootstrap is being used for responsiveness.

Answer №1

.container{text-align:right;}
.adaptive{width:100%; height:auto}

Also, if you require the h2 heading to be aligned in another way, you can modify it using h2{text-align:center}

Answer №2

When using Bootstrap, you can achieve this layout by following this code:

<div class="col-xs-6">
    <img src="img/image.jpg" class="img-responsive" alt="some text" />
    <button type="button" class="btn btn-default pull-right">some text</button>
</div>

Note: I have corrected the button element in the provided code.

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

Preventing further onClick events from occurring ensures that any new onClick events will not be triggered as well. To achieve

In the process of developing a script, I've encountered a situation where the original developers may have implemented event prevention or some other mechanism to block any additional clicks on certain table td elements. Even though their click trigge ...

Prevent past date and time selection in "date" text-box mode using ASP.NET

Is there a way to prevent users from selecting past dates and times in a textbox with TextMode set to DateTime? I was able to achieve this using a calendar control, but my specific requirement is to implement it only within the textbox itself. protected ...

Showing the number of times a button has been pressed

I have written some HTML code to create a button and now I am looking for guidance on how I can use Vue.js to track how many times the button has been clicked. Here is what I have so far: <div class="123"> <button id = "Abutton&q ...

Creating a central navbar brand with a collapsing feature using Bootstrap 4

Struggling with Bootstrap 4 Alpha 6 I'm having trouble getting both the right links and left link to collapse when using Bootstrap. Currently, only the right-hand side link collapses while the left link remains unchanged. <nav id="topNav" class=" ...

I am unable to move HTML data to PHP

Here is my HTML code: <form action="test.php" method="get> <input type="text" name="text" /> </form> And this is my PHP code: <html> <head> <title>Result</title> </head> <body style="background: ...

Displaying various images within a bootstrap modal window

I'm facing an issue with my gallery. It contains small images, and when a user clicks on a thumbnail, a modal should open with the full-size image. The problem is that even though I have the full-size images stored in the "/uploads/" folder and the th ...

Styling tip: Distance the tooltip from its parent element when scrolling through a list

I have a table inside li tag, and I want to display the description on :hover inside td. However, when scrolling through the list, the description content starts to appear with a distance from its parent. Despite trying various combinations of position se ...

Chrome leak when rounded border in `overflow:hidden` parent is exceeded

Even with a rounded parent element, the hidden part of a child element continues to appear in Chrome: In Internet Explorer, adding the CSS property z-index to the parent element can solve this issue. However, this solution does not work in Chrome. #con ...

Extract the td elements from a table with specific class using the DataTable plugin

I stumbled upon this snippet of code while browsing through the DataTable website. var table = $('#example').DataTable(); table.column(0).data().each(function(value, index) { console.log('Data in index: ' + index + ' is: &apos ...

Is there a way to adjust the margin for a child DIV element using CSS?

Currently, I am working on my website located at www.buildinghunter.com. On the homepage, there are four div elements positioned in the bottom left corner of the page. I am attempting to align two specific divs (id=text-9 and id=text-10) with the other tw ...

What is the best way to set a single column to have a fixed position when scrolling horizontally?

There is an inline form that extends both horizontally and vertically. Within this form, there is a final column containing an add button which I would like to have a fixed position only when scrolling horizontally, not vertically. <!doctype html> &l ...

Suggestions on how to refactor redundant code in various peer AngularJS controllers for handling $intervals

In my compact single-page application, I have implemented multiple tabs to display operational status information for different applications. Each tab is associated with a controller that creates $interval objects to make AJAX calls to fetch status data fr ...

The use of Material-UI collapse animation in a table results in the insertion of div elements, triggering a validateDOMNesting warning

Having a data-filled table, I am looking to implement smooth transitions when adding or deleting an item. This is a ReactJS project utilizing Material-UI. The desired effect is similar to the one demonstrated in their example. While they use a List compon ...

Ways to adjust the location of the scrollbar using CSS

Can the position of the scroll bar be modified using CSS to switch it from left to right or from bottom to top? ...

What is the method to apply custom styles (CSS) to individual options within a jQuery UI selectmenu?

When working with an HTML form that includes a select element, I encountered a design challenge. <select id='myselect'> <option value='1'>1</option> <option value='2'>2</option> ... <option va ...

The stretched-link is dysfunctional when combined with its parent CSS transform: translate

When using Bootstrap 5, there seems to be an issue with the .stretched-link class not working properly on elements that have a CSS transform translate applied to them. How can this problem be addressed? .btn { transform: translate(0,0); } <link hre ...

XML powered jQuery menu

Admittedly, I have not yet used XML with jQuery. Below is a snippet of the XML: <folder title="Home"> <item title="Welcome" /> <folder title="My Photos"> <folder title="Holiday"> <item title="Photo 1" /> ...

What is the method for incorporating <style> in CSS code?

I am interested in creating a separate CSS stylesheet for my code. How can I accomplish this task? Here is the code that I would like to transfer: <style> body{color:red;} </style> ...

Troubleshooting the ModelState.IsValid issue while editing user data and saving changes

Need to make updates to user details such as Firstname, Lastname, and date-of-birth. Even though the ModelState is valid, encountering issues with the SaveChanges function not working. It seems that there are some errors related to the password and email f ...

The media query was running smoothly until it unexpectedly stopped functioning

I've encountered an issue where something that used to work perfectly fine suddenly stopped working :( @media only screen and (max-width: 768px) { form, button, input { width: 80vw !important; } } <meta name="viewport" content="width=de ...