Hongmu Notes
Home Language Notes How can I make the label and the input field appear on the same line using Bootstrap?
Language Notes Bootstrap

How can I make the label and the input field appear on the same line using Bootstrap?

How can I make the label and the input field appear on the same line using Bootstrap?

You can place the label and the input field on the same line by wrapping them together in a single line. You can use CSS styling to layout the label and the input field so that they appear in the same row.

Here is an example HTML code snippet where the `label` and `input` elements are placed on the same line:

<div class="form-group">  
  <label for="phone" class="form-label">手机号:</label>  
  <input type="tel" class="form-control" placeholder="请输入手机号" id="phone" name="phone"  
    pattern="^1[3|4|5|6|7|8|9][0-9]{9}$" required>  
</div>

In the above code, we have used one.divWrap the `label` and `input` elements within a container, then use CSS styles to layout them. You can arrange them in the same line using the following CSS styles:

.form-group {  
  display: flex;  
  flex-direction: column;  
}

.form-label {  
  margin-bottom: 10px;  
}

.form-control {  
  padding: 10px;  
  border: none;  
  border-bottom: 2px solid #ccc;  
}

In the above CSS style, we have useddisplay: flexUse the `attribute` to wrap the `label` and `input` elements within a `flex` container, and then apply it.flex-direction: columnUse the `attribute` to vertically arrange containers. We have also added some styling to the `label` and `input` elements to make them easier to identify and more readable.

When using a Flex container, you can use it.margin-bottomApply a bottom border to the `label` attribute – use this.paddingApply padding to the `input` attribute and use it.border-bottomApply a bottom border to the `input` attribute.

微信赞赏

WeChat

支付宝赞赏

Alipay

✍️ Author: Hong Mu

webmaster · Thanks for reading, stay tuned for more exciting content

Author homepage View home page →

Related articles

Bootstrap5 container document translation

Bootstrap5 container document translation Language Notes Bootstrap

Containers are the fundamental building blocks of Bootstrap; they are used to contain, fill, and align content within a specific device or viewport. Containers are the most basic layout elements in Bootstrap and are essential when using our default grid system. They are used to hold, fill, and (sometimes) center content. While containers can be nested, most layouts do not require nested containers. Bootstrap comes with three types of containers...
👁 189
Use of bootstrap5 accordion

Use of bootstrap5 accordion Language Notes Bootstrap

Parent Container: Class name: `accordion`; ID: `accordionExample` – The `data-bs-parent` attribute of the child accordion container must match the ID of the parent container. Child Item: Class name: `accordion-item`; Child Item Header: Class name: `Accordion-header`; ID: `headingOne`; The `aria-label` attribute of the child item content container...
👁 174
Summary of commonly used Bootstrap 5 form `pattern` attribute

Summary of commonly used Bootstrap 5 form `pattern` attribute Language Notes Bootstrap

Summary of commonly used Bootstrap 5 form `pattern` attribute: **Text input field validation**: Validates whether the value entered into a text input field matches a specified regular expression. For example, `pattern= "[a-zA-Z]{3,}$" ` ensures that the string contains at least 3 letters, and the last character cannot be a digit or a space. **Password input field validation**: Validates whether the value entered into a password input field matches a specified regular expression. For example,...
👁 338

Recommended reading

PHP serialize() function

PHP serialize() function Language Notes PHP

The `serialize()` function serializes an object or an array and returns a string. After serializing an object, you can easily pass it to other parts of your code that require it, without any changes to its type or structure. To convert a serialized string back into a PHP value, you can use the ` unserialize()` function. PHP version requirement: PHP 4, PH...
👁 148
(Adaptive mobile version) Web development company – PBootCMS template; IT and internet design company – Website source code download – 0391

(Adaptive mobile version) Web development company – PBootCMS template; IT and internet design company – Website source code download – 0391 Practical Collection pbootcms Template

This set consists of PbootCMS website templates designed by PbootCMS – an adaptive mobile-friendly website development and IT internet design company. The creative, tech-driven design style is ideal for showcasing website design projects, development cases, and team expertise. It helps internet companies present their professional image online and expand their business reach. Template Display | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: admin | Extraction Password: www.4s5.cn – Related...
👁 52
(Adaptive Mobile Version) CNC Lathe Website Template | CNC Machine Tool Website Source Code Download – 1119

(Adaptive Mobile Version) CNC Lathe Website Template | CNC Machine Tool Website Source Code Download – 1119 Practical Collection pbootcms Template

A CNC lathe and CNC machine tool website template compatible with both PC and WAP devices. Featuring a professional, tech-oriented design, this template is ideal for showcasing CNC machine tool products, machining services, and technical expertise. It enables machine tool manufacturing enterprises to present their products online and attract potential manufacturing clients. Template Display | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: admin | Extraction Password: www.4s5.cn – Related...
👁 28
Responsive exercise bike and fitness bicycle website template 0698

Responsive exercise bike and fitness bicycle website template 0698 Practical Collection Yiyou template

An eyouCMS responsive website template designed for the sports bike, fitness, and bicycle industries. Its dynamic, sports-oriented design is ideal for showcasing bicycle products, fitness equipment, sports gear, and brand stories. It helps bike and sports brand owners effectively present their products online and attract cycling enthusiasts. Template Overview | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Common Questions About Installing EasyCMS...
👁 51
PHP implode() function

PHP implode() function Language Notes PHP

The function combines array elements into a single string: <code>PHP arr = array('Hello', 'World!', 'I', 'love', 'Shanghai!'); echo implode(", arr);</code>
👁 175