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

Result of mixing CSS colors

Is there a way to retrieve the result of blending two colors using the color-mix function? In cases where the color-mix feature is not supported, is it possible to set a fixed value instead? ...

What is the process for clicking on the second link within a table when the values are constantly changing in Selenium RC Server?

How can I click on the second link labeled XYZ STORES? How do I print the text "Store XYZ address"? How can I click on the second link ABC STORES? How do I print the text "Store ABC address"? The links, addresses, and store names are all changing dynam ...

What steps do I need to take to launch an embedded kml tour?

This marks the beginning of my journey into the world of online forums! I used to rely on Stack Exchange for answers to my questions, but most of the time, someone else had already asked what I needed to know. It goes to show how effective this website is. ...

Navigation bar transforms color once a specific scroll position is reached

My website features a sleek navbar fixed to the top of the window. As users scroll past a specific div, the background color of the navbar changes seamlessly. This functionality has been working flawlessly for me thus far. However, upon adding anchor link ...

Introducing an alternative solution for handling tasks linked to the completion of CSS3 animations

In order to incorporate smooth CSS3 animations into my website, I have implemented the animate.css library created by Dan Eden. One particular scenario involves a loading screen that features a fade-out animation. It is crucial for this animation to comple ...

Mixing box-shadow and blur filters can result in unusual artifacts appearing in Webkit browsers

Recently, I encountered an intriguing and frustrating bug in WebKit browsers. Consider a scenario where there is a parent DIV (let's say .wrapper) and a child DIV (.main). You apply a box-shadow on the .main DIV and a blur filter on the .wrapper DIV. ...

Why is it that every time I write this code, the localhost gets redirected and a message pops up saying

<?php include("connect.php"); if(isset($_POST['submit'])) { $qonax=@$_POST['qonax']; $subject=@$_POST['subject']; $insert="INSERT INTO subject(ID,Qonax,Subject)VALUES('','$qonax', ...

Customizing hyperlink styles with JavaScript on click

Hey there! I'm experimenting with something new. I've managed to change the background color of each link after it's clicked, but now I'm facing a challenge: How can I revert the original style when another link is clicked? Here's ...

SVG path with dynamic elements

Consider the following SVG: <svg xmlns="http://www.w3.org/2000/svg" width="237" height="129" viewBox="0 0 237 129" fill="none"> <path d="M228 1H9C4.58172 1 1 4.58172 1 9V91V104V127L20 111.483L228 112C232.4 ...

What are some ways to align text both vertically and horizontally within columns?

How can I center text both vertically and horizontally inside two columns using Bootstrap 4? <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css"> <div class="row"> <div class="co ...

Leveraging AJAX to call upon a designated php file

I have a selection of menu items on my webpage, each with different options: option1, option2, and option3. Additionally, I have corresponding PHP files on my server for each of these menu items: option1.php, option2.php, and option3.php. For simplicity, ...

Obtaining numerous distinct array elements

I have created a form with checkboxes for users to select options. <input type="checkbox" name="rights[]" value="1" class="a"> A <input type="checkbox" name="rights[]" value="2" class="b"> B <input type="checkbox" name="rights[]" value="3" ...

Is it possible to implement counters in CSS with Jquery?

I am trying to implement a specific style when an if statement is executed, but Jquery is encountering syntax issues and generating errors. Does anyone have a solution for escaping these errors so that I can still apply the desired styling? The problemati ...

Guide to dynamically insert rows in HTML using Vue.js based on the selected option

This is the initial row. Depending on the selection made here, different rows will be displayed <div class="row"> <div class="col-md-4"> <div class="form-group label-floating"> <label class="control-label">Case Type< ...

The MUI Modal is too large for the display

I'm using a Modal component from MUI in my project and I am facing an issue with displaying a large JSON object inside the modal. The problem is, the top of the modal extends beyond the screen height and even after making it scrollable, I am unable t ...

Is there a way to alter a class using ng-class only when the form is deemed valid?

I am trying to implement a feature where an input field shows as required, but once the user enters text, it indicates that the input is valid by changing the border color from red to green. I am facing an issue with this line of code always returning fal ...

Can a webpage be redirected to another page after an animation using only HTML and CSS?

My goal is to design a landing page that has a button allowing users to trigger an animation before being redirected to another page. This concept involves adding a captivating element before transitioning between pages, similar to a link with a dynamic ...

Making sure all items in the top row of Flexbox columns have the same height

Within my flex wrapper, I have multiple column components with various flex items inside. Each column displays content adjacent to each other. The challenge is to ensure that the top item in each column has an equal height, creating a row-like effect. I&a ...

Is there a way to use JavaScript or jQuery to automatically convert HTML/CSS files into PDF documents?

While using OS X, I noticed that in Chrome I have the option to Save as PDF in the print window by setting the destination to "Save as PDF". Is this feature available on Windows? Is there a way to easily save to PDF with just one click? How can I access t ...

Retrieve the value of a CSS class property regardless of whether it is actively being utilized

I am facing a dilemma where I need to determine the value of the 'width' property for a css class named 'foo' (example: ".foo { width:200px}" ). However, there may not be an element with this class in the dom yet. My goal is to retrie ...