What is the best way to set up my css in order to ensure that the height of a span aligns with the height of a nearby input field (specifically

Can someone help me fix this issue?

https://i.sstatic.net/RyGML.png

The span with the percent symbol is stretching to fit the input margin. How can I stop this from happening? I've already tried various CSS attributes but nothing seems to work in separating the span from inheriting the input's excessive margin.

This layout was created using Hubspot CMS and I'm trying to replicate the Bootstrap styling on my regular website.

Here is the code:

<div class="row">
          <div class="col-sm-6">
            <label for="monthly-traffic" class="control-label">Monthly traffic (unique visitors)</label>
            <input class="form-control" type="number" name="monthly-traffic" id="monthly-traffic" class="form-control" placeholder="monthly traffic">
          </div>
          <div class="col-sm-6">
            <label for="percent-us" class="control-label">Percent of traffic from US</label>
            <div class="input-group">
              <input id="percent-us-addon" class="form-control" type="number" name="percent-us" placeholder="US traffic percentage" aria-describedby="percent-us-addon">
              <span class="input-group-addon">%</span>
            </div>
          </div>
        </div>

CSS styles used:

.col-sm-6 {
  width: 50%;
  float: left;
  position: relative;
  min-height: 1px;
  padding-left: 15px;
  padding-right: 15px;
}

.input-group {
  border-left: 0;
  border-bottom-left-radius: 0;
  border-top-left-radius: 0;
  position: relative;
  display: table;
  border-collapse: separate;
}

.form-control {
  display: block;
  width: 100%;
  height: 34px;
  padding: 6px 12px;
  font-size: 14px;
  line-height: 1.42857143;
  color: #555;
  vertical-align: middle;
  background-color: #fff;
  background-image: none;
  border: 1px solid #ccc;
  border-radius: 4px;
  box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
  transition: border-color .15s ease-in-out,box-shadow .15s ease-in-out; 
}

and

.input-group-addon {
  padding: 6px 12px;
  font-size: 14px;
  font-weight: 400;
  line-height: 1;
  color: #555;
  text-align: center;
  background-color: #e2e2e2;
  border: 1px solid #ccc;
  border-radius: 4px;
  width: 1%;
  white-space: nowrap;
  vertical-align: middle;
  display: table-cell;
}

Answer №1

Make sure to wrap your markup in the .input-group container and add the necessary addon classes (.input-group-append and .input-group-text).

By using this updated markup, you won't need any additional custom CSS:

  <label for="percent-us" class="control-label">Percentage of traffic from the US</label>
  <div class="input-group">
    <input id="percent-us-addon" class="form-control" type="number" name="percent-us" placeholder="US traffic percentage" aria-describedby="percent-us-addon">
    <div class="input-group-append">
      <span class="input-group-text">%</span>
    </div>
  </div>

See the complete codepen example @ https://codepen.io/cfxd/pen/ywbjxZ

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

Executing Python code through a website using PHP - is there a way to deactivate the button once it has been clicked?

Can you assist with the following issue? <?php if(isset($_POST['MEASURE'])) { shell_exec("sudo python /var/www/html/lab/mkdir.py"); } ?> Here is the HTML part: <form method="post" > <input type="submi ...

Guide to adding up the radio button values with Javascript

The tutorials I have reviewed include: How might I calculate the sum of radio button values using jQuery? How to find a total sum of radio button values using jQuery/JavaScript? How might I calculate the sum of radio button values using jQuery? Unfortu ...

Expansive menu that stretches the full height of the webpage

I'm having difficulty making my side spry menu extend the full length of the webpage. I tried using this code: $("nav").css({ "height" : $("nav").height() }); but it still isn't working as expected. I just want the grey color, like ...

What is the best way to style a Rails form field using CSS/Bootstrap?

I've been trying various methods and experimenting but I can't seem to figure out how to format my Rails view to display a form with Bootstrap or CSS. The issue might be related to the Bootstrap classes or the CSS. My goal is to create a two-col ...

The initial attempt to fetch a value using jQuery returned as undefined

When using jQuery to retrieve each message ID, I am facing an issue where the first instance of the message that the user has shows up as undefined. However, for all subsequent messages, it works perfectly fine. var mssg_id = $(this).find('input[name= ...

Scrollable tabs with Ionic

Hey there! I was researching before starting my project to see if Ionic has a feature similar to scrollable tabs. I noticed this in the fitrpg app, which was built with Ionic, but I'm unsure if it's a custom design. I plan to use it for a list si ...

When attempting to print a Bootstrap 4 HTML page in Chrome, the browser headers and footers are being clipped

Currently experiencing an issue with printing an HTML page styled using Bootstrap 4 (Bootstrap 3.3.7 works fine) on Chrome where the header and footer are partly covered up. Take a look at this screenshot to see what I mean - the date, title, and file/url ...

Is it possible for CSS div to have a height of 100% when placed within fluid parents

When the parent div's height is set to 100%, you can also set the child to 100% and it will function correctly. However, if the parent's height is determined by its content, the height attribute does not work as expected. Are there any effective ...

What is the process for creating a pop-up bubble that appears when the cursor hovers over an image displayed within a table using R Shiny?

I am currently working on code that is almost achieving my desired functionality. I want to make it so that hovering over each question mark in the table will trigger a pop-up bubble displaying the help text, rather than having the text appear at the botto ...

How to Extract Nested JSON Data in Java using Regular Expressions

Exploring the world of regex, I am on a mission to convert nested JSON into strings. Check out some sample examples below: My desired output string format is as follows: {"mainId":"12345","binaries":[{"subId":"123456bd","splitAll":true},{"subId":"123456c ...

What is the best method for selecting or isolating the code for a single animation created using JavaScript?

Currently, I am attempting to extract the CSS and JS code of an image reveal animation that is part of a static HTML page: https://i.stack.imgur.com/bnmaO.gif The challenge lies in the fact that the desired effect is one among many showcased image animat ...

Consolidate all CSS links into a single line

Within my HTML document, I currently have the following CSS links: myPage.html <link href="https://fonts.googleapis.com/css?family=Roboto:300,300i,400,400i,500,500i,700,700i" rel="stylesheet"> <link href="https://fonts.googleapis.com/icon?family ...

Include a visible symbol in the search bar of the kendo UI for easier navigation

Incorporating kendo UI Jquery into my website has allowed me to utilize components like the Kendo Multiselect, which features a clear icon on the right side provided by default. <div> <label for="simple-input">Input</label> <input ...

By setting the overflow-x property to hidden on my container, I have inadvertently disabled the sticky positioning

How can I make an element sticky when scrolling and hide horizontal scroll on mobile? I'm having trouble with horizontal scrolling on iPhone. Can you help me troubleshoot this issue? Thank you. .sticky-sidebar { position: -webkit-sticky; posit ...

Ways to stop two JavaScript files from running at the same time

After combining two JavaScript files, I am facing some issues. The first file handles validation while the second one has an ajax plugin for form submission after validation. When I include these files in the header section, they both run simultaneously. H ...

Attempting to rearrange the table data by selecting the column header

In an attempt to create a table that can be sorted by clicking on the column headers, I have written code using Javascript, HTML, and PHP. Below is the code snippet: <?php $rows=array(); $query = "SELECT CONCAT(usrFirstname,'',usrSurname) As ...

Navigational assistance on the keyboard - Improving Accessibility

My situation involves selecting an option from a dropdown menu on X-page, which triggers the opening of Modal-1 while disabling the background. If a selection is made within Modal-1, it leads to Modal-2. I am facing two issues/questions: Upon opening Moda ...

The column count is not properly set by Bootstrap 4.3 card-deck

I am working with Bootstrap 4.3 and custom Bootstrap SCSS imports, attempting to configure my card-deck for a custom theme. However, I am facing an issue with the $card-columns-count, as it is not being set correctly to 3 columns (as shown in the screensho ...

Ways to eliminate the extra space in a dropdown menu

Is there a way to eliminate padding on the "dropdown-menu" <ul> tag when the list is empty, so that no space is displayed in place of the padding? I want to avoid using .dropdown{padding: 0} because it will remove necessary padding when the list is ...

The MySQL database will need to contain an HTML form with specific styling attributes

I have been experimenting with creating an HTML form that allows users to add style attributes to their posts, such as Bold, Center, Font-Size, Link, Image, and more. However, my English skills are not the best, so I apologize if I am not explaining my que ...