The alignment of the text with the Bootstrap glyphicon is off

Currently, I am in the process of developing a form and implementing validation on my bootstrap form using bootstrap components. To handle server side validation, I am utilizing a c# class library, and then using c# code-behind to apply styles when the form meets certain validation conditions. The structure of my form control is contained within a panel as shown below:

<asp:Panel ID="TeacherNamePanel" CssClass="form-group" runat="server">
                    <asp:TextBox ID="tbTeacherName" CssClass="form-control input-lg" placeholder="Teacher-in-charge" runat="server"></asp:TextBox>
</asp:Panel>

In the code-behind, I validate the style like this:

if (teacherName.Length == 0)
{
      TeacherNamePanel.CssClass = "form-group has-error has-feedback";
      Label span = new Label();
      span.CssClass = "glyphicon glyphicon-remove form-control-feedback";
      span.Attributes["style"] = "vertical-align:middle";
      TeacherNamePanel.Controls.Add(span);
}
else
      TeacherNamePanel.CssClass = "form-group";

However, I am facing an issue where the glyphicon is not centered within the input control of my form, appearing slightly lower than expected. I have attempted to adjust the positioning by changing the "top" value for ".has-feedback .form-control-feedback" in the CSS file, but so far I have been unsuccessful.

Answer №1

Here are a couple of methods to achieve what you're looking for.

  1. Try using different syntax:

span.Attributes["style"] = "vertical-align:middle";

instead of

span.Attributes.Add("vertical-align", "middle");

  1. Another option is to add a css class and apply it to the label using the CssClass property. For example:

You can define this in your css file

.centerAlign {vertical-align: middle;}

and then use the following code snippet

span.CssClass = "centerAlign";

which will result in:

<span class="centerAlign">your text</span>

Answer №2

One way to ensure that the attribute overrides any predefined ones is by using the !important rule, as shown below:

span{vertical-align:middle!important;}

Answer №3

Issue resolved! I took the CSS code snippet below from bootstrap.css:

.has-feedback .form-control-feedback {
position: absolute;
top: 25px;
right: 0;
display: block;
width: 34px;
height: 34px;
line-height: 34px;
text-align: center;
} 

I then inserted it into my own stylesheet and made adjustments to the 'top' and 'right' values to suit my input box. Many thanks for your guidance and support!

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

CSS Flexibility in Action

Presently, my tab bar has a fixed look as shown here: https://codepen.io/cdemez/pen/WNrQpWp Including properties like width: 400px; etc... Upon inspecting the code, you'll notice that all the dimensions are static :-( Consequently, I am encountering ...

Utilize Flexbox to create a layout with 3 divs, organized into two columns where one column

I am attempting to transform <div></div> <div></div> <div></div> Three consecutive divs into the following format. Div 1 is red, div 2 is green, and div 3 is blue. I have achieved this using floats, like so: .div1 { ...

Just starting to learn jquery and I'm struggling with this code, can someone help?

I am trying to move the .icon element to the right and animate it based on its position().left value. Unfortunately, my code is not working as expected and I can't figure out why. It seems like such a simple task! <script> $("li.menu-item").ho ...

What is the process for creating a date range query using MongoDB's aggregation framework?

My objective is to carry out a match and group operation based on date ranges using mongodb 2.2 in conjunction with the latest c# driver. I'm encountering difficulties in constructing a match query within the aggregation framework that involves datet ...

utilize javascript to style iframe from an external domain without access to its DOM structure

I have two websites, example.com and example1.com. I'm trying to display the content of example1.com within an iframe on example.com. For instance: Add this code to example.com: <iframe src='http://example1.com'> Then add the follow ...

Webpage unable to scroll

Having trouble with scrolling on my webpage and I can't figure out why! The issue is happening when trying to view this page: Within the main file, I have included 2 other php files: <?php include '../../include/menu.php'; inclu ...

Preventing Past Dates from Being Selected in JQuery Date Picker

Need help with a date picker that only allows selection of the 1st and 15th dates of each month. How can I prevent users from selecting previous dates? <link href="https://code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css" rel="stylesheet" ty ...

The most recent version of Bootstrap is experiencing issues with responsiveness in the navbar

I have set up Bootstrap as follows: "@ng-bootstrap/ng-bootstrap": "^1.0.0-beta.5", "bootstrap": "^4.0.0-beta" Now, I wanted to add a navbar, so I created the following code: <nav class="navbar navbar-toggleable-md navbar-light bg-faded" *ngIf="! ...

Data loaded by the load() function disappears following an ajax action

I need assistance with a sorting page I am creating that displays content from a database and allows users to sort it using listjs. The issue I am facing is that when I click on any button, the loaded content disappears. Strangely, manually adding content ...

What could be causing my click() function to only work properly after resizing?

It's driving me crazy. The code snippet below works perfectly, but not in my project. Only the code in the resize() function seems to work. When I resize the window, everything functions as expected - I can add and remove the 'open' class by ...

Is there a way to simultaneously insert data into several tables using Linq?

How do I use Linq to insert records into multiple related tables? I have three tables - Contact, Phone, and Email. Is it possible to create a Contact first and then add Phone or Email records, as Phone and Email use ContactID as a foreign key? Below is t ...

Pagination of AJAX result on the client side using jQuery

My issue revolves around pagination in AJAX. I want to avoid overwhelming my search result page with a long list of returned HTML, so I need to split it into smaller sections. The Ajax code I am currently using is: $.ajax({ url: "getflightlist.php?pa ...

Avoid displaying "undefined" on HTML page when Firebase database value is empty

I am trying my best to explain my issue, although I struggle with scripts. Please bear with me and help me improve. ˆˆ Below is the script I am working on. The goal is to display all records with a date set for 'today or in the future'. Progr ...

Web links do not adjust properly on mobile pages

Weblinks are causing issues with responsiveness on my website, as they are increasing the mobile page width and resulting in a poor user experience. I am currently using the Asona theme. Please help me resolve this issue - the weblinks are not wrapping t ...

Tips for Rearranging Columns Using Bootstrap 4

In my Bootstrap 4 project, I have utilized the following HTML tags. <div class="container"> <div class="row align-items-center"> <div class="col-md-3"> <div class=&q ...

What is the best way to store plain HTML text in a database?

Currently, I am working on PHP source code to insert the page created using Quill text editor. Although the text editor data insertion is working fine, it is not inserting plain text as desired. My goal is to insert HTML plain text instead. Below is the J ...

Managing images in JavaScript while conserving memory

Welcome I am embarking on a project to construct a webpage using HTML, CSS, JavaScript (jQuery), and nearly 1000 images. The length of the HTML page is substantial, around 5000px. My vision involves creating a captivating visual experience for users as t ...

I encounter issues with HTML input fields becoming unresponsive whenever I attempt to apply CSS filters in IE8 for stretching the background

When I wanted to stretch a background image on my website so that it always fills the available window area regardless of resolution, I initially used background-size:cover;. Unfortunately, Internet Explorer doesn't seem to support valid CSS, so I had ...

The HTML rendering of the Django thumbnail image URL is not displaying correctly

Included in my template is this piece of HTML code: {%load thumbnail%} <img style="border: 1px solid #53BCB8; padding: 2px;" src="{%thumbnail 'photodir/photo.jpg' 256x256%}" /> Also in my settings.py file: MEDIA_URL="http://url.com/stati ...

Issue with jQuery click event not activating on initial click but functioning properly on the subsequent click

I am currently implementing the jquery.ime editor in my project, which allows for multi-language editing capabilities. The library I am using can be found here. By default, the language JSON files are loaded on "change" events. However, I would like this f ...