Textfield with Bootstrap Glyph Icons

I am facing an issue with adding a Textfield input-group-addon. The problem arises when I combine this class with a glyphicon, as the icon does not align correctly next to the textfield. You can see the issue in the image below.

If anyone has any insights or suggestions on why this might be happening, I would greatly appreciate it!

<!-- Text input-->
        <div class="form-group">
            <label class="col-md-4 control-label" for="name2"></label>
            <div class="col-md-4">
                <input id="name2" name="name2" type="text" placeholder="" class="form-control input-md">

            </div>
        </div>

        <!-- Multiple Radios (inline) -->
        <div class="form-group">
            <label class="col-md-4 control-label" for="gender">Gender</label>
            <div class="col-md-4">
                <label class="radio-inline" for="gender-0">
                    <input type="radio" name="gender" id="gender-0" value="1" checked="checked">
                    Male
                </label>
                <label class="radio-inline" for="gender-1">
                    <input type="radio" name="gender" id="gender-1" value="2">
                    Female
                </label>
            </div>
        </div>


        <div class="form-group">
            <label class="col-md-4 control-label" for="gender">Date of Birth</label>
            <div class="col-md-4">
                <div class='input-group  date' id='datetimepicker2'>
                    <input type='text' class="form-control" />
                    <span class="input-group-addon">
                        <span class="glyphicon glyphicon-calendar"></span>
                    </span>
                </div>
                    <script type="text/javascript">
                        $(function () {
                            $('#datetimepicker2').datetimepicker({
                                language: 'en'
                            });
                        });
                    </script>

                </div>
            </div>

Answer №1

Your code is functioning well with Bootstrap alone. You can check out this fiddle for reference: http://jsfiddle.net/WNAB8/1/

The issue lies within your custom CSS. Utilize developer tools (F12) to identify what is causing the margin-right on the input or margin-left on the addon. Alternatively, share your custom CSS so that we can assist you.

Update:

The problem seems to arise from the specific max-width assigned to inputs. If you still need to utilize max-width, one solution is to apply it to .input-group like this:

.input-group {
  max-width: 280px;
}

Demo: http://jsfiddle.net/WNAB8/5/

Answer №2

Your fiddle is currently overriding bootstrap's textarea maxwidth option. To fix this, remove the following code from your CSS:

    /* Set width on the form input elements since they're 100% wide by default */
input,
select,
textarea {
    max-width: 280px;
}

Here is a working example for reference.

If you need to adjust the width of your text areas, use Bootstrap's form layout feature. You can customize the width by utilizing the form layout options. For instance, consider using the horizontal form layout and control the width by placing the input inside a div with the col-* classes:

 <div class="col-sm-10">
  <input type="email" class="form-control" id="inputEmail3" placeholder="Email">
</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

The border-bottom property isn't functioning properly in Chrome when viewing in full screen mode

I have observed that the css border-bottom property is not functioning properly in Chrome. Upon testing in IE 10 and Mozilla, I found that it works fine on these browsers. However, it only works in Chrome when the full screen mode is not being utilized. ...

Displaying vertical text in all browsers except for Internet Explorer

