การตั้งค่าความกว้างของ 2 ส่วนประกอบจากนานที่สุดข้อความ

0

คำถาม

ฉันพยายามหาหนทางที่ดีที่สุดที่จะทำให้ 2 ส่วนประกอบไปในรูขนาดเดียวกันดูจากข้อความของที่ใหญ่กว่าองค์

German Text - same size

French Text example 2 different sizes

ก็เอา 2 ข้อความรายการ"ouverture เดอวาระงาน"และ"xyz"(ใช้สำหรับคำสั้นตัวอย่าง)ดังนั้นทั้งสองปุ่มเดียวกับขนาดและเป็นใหญ่พอที่จะรับมือกับการที่ใหญ่กว่าของ 2 ข้อความ inputs.

มันสำเร็จได้ผ่านทางจาวาสคริปต์,สี่เหลี่ยม,อะไรก็ตาม

angular javascript typescript
2021-11-24 00:36:42
3

คำตอบที่ดีที่สุด

1

คุณสามารถทำมันกับ CSS grids:

.button-panel {
  display: inline-grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  column-gap: 10px;
}
<div class="button-panel">
  <button>A very long button name</button>
  <button>Ok</button>
</div>

2021-11-24 04:42:36
1

คุณสามารถหาปุ่มกับที่ยิ่งใหญ่ offsetWidthงั้นใช้มันเพื่ออื่นปุ่มเป็น width รูปแบบพื้นที่ของเขา

const buttons = document.querySelectorAll('button')

if (buttons[1].offsetWidth > buttons[0].offsetWidth) {
  buttons[0].style.width = buttons[1].offsetWidth + 'px';
} else {
  buttons[1].style.width = buttons[0].offsetWidth + 'px';
}
<button>Hello World!</button>
<button>Spectric</button>

ถ้าคุณต้อง ultiple ปุ่มเป็นมากก scalable ทางออก:

const buttons = document.querySelectorAll('button')

const biggestWidth = [...buttons].reduce((a,b) => a = b.offsetWidth > a ? b.offsetWidth + 1 : a, 0)

buttons.forEach(e => e.style.width = biggestWidth + 'px')
<button>Hello World!</button>
<button>Spectric</button>

2021-11-24 00:56:39
0

คุณสามารถตั้งค่าทรัพย์สินของมินความกว้างอยู่ที่ปุ่มององค์ ด้วยการทำเรื่องนี้เล็กลงปุ่มจะถูกของเดียวกับความกว้างเหมือนที่ใหญ่กว่าหนึ่ง

2021-11-24 00:50:55

ในภาษาอื่นๆ

หน้านี้อยู่ในภาษาอื่นๆ

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................

ดังอยู่ในนี้หมวดหมู่

ดังคำถามอยู่ในนี้หมวดหมู่