Home > Web Front-end > HTML Tutorial > Align text and select box to same width using HTML and CSS

Align text and select box to same width using HTML and CSS

WBOY
Release: 2023-09-04 22:37:05
forward
940 people have browsed it

Align text and select box to same width using HTML and CSS

When we set the width and height of an element in CSS, the element will often appear larger than its actual size. This is because by default, padding and borders are added to the element's width and height before the element is displayed.

Box sizing properties include the actual element's padding and borders. Width and height so that the element doesn't look larger than it actually is. Use this property in the format "box-sizing: box-border"

Example

You can try running the following code to align text and select boxes of 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>
Copy after login

The above is the detailed content of Align text and select box to same width using HTML and CSS. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template