- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Align text and select boxes to the same width with HTML and CSS
When we set the width and height of an element in CSS then often the element appears bigger than the actual size. This is because by default, the padding and border are added to the element’s width and height and then the element is displayed.
The box sizing property includes the padding and border of an element with actual width and height so that the element does not appear bigger than the actual size. The format to use this property is “box-sizing: box-border”
Example
You can try to run the following code to align text and select boxes to the same width −
<html> <head> <style> input, select { width: 250px; border: 2px solid #000; padding: 0; margin: 0; height: 22px; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box; } input { text-indent: 3px; } </style> </head> <body> <input type = "text" value = "Name of Candidate"><br> <select> <option>Select Choice</option> <option>Student</option> <option>Teachers</option> <option>Head</option> </select> </body> </html>
- Related Articles
- How to create custom select boxes with CSS and JavaScript?
- Is it possible to select text boxes with JavaScript?
- Align the text of a document with CSS
- Align the text of a paragraph with CSS
- Align the last line of the text with CSS
- Center image using text-align center with CSS?
- CSS text-align-last property
- How to place text over an image with HTML and CSS?
- How to Justify Text using text-align & text-justify CSS Properties?
- Usage of text-align property in CSS
- Emphasis text and color with CSS
- How to center align text in table cells in HTML?
- How to create a mega menu (full-width dropdown menu in a navigation bar) with HTML and CSS?
- Align flex lines with CSS
- Control the flow and formatting of text with CSS

Advertisements