This is absolutely fascinating to me right now! span.verti{ -moz-transform: rotate(-90deg); /* FF3.5+ */ -o-transform: rotate(-90deg); /* Opera 10.5 */ -webkit-transform: rotate(-90deg); /* Saf3.1+, Chrome */ filter: progid:DXImageTrans ...

Can the height of one div be determined by the height of another div?

Here's the specific situation I am facing: I want the height of Div2 to adjust based on the content of Div3, and the height of Div3 to adapt based on the content in Div2. The height of Div1 is fixed at 500px. Some of the questions that arise are: I ...

Tips for customizing the appearance of a checkbox made with AngularJS

I need to style the checkbox using CSS without modifying the HTML code provided due to company restrictions. Is there a way to customize the appearance of the checkbox purely through CSS? Below is the AngularJS code snippet: <label class="form-lbl n ...

What could be causing my jQuery script to malfunction?

After scouring through numerous Stack Overflow questions and conducting countless Google searches, I am still stumped by the issue at hand. As a beginner in web development, all I want is for this simple page to function properly. Can someone please point ...

What is the best way to align the navigation bar in the center

Hi there! Currently, I am in the process of creating a navigation bar for a website but I am facing an issue where the logo and navigation elements are not covering the entire width of the browser. My goal is to have the logo aligned to the far left and th ...

Issue with Bootstrap card collapsing and merging with other cards

I am using Bootstrap to design a grid of cards, but I am facing an issue where all the cards are merging together when I resize the screen. This issue occurred when I attempted to position the icons to appear at the top left of the card and the bottom midd ...

What is the best way to add or remove a CSS class when a user selects a Radiobutton using JQuery?

Here is the ASPX markup I am working with. Users can select an answer by choosing a radiobutton labeled as the "winning question." I have HiddenFields that contain either True or False. If a user selects 'rdAnsBool1' and the 'HiddenField1& ...

Struggling with evenly positioning 6 elements in two rows using CSS

For positioning 6 different elements on a webpage, I've experimented with various methods: I initially tried stacking two unordered lists vertically but faced issues with scaling when stretching the page. Another attempt was using a table, but I stru ...

Overriding CSS with Autofill

Hey there, I could really use some guidance with CSS while working on my project using Next.js 13.4 and Typescript. Currently, I'm dealing with a form that consists of two input fields for login and password. While testing on Google Chrome and Mozill ...

Utilizing CSS Selector in Google Tag Manager to target a button with a specific name attribute

I am facing a challenge with the click trigger in Google Tag Manager. The trigger is set to fire when clicking on an element with the CSS selector button[name=checkout]. However, it does not work for spans inside the button tag. Any suggestions on how to r ...

Can CSS actually generate accurate inches?

Can you accurately set the width of an element, like a div, in inches and expect it to maintain that width across different devices? Or will it simply scale at a ratio like 1in = 96px? Edit: Try using CSS to set an element's width in inches and then ...

Setting Up One Stylesheet Based on Local Preferences

I am working on positioning translated text on a webpage. The word NEW in English and NOUVEAU in French need to be centered below a graphic. Since the words have different lengths, I am considering using absolute positioning. The challenge is setting the l ...

Create a single CSS style rather than using multiple CSS styles

I currently have multiple CSS styles applied: form#reply_form-c1r1.odgovor div#cmtforms-c1r1 input{color:red} form#reply_form-c2r1.odgovor div#cmtforms-c2r1 input{color:red} form#reply_form-c3r1.odgovor div#cmtforms-c3r1 input{color:red} form#reply_form-c4 ...

CSS- The ultimate guide to perfectly centering a webpage without the need for extra margins!

Our SharePoint 2013 generated web page has a width of 1024. The main content div is styled as follows: #container_master { width:1024px !important; margin-left: auto !important; margin-right: auto !important; background-color:#FFF !impor ...

Adjusting the dimensions of the geocoder control in Leaflet.js

I need assistance adjusting the size of the geocoder control on my customized map: L.Control.geocoder().addTo(Map) https://i.sstatic.net/UxkQZ.png ...

What is the best way to align a div and two buttons with respect to an image within an li element?

I am trying to adjust the positioning of text on top of an image with a 40px margin. Additionally, I want to place two buttons on each side of the list item (one on the right and one on the left). Despite numerous attempts with various solutions, including ...

Is there a quicker alternative to the 500ms delay caused by utilizing Display:none?

My div is packed with content, including a chart from amCharts and multiple sliders from noUiSlider. It also features various AngularJS functionalities. To hide the page quickly, I use $('#container').addClass('hidden'), where the rule ...

Ways to extract data from a specific part of the HTML code

Greetings, this is my initial foray into coding and I am attempting to create a scraper that can gather all the relevant information about my school and district. \[<p class="flex-icon"> \<svg aria-hidden="true" clas ...

Apply CSS styles when clicked and remove them when clicked again

I have successfully set a style when clicking on a div. However, I am looking to reset the style to default when clicked again. $('#tray-button').click(function() { $('.buttons-content').css('bottom', '160px& ...