Incorporating a bottom line or border within the input field with a specified width

I have been struggling with styling an input field. I added a 1px solid #000 border around it, but now I need to include a thicker black line within the input itself. I tried using border-bottom: 5px solid #000, but that just created a border at the bottom of the input. How can I add a thick black line inside the input?

https://i.stack.imgur.com/zIRF8.png

.form-control{
padding: 15px 20px;
border: 1px solid #000;
border-bottom: 5px solid black;
}
<input type="text" class="form-control" name="text" value="text"/>

Answer №1

Utilize background and gradient effects as shown in the following examples:

.form-control {
  padding: 15px 20px;
  border: 1px solid #000;
  background: 
    linear-gradient(black, black) 
    bottom/ /* Position */
    80% 5px /* Width height */ 
    no-repeat;
}
<input type="text" class="form-control" name="text" value="text" >

To get rid of padding on left and right precisely, consider using background-origin/background-clip properties like this:

.form-control {
  padding: 15px 20px;
  border: 1px solid #000;
  background: 
    linear-gradient(black, black) 
    bottom -15px left 0/ /* Position */
    100% 5px /* Width height */ 
    content-box padding-box /* background-origin background-clip*/
    no-repeat;
}
<input type="text" class="form-control" name="text" value="text" >

An alternative approach using calc():

.form-control {
  padding: 15px 20px;
  border: 1px solid #000;
  background: 
    linear-gradient(black, black) 
    bottom/ /* position */
    calc(100% - 2*20px) 5px /* Width height */ 
    no-repeat;
}
<input type="text" class="form-control" name="text" value="text" >

You may also explore the use of box-shadow:

.form-control {
  padding: 15px 20px;
  border: 1px solid #000;
  box-shadow:
    20px  0 0 #fff inset,
    -20px 0 0 #fff inset,
     0 -5px 0 #000 inset;
}
<input type="text" class="form-control" name="text" value="text" >

Here's another concept involving gradients:

