首頁 web前端 css教學 如何使輸入欄位填滿固定寬度容器中的剩餘空間?

如何使輸入欄位填滿固定寬度容器中的剩餘空間?

Nov 15, 2024 am 11:18 AM

How to Make an Input Field Fill Remaining Space in a Fixed-Width Container?

Achieving Fluid Width for Input Elements within Fixed-Width Containers

Question:

How can an input field be styled to occupy the available remaining space within its fixed-width container, without text wrapping or the need to determine label size beforehand?

Answer:

To achieve this effect, consider the following:

  1. Wrapper Span: Wrap the input field within a span element set to display: block.
  2. Positional Order: Place the "button" (or other elements) before the input field.
  3. Floating: Float the "button" (or other elements) to the right to allow the input field to fill the remaining space.

Example Code:

1

2

3

4

<form method="post">

  <button>Search</button>

  <span><input type="text" title="Search" /></span>

</form>

登入後複製

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

form {

  width: 500px;

  overflow: hidden;

  background-color: yellow;

}

 

input {

  width: 100%;

}

 

span {

  display: block;

  overflow: hidden;

  padding-right: 10px;

}

 

button {

  float: right;

}

登入後複製

以上是如何使輸入欄位填滿固定寬度容器中的剩餘空間?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱門文章

倉庫:如何復興隊友
3 週前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
1 週前 By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒險:如何獲得巨型種子
3 週前 By 尊渡假赌尊渡假赌尊渡假赌

熱門文章

倉庫:如何復興隊友
3 週前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
1 週前 By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒險:如何獲得巨型種子
3 週前 By 尊渡假赌尊渡假赌尊渡假赌

熱門文章標籤

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

將框陰影添加到WordPress塊和元素 將框陰影添加到WordPress塊和元素 Mar 09, 2025 pm 12:53 PM

將框陰影添加到WordPress塊和元素

使用智能表單框架創建JavaScript聯繫表格 使用智能表單框架創建JavaScript聯繫表格 Mar 07, 2025 am 11:33 AM

使用智能表單框架創建JavaScript聯繫表格

使用GraphQL緩存 使用GraphQL緩存 Mar 19, 2025 am 09:36 AM

使用GraphQL緩存

揭開屏幕讀取器的神秘面紗:可訪問的表格和最佳實踐 揭開屏幕讀取器的神秘面紗:可訪問的表格和最佳實踐 Mar 08, 2025 am 09:45 AM

揭開屏幕讀取器的神秘面紗:可訪問的表格和最佳實踐

使您的第一個自定義苗條過渡 使您的第一個自定義苗條過渡 Mar 15, 2025 am 11:08 AM

使您的第一個自定義苗條過渡

比較5個最佳的PHP形式構建器(和3個免費腳本) 比較5個最佳的PHP形式構建器(和3個免費腳本) Mar 04, 2025 am 10:22 AM

比較5個最佳的PHP形式構建器(和3個免費腳本)

展示,不要說 展示,不要說 Mar 16, 2025 am 11:49 AM

展示,不要說

NPM命令是什麼? NPM命令是什麼? Mar 15, 2025 am 11:36 AM

NPM命令是什麼?

See all articles