Bootstrap 4: Inline Button with Full Width Styling

Although the title may seem misleading, I struggled to come up with a better one. What I need is to have an image aligned with text within a div, and a button below that text. However, I'm facing difficulty in making the button take up the full width without adding any padding regardless of what I attempt.

To provide a clearer explanation, here's an illustration of what I'm aiming for:

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

I am attempting to achieve this using only Bootstrap 4 utilities. Here is my code progress so far:

.col-md-3 {
  background-color: #ededed;
}
.img {
  width: 188px;
  height: 88px;
  background-color: #292a2c;
}
.btn {
  background-color: #292a2c;
  color: #ededed;
}
<div class="col-md-3 d-flex p-0">
  <div class="img"></div>
    <div>
      <h6 class="m-auto">Text goes here</h6>
      <button class="btn rounded-0 btn-block">Button</button>
    </div>
</div>

How can I resolve this issue? Also, note that the .img class div serves as a placeholder and must remain as it is.

Thank you!

Answer №1

To easily achieve this layout, utilize the bootstrap media object without any extra css needed. Refer to the code snippet below for implementation:

<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container-fluid">
  <div class="row">
    <div class="col-12">
      <div class="media">
        <img src="https://via.placeholder.com/188x88" class="mr-3" alt="">
        <div class="media-body">
          <h5 class="mt-0">Media heading</h5>
          <button class="btn btn-primary btn-block">Button</button>
        </div>
      </div>
    </div>
  </div>
</div>

Answer №2

If you're looking to create a layout similar to this, you can start with the following structure and then customize it as needed:

<div class="container-fluid">
  <div class="row">
    <div class="col-4">
      <img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ79Qe630Fli9-SIDz188GQURmrRfhh6AksMKexPP5JvsE7AJ6t01mf5A">
    </div>
    <div class="col-8">
      <div class="row">
        <p>text</p>
      </div>
      <div class="row">
        <button>button</button>
      </div>
    </div>
  </div>
</div>

Answer №3

Below is the code snippet to achieve the layout displayed in the image:

'<div class="col-md-12"><div class="row"><div class="col-md-3"><div class="row"><div class="img"></div></div></div>
<div class="col-md-6"><div class="row">
 <h6 class="m-auto">Text goes here</h6><button class="btn rounded-0 btn-block">Button</button></div></div></div>

To apply styling, use the CSS provided in your question.

Answer №4

Here is a solution you can try out.

Keep in mind that Bootstrap doesn't come with a black background class, so you'll need to define one.

.bg-black {
  background-color: #000 !important;
  border: 2px solid #000 !important;
 }
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet"/>


<div class="container-fluid">      <!-- Make it full width -->
  <div class="row d-flex">         <!-- display flex -->
    <div class="col-4 align-self-stretch">      <!-- stretch the column -->
      <img class="w-100" src="http://placehold.it/200x200" />
    </div>
    <div class="col-8 align-self-stretch">      <!-- stretch the column -->
      <p>Some Text Here.<br/> Can be long or short</p>
      <p>Yet another paragraph</p>
      <p>And one more paragraph</p>
      <button class="btn btn-primary bg-black btn-block rounded-0">Btn Txt</button>
    </div>
  </div>
</div>


<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js"></script>

Answer №5

   .col-md-3 {
      background-color: #f1f1f1;
      width:100% !important;
      
    }
    
   .col-md-3> div{
    display:inline-block;
    float:left;
     width: 60%;
     height:100%;
    }
    .img {
      width: 15% !important;   
      height: 80px !important;
      background-color: #333333;
      display:inline-block;
    }
    
    .btn {
      width: 60%;
      background-color: #333333;
      color: #f1f1f1;
      height:50%;
      display:inline-block;
    }
<div class="col-md-3 d-flex p-0">
  <div class="img"></div>
    <div>
      <h6 class="m-auto">Custom text here</h6>
      <button class="btn rounded-0 btn-block">Click Here</button>
    </div>
</div>

Answer №6

Ensure that the bootstrap.css file is correctly located and functioning properly in your project.

I have made some edits to your code, although it is a bit hardcoded. Be cautious not to directly modify bootstrap classes when making changes.