.form-control {
  padding: 15px 20px;
  border: none;
  border-bottom:5px solid transparent;
  border-image:
    linear-gradient(to right, transparent 20px,#000 20px calc(100% - 20px),transparent 0) 5;
  box-shadow:0 0 0 1px #000;
}
<input type="text" class="form-control" name="text" value="text" >

Answer №2

<div class="mainContainer">
    <input type="textarea" class="form-control" name="message" value="Your Message Here">
     <div class="lineDecoration"></div>
</div>


.mainContainer {
    width: 200px;
    position: relative;
}
div.lineDecoration{
    border-bottom: 5px solid black;
    width: 80%;
    position: absolute;
    bottom: 1px;
    left: 0;
    right:0;
    margin-left:auto;
    margin-right:auto;
}

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

Display the item with jQuery once the CSS generated by jQuery has finished loading

Is it possible to delay the visibility of an object until my script finishes loading? I tried using ajaxcomplete() and ajaxSuccess() without success. Check out the code snippet below for an example. There's an image with the id: imagefocus. Whenever ...

Differences in HTML animations can be seen when comparing Google Chrome to Microsoft Edge. Looking for a workaround for autoplay to ensure

My intro video animation is facing recording difficulties due to the autoplay policy in Google Chrome. It seems nearly impossible to capture it accurately. If only autoplay could function for an offline HTML file, my issue would be resolved. Unfortunately ...

Unable to eliminate top padding without using universal selector

Trying to remove the top padding on a webpage, but encountering some difficulty. Here's the HTML code: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <link rel="stylesheet" href="style.css"> <title&g ...

Tips for maintaining a scrollable Material-UI Table with dynamic height?

I'm encountering an issue with the Material-UI Table component in terms of its size and scrollability. Summary: The Material-UI table only becomes scrollable when its parent has a fixed size. If I set the size to 100% to fit the parent, it overflows. ...

Setting the height of a div based on its own width: A step-by-step guide

Is there a way to dynamically adjust the height of a div based on its width using CSS and Bootstrap? I am looking to maintain an aspect ratio of 75:97 for the height and width of the div. .my-div{ height: auto; border-radius: 20px; padding: 20 ...

Bootstrap 3 with a dual sidebar layout positioned on the left side

I am currently working on a project where I need to create a fluid layout with a left sidebar. However, now I would like to add an expandable sidebar next to the existing one. Below is an image to illustrate my goal: Initially, the left sidebar contains a ...

When I attempt to view my calendar in a modal popup, the opening action causes it

Recently, I encountered an issue with the bootstrap datepicker in a modal pop-up. The problem arises when it gets cut off unexpectedly. I am seeking suggestions or solutions to resolve this inconvenience. <input id="doohMediaStartDate" name="startDate" ...

Scrollbar width does not expand when hovered over

I am having trouble increasing the width of the scrollbar when hovering over it. However, I keep receiving an error in the console stating that 'scrollbar.addEventListener' is not a function. JAVASCRIPT setTimeout(function() { const scrollbar ...

Ensuring divs are centered when resizing the page

Is there a way to center an unordered list of tables while ensuring that it remains centered even when the window is resized? The list should move each table to a new line if they can no longer fit. Check out the code snippet below for reference: <d ...

Is it achievable to create shadows that do not overlap?

When you hover your mouse over the pill-shaped object, it should smoothly move over the circle as desired. However, the shadow of the circle still remains visible creating an unwanted effect. I am looking for a solution where the shadows do not overlap but ...

Is anyone else experiencing differences in the appearance of my mega menu between Safari, Firefox, and Chrome? It seems like

When viewing in Safari, the text overlaps for some reason. It works fine on Firefox and Chrome. Here's a screenshot of the issue: Safari: https://i.stack.imgur.com/hf7v2.png Firefox: https://i.stack.imgur.com/NrOOe.png Please use Safari to test th ...

Text vanishing upon the loading of an HTML webpage

I am experiencing an issue where the text on my webpage disappears after it loads, and I am struggling to figure out the cause. (I did not create the site) The white text displayed on top of the header image initially appears correctly but then vanishes. ...

Repairing div after upward scrolling and maintaining its fixation after refreshing the page

I have encountered two issues with this particular example: One problem is that the fixed_header_bottom should stay fixed beneath the fixed_header_top when scrolling up, causing the fixed_header_middle to gradually disappear as you scroll up, or vice v ...

Content escapes its parent container and seamlessly transitions to the following element

I am facing an issue with the layout of my element, which includes an image and text centered inside a parent container. Whenever I try adding more elements below the existing image and text, the green text with a red border overflows the current parent . ...

The issue of height and width always being zero in Chrome when using Classic ASP with JavaScript

Within my markup, I have an image field that I am setting the source for using JavaScript. I am in need of its height and width, so I utilized the image.height() and image.width() methods. Despite working properly in Internet Explorer, these methods do not ...

What is the best way to achieve consistent width in a material-ui card component?

How can I ensure that all these cards have the same width? https://i.stack.imgur.com/Ns3zw.png I'm experiencing an issue with achieving uniform card widths when using flexbox in material-ui. How can I resolve this? Is it necessary to utilize Grid fo ...

Enhancing the appearance of the CSS panel with Font Awesome icons

I need help adding a fontawesome or any other icon to my CSS3 based sliding panel button. The icon should change from open to close when clicked on. Any ideas on how to achieve this would be greatly appreciated! * { margin:0; padding:0; font-famil ...

Position footer at the bottom of the webpage and adjust the height to be filled with main content using Bootstrap 4

I am currently in the process of designing a bootstrap layout that includes a header navbar along with a footer. My goal is to ensure that the footer is always at the bottom of the page, even if there is limited content. Here's what I have implemente ...

When creating a dynamic page number using JavaScript during a print event, the height of an A4 page is not taken into

While creating my A4 invoice using HTML, CSS, and JS, everything appears correctly in the print preview. However, I am encountering an issue where the page number is not aligned properly and extra empty pages are generated automatically. Below is a snippe ...

Issue: Inability to scroll on div overflow section

My website consists of one static page with an HTML and CSS file. Oddly enough, when testing the page and inputting content into a multiline textarea until it overflows, the browser fails to display a scrollbar. Despite inspecting the div with the id &apos ...