2016-07-14 8 views
0

を使用して、警告メッセージボックスを作成する - This is what i want私は、まさにこのようにする必要があり、CSSを使用して、必要なフィールドの警告メッセージボックスを作成したいCSS

これまでのところ、私はここthis- https://jsfiddle.net/payalsuthar/352k4ope/ のように、この何かを達成したことは私ですここでは、HTMLコード -

Name:<input type="text" placeholder="name" id="name"><br> 
<div id="errname"><p id="sym">!</p>Please fill out this field.</div> 

Address:<textarea></textarea> 
<input type="submit" value="submit" /> 

は私のcssである -

#errname{ 
    border:1px solid orange; 
    border-radius:4px; 
    width:250px; 
    margin-top=100px; 
    background-color:white; 
    font-size:15px; 
    padding:10px; 
} 
#sym{ 
    width:18px; 
    text-align:center; 
    background-color:darkorange; 
    color:white; 
    font-weight:bold; 
    font-size:14px; 
    border:1px solid white; 
} 

しかし、私は、それはまったく同じになりたいです上記のイメージは、次のフィールドと重複していて、上記のイメージと同じ位置に表示されるかどうかは気にしません。これはhtmlの必須のフィールドバリデーターメッセージボックスですが、私とはうまく動作しませんそのようなものを作成します。 ありがとうございます。

+2

を試してみてください、しかし、満たされていない。あなたはそれを使うことができない理由はありますか? –

+0

...また、ここでの質問は何ですか?私はこれが複数の重複であることを見ることができます。 –

+0

私はphpデスクトップクロムアプリケーションでそれを使用しようとしましたが、それは完全に機能しています。すべてのフィールドが満たされていない限りフォームを送信させませんが、唯一の問題はメッセージボックスを表示しないということです@ RoryMcCrossan –

答えて

0

何を示してきたことは `required`属性が設定されているときにChromeで表示されている標準のツールチップでこのhttps://jsfiddle.net/352k4ope/4/

#name { 
    position: relative; 
} 

#name::before { 
    position: absolute; 
    top: 20px; 
    left: 60px; 
    content: ''; 
    display: block; 
    width: 0; 
    height: 0; 
    line-height: 0; 
    font-size: 0; 
    border-left: 8px solid transparent; 
    border-right: 8px solid transparent; 

    border-bottom: 10px solid white; 
} 

#name::after { 
    content: url('http://67.media.tumblr.com/fdeec9480199afb3c6ed9c24b2aec9c5/tumblr_oaayc9r25Z1vaudwko1_75sq.png')' Please fill out this field.'; 
    font-family: arial; 
    font-size: 14px; 
    line-height: 50px; 
    padding: 0 10px; 
    vertical-align: top; 
    width: 170px; 
    height: 50px; 
    position: absolute; 
    background-color: white; 
    top: 30px; 
    left: 50px; 
} 
+0

これはまさに私が欲しかったのですが、唯一の問題はそのトライアングルと一緒にブロック全体にどのようにボーダーを追加するのかということです。@ Mark Pereraを助けてくれれば大きな助けになります。 –

+0

申し訳ありませんが、三角形が境界線であるため、三角形ではなく、ボックスに罫線を追加できます。 https://jsfiddle.net/352k4ope/7/ –

+0

を参照してください。トライアングルは境界です –

1

私はCSSのヘルプを求めていると思います。 代わりのpタグを使用しては

#sym { 
background-color: darkorange; 
color: white; 
font-weight: bold; 
font-size: 14px; 
border: 1px solid white; 
padding: 2px 5px 2px 5px; 
margin-right: 8px; 
} 

次のCSSでspanを使用しようと編集

私はスリカンス・レッディで答えからCSSを使用し、ここにあなたの更新jsfiddleでいます。 https://jsfiddle.net/352k4ope/3/

編集2

は白い三角形の周りにオレンジ色の境界線を追加しました。ここで https://jsfiddle.net/352k4ope/5/

+0

ありがとうございますが、私はそのオレンジ色に問題があります。その三角形の中に詰め込まれています。色が白で、境界線がオレンジ色になっています。@ Hitesh Riziya @ Hitesh Riziya –

+1

@payal_sutharそこに画像を使うことができます。ちょうどそのCSSを調整してください。 – hriziya

+1

@payal_suthar check編集2今すぐ、それはあなたのために大丈夫でしょう:) – hriziya

1

ソリューション....

のCss

.input-block { 
    position: relative; 
} 
.error-block { 
    position: absolute; 
    top: 100%; 
    left: 50px; 
    border:1px solid orange; 
    border-radius:4px; 
    width:250px; 
    background-color:white; 
    font-size:14px; 
    padding:10px; 
} 
.error-block::before { 
    content: ''; 
    position: absolute; 
    top: -20px; 
    left: 20px; 
    width: 0; 
    height: 0; 
    border-style: solid; 
    border-width: 10px; 
    border-color: transparent transparent orange; 
} 
.error-icon { 
    width:18px; 
    text-align:center; 
    background-color:darkorange; 
    color:white; 
    font-weight:bold; 
    font-size:14px; 
} 

Htmlの

<div class="input-block"> 
    Name:<input type="text" placeholder="name" id="name"> 
    <div class="error-block"><span class="error-icon">!</span>Please fill out this field.</div> 
</div> 
+0

..おかげで大いに私を助けました.... Stackoverflowは、他人を助ける準備ができているあなたのような人が必要です... –

0

はこの1つ試してみてください:

HTML:

<form> 
    <ul class="errorMessages"></ul> 

    <div> 
     <label for="name">Name:</label> 
     <input id="name" type="text" required> 
    </div> 

    <div> 
     <label for="comments">Address:</label> 
     <textarea id="comments" required></textarea> 
    </div> 

    <div class="buttons"> 
     <button>Submit</button> 
    </div> 
</form> 

のjQuery

var createAllErrors = function() { 
      var form = $(this), 
       errorList = $("ul.errorMessages", form); 

      var showAllErrorMessages = function() { 
       errorList.empty(); 

       // Find all invalid fields within the form. 
       var invalidFields = form.find(":invalid").each(function(index, node) { 

        // Find the field's corresponding label 
        var label = $("label[for=" + node.id + "] "), 
         // Opera incorrectly does not fill the validationMessage property. 
         message = node.validationMessage || 'Invalid value.'; 

        errorList 
         .show() 
         .append("<li><span>" + label.html() + "</span> " + message + "</li>"); 
       }); 
      }; 

      // Support Safari 
      form.on("submit", function(event) { 
       if (this.checkValidity && !this.checkValidity()) { 
        $(this).find(":invalid").first().focus(); 
        event.preventDefault(); 
       } 
      }); 

      $("input[type=submit], button:not([type=button])", form) 
       .on("click", showAllErrorMessages); 

      $("input", form).on("keypress", function(event) { 
       var type = $(this).attr("type"); 
       if (/date|email|month|number|search|tel|text|time|url|week/.test (type) 
        && event.keyCode == 13) { 
        showAllErrorMessages(); 
       } 
      }); 
     }; 

     $("form").each(createAllErrors); 

DEMO HERE

+0

..ありがとう..でも、これは私が使用しているアプリケーションでは動作しません..何かのお返事ありがとう.. –

+0

あなたは歓迎です。@ payal_suthar –

+0

サー.. ???私は女性です.. @ Ivin Raj –

関連する問題