IT박스

CSS로 입력 및 제출 버튼의 스타일을 지정하는 방법은 무엇입니까?

itboxs 2020. 6. 27. 11:46
반응형

CSS로 입력 및 제출 버튼의 스타일을 지정하는 방법은 무엇입니까?


CSS를 배우고 있습니다. CSS로 입력 및 제출 버튼의 스타일을 지정하는 방법은 무엇입니까?

이런 식으로 만들려고하지만 어떻게 해야할지 모르겠습니다.

<form action="#" method="post">
    Name <input type="text" placeholder="First name"/>
    <input type="text" placeholder="Last name"/>
    Email <input type="text"/>
    Message <input type="textarea"/>
    <input type="submit" value="Send"/>
</form>

여기에 이미지 설명을 입력하십시오


http://jsfiddle.net/vfUvZ/

시작점이 있습니다

CSS :

input[type=text] {
    padding:5px; 
    border:2px solid #ccc; 
    -webkit-border-radius: 5px;
    border-radius: 5px;
}

input[type=text]:focus {
    border-color:#333;
}

input[type=submit] {
    padding:5px 15px; 
    background:#ccc; 
    border:0 none;
    cursor:pointer;
    -webkit-border-radius: 5px;
    border-radius: 5px; 
}

다른 html 요소의 스타일을 지정하는 것처럼 제출 단추의 스타일을 지정하십시오. CSS 속성 선택기를 사용하여 다른 유형의 입력 요소를 타겟팅 할 수 있습니다.

예를 들어 쓸 수 있습니다

input[type=text] {
   /*your styles here.....*/
}
input[type=submit] {
   /*your styles here.....*/
}
textarea{
   /*your styles here.....*/
}

다른 선택기와 결합

input[type=text]:hover {
   /*your styles here.....*/
}
input[type=submit] > p {
   /*your styles here.....*/
}
....

다음은 작동하는 예입니다.


HTML

<input type="submit" name="submit" value="Send" id="submit" />

CSS

#submit {
 color: #fff;
 font-size: 0;
 width: 135px;
 height: 60px;
 border: none;
 margin: 0;
 padding: 0;
 background: #0c0 url(image) 0 0 no-repeat; 
}

대신 사용하는 것이 좋습니다

<input type='submit'>

사용하다

<button type='submit'>

CSS 스타일을 염두에두고 버튼이 소개되었습니다. 이제 그라데이션 배경 이미지를 이미지에 추가하거나 CSS3 그라데이션을 사용하여 스타일을 지정할 수 있습니다.

HTML5 양식 구조에 대한 자세한 내용은 여기를 참조하십시오.

http://www.w3.org/TR/2011/WD-html5-20110525/forms.html

건배! .Pav


For reliability I'd suggest giving class-names, or ids to the elements to style (ideally a class for the text-inputs, since there will presumably be several) and an id to the submit button (though a class would work as well):

<form action="#" method="post">
    <label for="text1">Text 1</label>
    <input type="text" class="textInput" id="text1" />
    <label for="text2">Text 2</label>
    <input type="text" class="textInput" id="text2" />
    <input id="submitBtn" type="submit" />
</form>

With the CSS:

.textInput {
    /* styles the text input elements with this class */
}

#submitBtn {
    /* styles the submit button */
}

For more up-to-date browsers, you can select by attributes (using the same HTML):

.input {
    /* styles all input elements */
}

.input[type="text"] {
     /* styles all inputs with type 'text' */
}

.input[type="submit"] {
     /* styles all inputs with type 'submit' */
}

You could also just use sibling combinators (since the text-inputs to style seem to always follow a label element, and the submit follows a textarea (but this is rather fragile)):

label + input,
label + textarea {
    /* styles input, and textarea, elements that follow a label */
}

input + input,
textarea + input {
    /* would style the submit-button in the above HTML */
}

form element UI is somewhat controlled by browser and operating system, so it is not trivial to style them very reliably in a way that it would look the same in all common browser/OS combinations.

대신 특정 항목이 필요한 경우 양식 가능한 양식 요소를 제공하는 라이브러리를 사용하는 것이 좋습니다. uniform.js 는 그러한 라이브러리 중 하나입니다.


입력 유형을 스타일링 할 때 다음 코드를 사용하십시오.

   input[type=submit] {
    background-color: pink; //Example stlying
    }

사실, 이것도 훌륭합니다.

input[type=submit]{
                 width: 15px;
                 position: absolute;
                 right: 20px;
                 bottom: 20px;
                 background: #09c;
                 color: #fff;
                 font-family: tahoma,geneva,algerian;
                 height: 30px;
                 -webkit-border-radius: 15px;
                 -moz-border-radius: 15px;
                 border-radius: 15px;
                 border: 1px solid #999;
             }

여기에 주어진 답변을 기반 으로이 방법을 사용했습니다.

.likeLink {
    background: none !important;
    color: #3387c4;
    border: none;
    padding: 0 !important;
    font: inherit;
    cursor: pointer;
}
    .likeLink:hover {
        background: none !important;
        color: #25618c;
        border: none;
        padding: 0 !important;
        font: inherit;
        cursor: pointer;
        text-decoration: underline;
    }

HTML

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>CSS3 Button</title>
<link href="style.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>
<div id="container">
<a href="#" class="btn">Push</a>
</div>
</body>
</html>

CSS 스타일링

a.btn {
display: block; width: 250px; height: 60px; padding: 40px 0 0 0; margin: 0 auto;

background: #398525; /* old browsers */
background: -moz-linear-gradient(top, #8DD297 0%, #398525 100%); /* firefox */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#8DD297), color-stop(100%,#398525)); /* webkit */

box-shadow: inset 0px 0px 6px #fff;
-webkit-box-shadow: inset 0px 0px 6px #fff;
border: 1px solid #5ea617;
border-radius: 10px;
}

매우 간단합니다 :

<html>
<head>
<head>
<style type="text/css">
.buttonstyle 
{ 
background: black; 
background-position: 0px -401px; 
border: solid 1px #000000; 
color: #ffffff;
height: 21px;
margin-top: -1px;
padding-bottom: 2px;
}
.buttonstyle:hover {background: white;background-position: 0px -501px;color: #000000; }
</style>
</head>
<body>
<form>
<input class="buttonstyle" type="submit" name="submit" Value="Add Items"/>
</form>
</body>
</html>

이것은 내가 테스트 한 것입니다.

참고 URL : https://stackoverflow.com/questions/17042201/how-to-style-input-and-submit-button-with-css

반응형