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

The width of the absolute div shrinks to such an extent that the text starts wrapping around itself

My goal is to create a button that, when hovered over, displays a div. However, I am encountering challenges with the width and position of this div. The issue is illustrated in the images below and in the accompanying jsfiddle. When I set the positioning ...

Java Spring - The on-page styling is out of control

Currently, I am in the process of developing a taxi web application using Java Spring. After successfully creating the website with the help of a template, I encountered an issue when trying to integrate the login functionality. Strangely, the styling on ...

Incorporate a glyphicon into a webpage design that wasn't originally built with bootstrap while maintaining the original layout

Looking to jazz up my vintage website with some cool glyphicons on a specific page. Don't want to mess up the entire look of my site by installing bootstrap. Is there a way to add just the "glyphicons functionality" without changing everything else? ...

What are some strategies to stop a jQuery UI button created with a link from inheriting the link's text color?

I recently came across a recommendation to create a jQuery button on top of a link for redirect purposes: <a href="/search" class="button">My link</> $(".button").button(); However, I noticed that if the button class has a red foreground colo ...

Utilize jQuery to dynamically swap out a CSS stylesheet in response to changes in the body class

In the head section of my HTML, I have the following stylesheet: <link rel="stylesheet" href="/templates/jooswatch-v3-5/css/bootswatch/superhero/bootstrap.min.css"> I want to replace this stylesheet with different ones based on changes in the body# ...

Excessive content spilling over the div container

Hello everyone I've been trying to set up a div that includes an image, a title, and some text. I want the image to be aligned on the left side, with the title and text following on the right. However, I'm having an issue where the text is overf ...

Arranging my HTML text fields for optimal organization

I am struggling to format my text fields the way I envision. Here's what I want: - Username field at the top - First and last name underneath each other - Password and confirm password next to each other below names As a newcomer to HTML, I'm fi ...

Learn how to implement a feature in your chat application that allows users to reply to specific messages, similar to Skype or WhatsApp, using

I am currently working on creating a chatbox for both mobile and desktop websites. However, I have encountered an obstacle in implementing a specific message reply feature similar to Skype and WhatsApp. In this feature, the user can click on the reply butt ...

Whenever I click the left mouse button, the website crashes

Why does clicking the left mouse button make the website scroll down? Any ideas for a solution? Check out the link here: I've tried everything since I just started working on my website. Be prepared to be shocked when you see the source code HAHAHHA ...

Tips for handling transparent areas during a hover event

Is there a way to make only the rhombus image respond to hover events? I want to exclude the transparent area, as shown in this picture. <img src='http://s30.postimg.org/xpd6gwla9/1_Copy.jpg' id="first"> #first:hover { -moz-box-shadow ...

Avoid duplicate borders on columns that adjust their size based on the screen width

Picture yourself utilizing Bootstrap 4 and displaying various cells, each with unpredictable numbers. .cell { border: 1px solid black; } <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"> < ...

Attach a tab-icon to a picture

I am looking to add a tab to the bottom border of an image within a gallery. This tab needs to be right up against the image border with no space in between. When clicked, this tab should activate a small JavaScript function that will display the content ...

Is there a way to display multiple Bootstrap 5 modals simultaneously without automatically closing the previous ones?

My current project utilizes bootstrap 5.2, which is a departure from the previous version, bootstrap 3. In bootstrap 3, it was possible to open multiple modals on top of each other, creating an overlapping effect. However, in bootstrap 5 and 5.2, the behav ...

Using jQuery to move a div to a specific location on the page

Is there a way to translate the position of div x and y using Jquery that is compatible with all browsers, such as IE 7, IE8, IE9, and IE10? I have attempted the following: <div id="s1" style="-ms-transform:translate(159,430)"> hello ...

Setting the z-index for a JavaScript plugin

I need help with embedding the LinkedIn plugin into a website that has stacked images using z-index for layout. I have tried assigning the plugin to a CSS class with a z-index and position properties, but it hasn't worked as expected. Can anyone sugge ...

Creating a Loop for Tabs on an HTML Form

When navigating through form input boxes using the tab key, it usually goes in order. However, I discovered that you can actually customize this order by using tabindex=x. Since I have 5 inputs on my form, I use tabindex 5 times to specify the order. But ...

Prevent animation when expanding the menu in Vue using CSS

The animation only works when collapsing the menu, not when expanding it. I tried adding CSS for setting a max-height, but the animation only functions when collapsing the menu. <template> <div> <p> <button @click="is ...

Switching FontAwesome Stacks on Hover

I'm facing a challenge with creating a quick animation that replaces an entire span on hover. How can I successfully approach replacing a span on hover? <h1>I am looking to have this element replaced...</h1> <span class="fa-stack fa-lg ...

Tips for showcasing several images with accompanying content once the webpage has finished loading

I am faced with an issue on my PHP website. The website is a social networking platform with numerous images and contents. I am seeking a way to first display only the content to the user, then show the images after they have all finished loading. Addition ...

Is there a way to apply border-radius to the header of a table in Bootstrap 5?

My use of Bootstrap 5 for styling a table has encountered an issue. Even with the border-radius set on the table-dark class, the thead element's border does not change. I am looking for a way to address this problem. Any suggestions? .table-dark { ...