Styling ASP.NET Textbox with CSS to fill the width of a div

I am struggling to make my ASP.NET C# textbox responsive and span the entire width of the div. I am using Bootstrap 4 and have tried various methods without success.

  • I attempted nesting divs with centering and expanding techniques.
  • Setting margin-left & right to auto.
  • Experimenting with display: block, flex, and inline-block.
  • Hard coding size values.
  • Utilizing CSS sizing properties.
  • Exploring box sizing options.
  • Testing out numerous Bootstrap classes.
  • And more strategies.

Here is a screenshot of my current result: https://i.sstatic.net/USdMk.png

Below is the ASPX and HTML Code:

         <div class="col-sm-6">
            <asp:Label ID="lblContactHeader" runat="server" Text="Drop us a line" Font-Bold="True" CssClass="large-label"></asp:Label>
            <br />
            <div class="form-group">
                <asp:Label ID="lblName" runat="server" Text="Name*"></asp:Label><br />
                <asp:TextBox ID="txtName" runat="server" CssClass="inputSize"></asp:TextBox><br />
            </div>
            <div class="form-group">
                <asp:Label ID="lblPhone" runat="server" Text="Phone*"></asp:Label><br />
                <asp:TextBox ID="txtPhone" runat="server" CssClass="inputSize"></asp:TextBox><br />
            </div>
            <div class="form-group">
                <asp:Label ID="lblEmail" runat="server" Text="Email*"></asp:Label><br />
                <asp:TextBox ID="txtEmail" runat="server" CssClass="inputSize"></asp:TextBox><br />
            </div>
            <div class="form-group">
                <asp:Label ID="lblComments" runat="server" Text="Comments*"></asp:Label><br />
                <asp:TextBox ID="txtComments" runat="server" CssClass="inputSize" TextMode="MultiLine" Rows="3"></asp:TextBox>
            </div>
            <br />
            <asp:Button ID="custContact" runat="server" Type="submit" Text="Submit" CssClass="btn btn-orange btn-right"/>
        </div>

The following is my current CSS code where I have implemented multiple solutions proposed in different Stack Overflow posts:

.inputSize {
width: 100%;
margin-left: 0px;
margin-right: 0px;
padding-left: 0px;
padding-right: 0px;}

Lastly, here is the HTML version of the code:

                    <label>Name*</label>
                    <input type="text" name="custName" class="form-control" required />
                    <label>Phone*</label>
                    <input type="text" name="custPhone" class="form-control" placeholder="(###) ###-####" pattern="^\d{10}$|^(\(\d{3}\)\s*)?\d{3}[\s-]?\d{4}$" required />
                    <label>Email*</label>
                    <input type="text" name="custEmail" class="form-control" required />
                    <label>Comments*</label>
                    <textarea class="form-control" name="custComm" required ></textarea>
                    <br/>
                    <input type="submit" name="btn-submit" id="custContact" value="Submit" class="btn btn-orange btn-right"/>

Answer №1

The reason for this issue could be attributed to a different style sheet taking precedence over the bootstrap styles.

Answer №2

It's important to familiarize yourself with the Bootstrap documentation in order to understand how the

<div class="row" />
and
<div class="col-*" />
elements function. Additionally, learning about reponsive breakpoints can help clarify the purpose of -sm-, -md-, and other designations.

For example, if you have:

<div class="row">
    <div class="col-sm-6">
        ...
    </div>
</div>

This will give you a column that occupies 50% of the screen width because Bootstrap operates on a 12-column system, with 6 representing half of it.

If you require a full-width element, simply omit the

<div class="row" />
and
<div class="col-sm-6" />
tags or switch to
<div class="col-sm-12" />
.


To make an input span the entire width within its container, as suggested by @bhmahler in the comments, apply the .form-control class to the input field. This class sets the input to display: block; and width: 100%;: https://getbootstrap.com/docs/4.5/components/forms/#layout

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

Utilizing Padding Effectively Within an <a> Tag in HTML/CSS

Is there a way to make it so that clicking on the padding with the grey background color and orange rollover will also open the link, in addition to clicking on the text as expected? https://i.sstatic.net/AJ9Fy.png The JavaScript code is shown below: so ...

Having issues changing the color of fontawesome icons

I am struggling to change the color of a fontawesome icon when it is clicked. <a id="thumbsup">@Html.FontAwesome(FontAwesomeIconSet.ThumbsUp, FontAwesomeStyles.Large2x)</a> My goal is to have the icon start off as gray, turn blue when clicke ...

Using Bootstrap "Display-3" effectively for smaller mobile screens

I am impressed with how "display-3" looks on desktop, it really stands out. However, the issue arises when viewing it on mobile as some of the words are cut off. I'm wondering how to change it to "display-4-sm" or something similar for mobile devices. ...

