Change the color of the div's background

My grid created using bootstrap 3 divs consists of a button, followed by a radio button, and then another button. I want to highlight these elements with a consistent background color that stretches across like a single row.

Check out my attempt on this fiddle - https://jsfiddle.net/oxfqvtds/2/

In the current setup, there is excess white space at the bottom right of the div which affects the uniformity of the highlighting.

.highlight {
  background-color: yellow;
}

.input-field {
  height: 20px;
  padding: 2px 10px;
}

.custom-label {
  line-height: 3.3em !important;
}

.label-size {
  font-size: 10px;
  line-height: 2.1em;
}

label {
  padding-right: 0px;
}
<head>
  <link type="text/css" rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
</head>
<body>
  <div class="container-fluid">

    <form class="form-horizontal">
      <div class="col-md-12">...</div>
      <div class="col-md-12">...</div> 
      <div class="col-md-10  highlight">
        <div class="form-group">
          <div class="col-md-3">
            <button class="btn btn-primary btn-xs" type="button">Test</button>

          </div>

          <label class="col-md-2 label-size">Options</label>

          <div class="radio" class="col-md-7 label-size">
            <label class="label-size">
            <input type="radio" name="opt" value="opt" >opt</label>

          </div>
        </div>
      </div>
      <div class="col-md-2 highlight form-group">

        <button class="btn btn-info btn-xs pull-right">Test2</button>

      </div>
    </form>
  </div>
</body>

https://i.stack.imgur.com/Pgf5x.png

I'd also like for the buttons and radio buttons to be vertically centered within the highlighted area, as they currently appear towards the top.

Answer №1

When using bootstrap, ensure that your columns are within a row element. Once the row is in place, you can apply background color to it. Also, make sure to remove any form-groups and check for duplicate class listings around elements like radio buttons which may interfere with the Bootstrap column classes.

.highlight.row {
  background-color: yellow;  
  margin:0;
}

.input-field {
  height: 20px;
  padding: 2px 10px;
}

.custom-label {
  line-height: 3.3em !important;
}

.label-size {
  font-size: 10px;
  line-height: 2.1em;
}

label {
  padding-right: 0px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container-fluid">
<div class="row highlight">
  <form class="form-horizontal">

    <div class="col-md-10  ">
      <div class="">
        <div class="col-md-3">
          <button class="btn btn-primary btn-xs" type="button">Test</button>

        </div>
        <div class="col-md-2">
        <label class="label-size">Options</label>
        </div>
        
        

        <div class="col-md-5 label-size">
          <label class="label-size">
            <input type="radio" name="opt" value="opt" >opt</label>

        </div>
      </div>
    </div>
    <div class="col-md-2">

      <button class="btn btn-info btn-xs pull-right">Test2</button>

    </div>
  </form>
  </div>
</div>

Answer №2

Eliminate the margin-bottom on this specific form-group

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

dynamic webpage resizing using html and css

Looking for a way to make my SharePoint window automatically resize when the user changes their browser size. I'm using the web version of SharePoint at work and don't have access to Designer. <style type="text/css"> #dgwrap { HEIGHT: ...

Steps to place a URL and Buttons over an existing header Image

1) I am working with a header JPEG image that is 996px wide and includes a square logo on the left side. My goal is to use only this square logo section and add an href tag so that when users hover over it, the cursor changes to a hand pointer and they are ...

The delete button is designed to remove the record from the database while keeping it visible on the frontend