.box {
  background-color: #ededed;
}
.img {
  width: 188px;
  height: 88px;
  background-color: #292a2c;
  float: left;
  margin-right: 5px;
}
.text {
  float: left;
}
.btn {
  background-color: #292a2c;
  color: #ededed;
  margin-top: 33px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet"/>
<div class="col-md-6 d-flex p-0">
  <div class="box">
    <div class="img"></div>
    <div class="text">
      <h6 class="m-auto">Text goes here</h6>
      <button class="btn rounded-0 btn-block">Button</button>
    </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

A guide on incorporating Bootstrap 5 into Nuxt.js

Initially, my attempt to incorporate bootstrap-vue was unsuccessful as it only supports bootstrap 4 and vue2. Now, I am pursuing the integration of bootstrap 5 without making any modifications by following these steps: To begin, I will install the bootstr ...

Unable to activate slideToggle due to malfunctioning links

When using the slideToggle function, I encountered an issue where the links are not functioning properly. Check out my demo site at the following link: Here is my script: $(".nav li > a").click(function(e) { $(this).parent().siblings().find(&a ...

The JSON is not displaying in the expected sequence

I am currently working with a json file named places.json which contains data on various cities around the world. Here is a snippet of the file: { "Europe": [ { "name": "London", "country": "England" }, ...

Obtaining data from console.log and showcasing it within a div element

Currently, I am facing a challenge where I want to retrieve the title, plot, and poster using the themoviedb API. However, I am lost on how to begin coding this. Whenever I perform a search, the information is displayed in the console log of the browser. ...

A guide on effectively selecting an element with the '@font-face' tag

I'm endeavoring to design a distinctive logo by utilizing a personalized font... and am keen on incorporating it into my CSS As an illustration: the identifier for my div element is "logo" Should I merely employ this code? #logo { font-family: ...

Tips for eliminating gaps between form fields when utilizing Bootstrap Flask's render_form_row function

Is there a way to incorporate the "no-gutters" style when using the render_form_row function in bootstrap-flask? Check this link for more information I attempted the following code but it didn't yield the desired result: {{ render_form_row([form.var ...

Eliminate styling that is specific to certain browsers

Recent browser updates have introduced new styling and functionality to input[type=number], including up and down buttons. In Chrome, I was able to eliminate this added styling by accessing the shadow DOM and identifying the specific element. However, de ...

Using Selenium to locate and click on a hyperlink within a table by identifying it with its displayed name

In my case, I have a table that displays records of school districts. My goal is to use Selenium in order to select the delete icon positioned in the eighth td for the district located on a row with a specific name. In this scenario, the name being QA__run ...

Validation of forms - Must include one particular word from a given set

I am in the process of utilizing Javascript to validate an input field with the specific formatting requirements outlined below: "WORD1,WORD2" The input must contain a comma separating two words, without any spaces. The first word (WORD1) can be any word ...

Is there an issue with the JavaScript functionality of the max/min button?

Help needed with maximize/minimize button functionality as my JavaScript code is not working. Any suggestions for a solution would be greatly appreciated. Thank you in advance. Below is the code snippet: <html> <head> <script> $(functio ...

CSS - extend underline text decoration to include :before elements

Currently, I am utilizing a font icon from Icomoon to include an icon in the :before element of an <a>. The functionality is smooth, but the issue arises with the text-decoration: underline, which only applies to the icon and text within the anchor t ...

modify data when parsing a file / utilizing loops in shell scripts

I have a log file that has the following format, <tr><td>AAA-application-01 <br> Quality_gate_failed_reason:xxxxxxx </td></tr> <tr><td>AAA-application-02 <br> Quality_gate_failed_reason:xxxxxxx </td>&l ...

Unable to extract text input from form

When designing a form for users to change their password, I encountered an issue where passing 3 empty Strings instead of a User object resulted in the Strings being returned as empty when submitting the form. Is there a way to retrieve String values from ...

What is the process of closing a dropdown in Vue 3 JS when clicking on any part of the page?

I am currently working with Vue 3 JS and Tailwind CSS. My dropdown functionality is working correctly, but I want the dropdown to close when clicking anywhere on the page. Initially, Tailwind guided me towards using Popovers and PopoverButtons, which cau ...

What is the best way to add color to the "ngx-star-rating" component?

I've been experimenting with the ngx-star-rating plugin, and I've tested different approaches like fill and color, but nothing seems to be working! Can anyone provide suggestions on how to change the star rating color from yellow to a different c ...

Tips for preventing flex items from having equal height when collapsing

When I try to place elements from an array in a list with display flex, the height of other elements gets modified when one is collapsed. I have attempted different display and inline placement on li elements but nothing has worked so far. Is there a way ...

Implementing a JavaScript/CSS popup element within a PHP document

I recently attempted to add a popup div to my front page by following instructions from this guide Given that I am not well-versed in coding, I found it challenging to implement the code into my PHP file (which is for a WordPress site). Uncertain about wh ...

Accessing user input upon button press

I am facing a challenge in displaying my emailInput on my createPassword page, specifically where [email protected] is mentioned. I have provided the code snippets for both pages below, the email page containing a user input and the password page wher ...

Change the color of the first element when hovering over any of its siblings using only CSS

I am looking for a solution using only CSS We have 3 circles here. When I hover over circles with the class name "Mycircle", the circle with the class name "BigCircle" should change to red color HTML <div class="BigCircle"></div> <div cl ...

Tips and insights on developing a personalized theme selector for Django: brainstorming and recommendations

As I continue to enhance my Django website, I am seeking advice on incorporating graphic charts and how to integrate them with Django. During the development of my software, I implemented a graphic chart that aligns with my company's colors (blue and ...