Retrieving User.Identity on the Master Page

Having trouble accessing User.Identity from my master page to determine who is logged in. Even after importing System.Security.Principal, it doesn't seem to work: <%@ Import Namespace="System.Security.Principal" %> Interestingly, I can access ...

Verification of Social Security Numbers using Regular Expressions

How can I achieve the following? I would like the text box to be empty when the cursor is placed inside, and to display the 000-00-0000 format when the page loads. I have attempted the following- <asp:RegularExpressionValidator ID="RegularExpressionV ...

Aurelio's never-ending quest for fetch

Recently, I've been diving into my first Aurelia project using the skeleton for typescript and asp.net core. However, I've run into a puzzling issue with the fetch operation that seems to be stuck in an endless loop without any clear reason why. ...

The method for extracting values from a PXselectorgetQuery- has multiple benefits

Greetings, I am new to Acumatica development and have a question regarding retrieving data from pxselector when a row is selected. Below is the selector that I have created: https://i.sstatic.net/PTifH.png Currently, when I select a row, I am only able ...

Modify the Repeater Index dynamically during execution

My Repeater control is currently populated with 4 values. 1 Class_1 2 Class_2 3 Class_4 4 Class_3 The Repeater displays the data in this order: Class_1 Class_2 Class_4 Class_3. However, I want the data to be displayed as: Class_1 C ...

Identify the specific code that will be executed upon pressing a button - checkbox restriction

Check out my code example on jsfiddle: https://jsfiddle.net/elenderg/wzarrg06/63/ In the first div, there are 10 buttons. See image below: https://i.sstatic.net/BDdtG.png <button class='btn btn-info custom' onclick="myFunction()" ...

Why is object-fit not functioning properly? Could it be that the container is influencing the object-fit

Why isn't object-fit working? It only seems to work with inline styling in the image tag. Could it be the hero_media container affecting object-fit? I'm also attempting to use pseudo-elements (after and before) to add text to the image. Is it nec ...

Encountering a issue while attempting to display a nested model in ASP.NET MVC

I'm attempting to display a model within another model in order to execute a join operation in the database. I have two models: public partial class Orders { [System.ComponentModel.DataAnnotations.DisplayFormat(DataFormatString = "{0:dd/MM/yy ...

A step-by-step guide to incorporating expandable and collapsible images within a div element using X

I have successfully created dynamic divs with some data that expand and collapse perfectly. Now I am looking to add expand and collapse images on these divs. I am relatively new to designing in xslt. <xsl:template match="category[key!='org.model.C ...

The body background position center does not function properly in Internet Explorer

I'm currently working on a website and facing some issues with the background-position property in CSS. Here is the code snippet that's giving me trouble: body { background-color: Black; background-image: url(images/background_ui.png); backg ...

What could be causing the Bootstrap4 modal to not display data on my Django Template?

Looking for a solution to display data in the modal body using django variables. I'm new to ajax and django, so struggling with it. The ajax function sends the id of the Galeria object, and then the view returns a JsonResponse with the data. Why is th ...

Display an image when the iframe viewport is reduced in size by utilizing media queries

I am looking to showcase a demo.html page within a 400px square iframe. When the viewport is smaller than 400px, I want demo.html to only display an image. Then, when clicking on that image in demo.html, the same page should switch to fullscreen mode. Sim ...

In ASP.NET 3.5, learn how to display a default image from the images folder when no items are found

I have implemented an ASHX handler to display images upon request from the server side. Below is the code for my handler : <%@ WebHandler Language="C#" Class="DisplayImage" %> using System; using System.Web; using System.Linq; public class DisplayI ...

Infragistics Web POP-UP box

We are facing challenges with our web app that is built on asp.net (C#) and utilizes some infragistics asp.net controls. Specifically, we are encountering issues with the infragistics web dialog window (IGWD) after transitioning the html of the app to ht ...

Steps to Make a White Content Box on Top of an Image Background using HTML/CSS

I am currently struggling with overlaying a white box on top of my background image in order to have my text inside the box for a more visually appealing look. Despite trying to add CSS code like this: .white-box { position: absolute; background-c ...

Guide on incorporating content from external pages into a modal using the latest version of Bootstrap, 4.4.x

I am looking to incorporate content from an external page into a Bootstrap 4.4 modal. You can view my demo here. JS: $('#theModal').on('show.bs.modal', function (e) { var button = $(e.relatedTarget); var modal ...

Unknown Tag in AjaxControlToolkit's HTML Editor Component

I am trying to incorporate an HTML editor into my code. Here is the snippet I have: <%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %> ...