When the delete button is pressed, it successfully removes the record from the database. However, it does not disappear from the frontend until the page is reloaded or refreshed. This is what I see: @foreach (var item in Model) { <a href="#" ...

Need help speeding up website load times?

My website is loading incredibly slow, even though it has minimal content. I suspect that the high number of images and JavaScript elements on the page are contributing to this issue. Is there a method available to diagnose what exactly is causing the ext ...

Processing of an array received via AJAX and passed to a PHP script, inside a separate function in a different file

I have a JavaScript array that I am sending via AJAX to a PHP file named aux.php. What I want is for this array to be visible and manipulable within a function inside a class in another PHP file called payments.php. I've provided all the code so they ...

What is the best way to align a scalable SVG image in the center?

My goal is to horizontally align this SVG within its container, which could be any div, body, or other element. <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1250 190" preserveAspectRatio="xMidYMid slice" class="svg-content"> &l ...

Execute function upon initial user interaction (click for desktop users / tap for mobile users) with the Document Object Model (DOM)

Looking to trigger a function only on the initial interaction with the DOM. Are there any vanilla JavaScript options available? I've brainstormed this approach. Is it on track? window.addEventListener("click", function onFirstTouch() { console.l ...

Sorry, but we are experiencing difficulties processing your request at the moment. HTTP ERROR 500: We are unable to locate the

My code seems to be functioning correctly when connecting to the database, but I'm encountering an error. Here is the code snippet: <?php include 'header.php'; ?> <!DOCTYPE html> <html> <head> <t ...

Automatically filling in related information in multiple input fields after choosing a value in a specific input field using JavaScript

My horizontal form is dynamically generated using JavaScript, with each input field having a jQuery autocomplete that retrieves data from a database using the $.get method. I'm looking to automatically populate the second input field with the corresp ...

Generate a new array using a single value extracted from an existing array

I'm new to working with arrays. Before this, I used to manually code everything in HTML. My question is, can you create an array based on the values of another array? var pmmain =["aaa", "bbb", "ccc", "ddd", "eee", "fff", "ggg", "hhh", "iii", "jjj", ...

Enhance the appearance of your Vuejs application with conditional style formatting

I want to enhance a basic table by applying conditional CSS styles to the cells based on their values. For example: If area1 == 'one', then assign the td-one CSS style. <tr v-for="version in versions" :key="version.id"> < ...

The error message "email() is not a valid function when using the onclick attribute

Can anyone lend a hand? I feel like I must be overlooking something really obvious. I'm having trouble calling my function to execute my ajax call. Any assistance would be greatly appreciated. Thank you! Here is an excerpt of the HTML code: $(docu ...

Is there a way to verify the identity of two fields using an external script such as "signup.js"?

My current project involves working with Electron, and it consists of three essential files. The first file is index.html: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <link rel="styles ...

Display the HTML tag inside a cell of a mat-table

I am currently exploring options to display an HTML tag within a cell of a mat-table in Angular. My goal is to show a colored circle next to the cell value. I have searched online for solutions, but haven't found one that works. If anyone has any insi ...

Master the art of filtering rows in an HTML table based on a select option when the mouse is clicked

I am trying to create a table that displays only the rows selected in a dropdown menu. Here is an example: If "All" is selected, the table should display all rows. If "2017" is selected, the table should display only the rows that have "2017" in the sec ...

How can I make the Bootstrap navbar drop-down menu disappear automatically when a link is clicked in an Angular application?

When viewing the Bootstrap navbar on smaller screens, it appears as a panel of buttons that cover the page content. While there are many solutions for hiding this panel when clicked on, my question pertains to hiding the panel when links within the main bo ...

What is the best approach to refreshing a particular div with the contents of a view file?

I have a block of code in PHP/Symfony that looks like this: <div id='content'> <?php include_partial( 'course/content.php', array("param1" => "1", "param2" => "2") ); ?> </div> Now, I am interested in updatin ...

Is there a way to adjust the transparency of a span element's background without affecting the text itself?

I have some code that needs to be customized. This is my HTML: <div class="text-rotator add-top-half add-bottom-half align-left white-txt medium-txt uppercase highlight-bg"> <div class="rotator-wrap" style="display: block;"> <sp ...

Issues with CSS margins in IE causing bugs?

Currently dealing with a CSS issue that seems to be specific to Internet Explorer. I haven't encountered it in Firefox, Safari, or Opera during testing with IE 11. The problem: I've set the top margin of the website content/stage to around 2%, ...

Adjust the size of the buttons based on the width of the screen

I have successfully implemented a dropdown menu with both text and an icon. However, I am now faced with the challenge of removing the text while retaining the icon when the screen width is reduced to a maximum of 768px. Is it possible to modify the conten ...