Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [CSS]Zdanie od dużej litery!
Forum PHP.pl > Forum > Przedszkole
woxala123
Witam
Jak można zrobić w CSS by zdanie zaczynało się od dużej litery. Znam już te wszystkie triki typu text-transform: none|capitalize|uppercase|lowercase|initial|inherit;
Ale one nie zmieniaja pierwszej litery w zdaniu.
woxala123
Viking jaki selector zastosować?

to zrobiłem tak
p:first-letter {
text-transform:capitalize;
}

No tak ale jak zrobić by w polu gdy zaczynam pisac tekst zaczynał się od dużej litery.
com
Co masz na myśli mówiąc żeby zdanie? Masz tekst nie pisany poprawnie i chcesz w css to zmieniać?
woxala123
Masz formularz np: komentarza i chcesz by ktoś jak pisze zaczynał ten tekst automatycznie od dużej litery, mimi toze nie zaczynał tekstu od dużej litery.
com
No to zmiana w css nic Ci nie da bo to tylko wizualny efekt, a do bazy itak trafi jak napisał wink.gif
woxala123
Okey powiem tak jak dam takie coś text-transform:capitalize; to w polu owszem zaczyna się od dużej litery, tylko nie chcę by dalej pisał następny wyraz z duzej litery.
Star
To może tak komentarz przepuścić przez ucfirst? smile.gif
http://php.net/manual/en/function.ucfirst.php

No a po stronie klienta można to ogarnąć przez JS:
  1. var text = document.getElementById("id").value;
  2. text.charAt(0).toUpperCase();
Star
Wkleiles kod js, ja bym dodał zdarzenie onchange to INPUTa bądź TEXTAREA :

  1. <input type="text" name="komentarz" value="" onkeyup="this.value.charAt(0).toUpperCase();">
woxala123
Cały kod wygląda tak
To gdzie byś to zdarzenie umieścił.

  1. <?php
  2. $username = $_SESSION['MM_Username'];
  3. ?>
  4. <!doctype html>
  5. <html>
  6. <head>
  7. <meta charset="utf-8">
  8. <style>
  9. p:first-letter {
  10. text-transform:capitalize;
  11. }
  12. </style>
  13. <title>Chat</title>
  14. <link rel="stylesheet" type="text/css" href="reset.css" media="screen">
  15. <style type="text/css">
  16. body {
  17. font-family: 'Open Sans';
  18. }
  19.  
  20. * {
  21. box-sizing: border-box;
  22. }
  23.  
  24. .chatContainer {
  25. width: 100%;
  26. height: 550px;
  27. border: 3px solid #eee;
  28. }
  29.  
  30. .p:first-letter {
  31. text-transform:ucwords,capitalize;
  32.  
  33. }
  34.  
  35. .chatContainer > .chatHeader {
  36. width: 100%;
  37. background: #fff;
  38. padding: 5px;
  39. border-bottom: 1px solid #ddd;
  40. }
  41.  
  42. .chatContainer > .chatHeader h3 {
  43. font-weight: 400;
  44. color: #666;
  45. }
  46.  
  47. .chatContainer > .chatMessages {
  48. height: 470px;
  49. border-bottom: 1px solid #ddd;
  50. overflow-y: scroll;
  51. }
  52.  
  53. .chatContainer > .chatBottom form input[type="submit"] {
  54. padding: 6px;
  55. background: #fff;
  56. border: 1px solid #ddd;
  57. cursor: pointer;
  58. }
  59.  
  60. .chatContainer > .chatBottom form input[type="text"] {
  61. width: 85%;
  62. padding: 8px 8px 8px 12px;
  63. border: 1px solid #ddd;
  64. border-radius: 5px;
  65. margin: 5px;
  66. height: 40px;
  67. }
  68.  
  69. .chatMessages li:nth-child(2n) {
  70. background: #eeeeee;
  71. }
  72.  
  73. .msg {
  74. list-style: none;
  75. border-bottom: 1px solid #ddd;
  76. padding: 5px;
  77. color: #222222;
  78. }
  79. </style>
  80. <body>
  81.  
  82. <div class="chatContainer">
  83. <div class="chatHeader">
  84. <h3>Witaj <?php echo ucwords($username); ?></h3>
  85. </div>
  86. <div class="chatMessages"></div>
  87. <div class="chatBottom">
  88. <form action="#" onSubmit='return false;' id="chatForm">
  89. <p class="chatBottom p">
  90. <input type="hidden" id="username" value="<?php echo $username; ?>"/>
  91. <input type="text" username="text" id="text" value="" placeholder="Wpisz wiadomość" />
  92. <input type="submit" username="submit" value="Wyślij" />
  93. </p>
  94. </form>
  95. </div>
  96. </div>
  97.  
  98.  
  99.  
  100. <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
  101. <script>
  102. $(document).ready(function(){
  103. $(document).on('submit', '#chatForm', function(){
  104. var text = $.trim($("#text").val());
  105. var username = $.trim($("#username").val());
  106.  
  107.  
  108. if(text != "" && username != "") {
  109. $.post('ChatPoster.php', {text: text, username: username}, function(data){
  110. $(".chatMessages").append(data);
  111.  
  112. $(".chatMessages").scrollTop($(".chatMessages")[0].scrollHeight);
  113. $("#text").val('');
  114. });
  115. } else {
  116. alert("Musisz wpisac wiadomość!");
  117. }
  118. });
  119.  
  120.  
  121.  
  122. function getMessages() {
  123. $.get('GetMessages.php', function(data){
  124. var amount = $(".chatMessages li:last-child").attr('id');
  125. $(".chatMessages").html(data);
  126. var countMsg = data.split('<li').length - 1;
  127. array = [countMsg, amount];
  128. });
  129. return array;
  130. }
  131.  
  132.  
  133. setInterval(function(){
  134. var num = getMessages();
  135. if(num[0] > num[1]) {
  136. $(".chatMessages").scrollTop($(".chatMessages")[0].scrollHeight);
  137. }
  138. },1000);
  139.  
  140.  
  141. });
  142. </script>
  143. </body>
  144. </html>
  145.  
Star
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <style>
  6. p:first-letter {
  7. text-transform:capitalize;
  8. }
  9. </style>
  10. <title>Chat</title>
  11. <link rel="stylesheet" type="text/css" href="reset.css" media="screen">
  12. <style type="text/css">
  13. body {
  14. font-family: 'Open Sans';
  15. }
  16.  
  17. * {
  18. box-sizing: border-box;
  19. }
  20.  
  21. .chatContainer {
  22. width: 100%;
  23. height: 550px;
  24. border: 3px solid #eee;
  25. }
  26.  
  27. .p:first-letter {
  28. text-transform:ucwords,capitalize;
  29.  
  30. }
  31.  
  32. .chatContainer > .chatHeader {
  33. width: 100%;
  34. background: #fff;
  35. padding: 5px;
  36. border-bottom: 1px solid #ddd;
  37. }
  38.  
  39. .chatContainer > .chatHeader h3 {
  40. font-weight: 400;
  41. color: #666;
  42. }
  43.  
  44. .chatContainer > .chatMessages {
  45. height: 470px;
  46. border-bottom: 1px solid #ddd;
  47. overflow-y: scroll;
  48. }
  49.  
  50. .chatContainer > .chatBottom form input[type="submit"] {
  51. padding: 6px;
  52. background: #fff;
  53. border: 1px solid #ddd;
  54. cursor: pointer;
  55. }
  56.  
  57. .chatContainer > .chatBottom form input[type="text"] {
  58. width: 85%;
  59. padding: 8px 8px 8px 12px;
  60. border: 1px solid #ddd;
  61. border-radius: 5px;
  62. margin: 5px;
  63. height: 40px;
  64. }
  65.  
  66. .chatMessages li:nth-child(2n) {
  67. background: #eeeeee;
  68. }
  69.  
  70. .msg {
  71. list-style: none;
  72. border-bottom: 1px solid #ddd;
  73. padding: 5px;
  74. color: #222222;
  75. }
  76. </style>
  77. <body>
  78.  
  79. <div class="chatContainer">
  80. <div class="chatHeader">
  81. <h3>Witaj </h3>
  82. </div>
  83. <div class="chatMessages"></div>
  84. <div class="chatBottom">
  85. <form action="#" onSubmit='return false;' id="chatForm">
  86. <p class="chatBottom p">
  87. <input type="hidden" id="username" value=""/>
  88. <input type="text" username="text" id="text" value="" placeholder="Wpisz wiadomość" />
  89. <input type="submit" username="submit" value="Wyślij" />
  90. </p>
  91. </form>
  92. </div>
  93. </div>
  94.  
  95.  
  96.  
  97. <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
  98. <script>
  99. $(document).ready(function(){
  100. $(document).on('submit', '#chatForm', function(){
  101. var text = $.trim($("#text").val());
  102. var username = $.trim($("#username").val());
  103.  
  104.  
  105. if(text != "" && username != "") {
  106. $.post('ChatPoster.php', {text: text, username: username}, function(data){
  107. $(".chatMessages").append(data);
  108.  
  109. $(".chatMessages").scrollTop($(".chatMessages")[0].scrollHeight);
  110. $("#text").val('');
  111. });
  112. } else {
  113. alert("Musisz wpisac wiadomość!");
  114. }
  115. });
  116.  
  117. $(document).on('keyup', '#text', function(){
  118. var text = $("#text").val();
  119. String.prototype.ucfirst = function()
  120. {
  121. return this.charAt(0).toUpperCase() + this.substr(1);
  122. }
  123. $("#text").val(text.ucfirst());
  124.  
  125. });
  126.  
  127.  
  128.  
  129. function getMessages() {
  130. $.get('GetMessages.php', function(data){
  131. var amount = $(".chatMessages li:last-child").attr('id');
  132. $(".chatMessages").html(data);
  133. var countMsg = data.split('<li').length - 1;
  134. array = [countMsg, amount];
  135. });
  136. return array;
  137. }
  138.  
  139.  
  140. setInterval(function(){
  141. var num = getMessages();
  142. if(num[0] > num[1]) {
  143. $(".chatMessages").scrollTop($(".chatMessages")[0].scrollHeight);
  144. }
  145. },1000);
  146.  
  147.  
  148. });
  149. </script>
  150. </body>
  151. </html>


Usunalem kod PHP ,musisz dodac spowrotem

u mnie ladnie zaczyna zdanie z duzej litery pomimo klikania z malej
woxala123
Wszystko by fajnie działało gdybym mógł wysłać wiadomość. Ponieważ musi on widzieć i tekst i usera. Co jest nie tak?
Okey zrobiłęm że zostawiłem stary kod a dodałem tylko twój skrypt i wygląda to tak ostatecznie::
  1. <?php
  2. $username = $_SESSION['MM_Username'];
  3. ?>
  4. <!doctype html>
  5. <html>
  6. <head>
  7. <meta charset="utf-8">
  8. <style>
  9. p:first-letter {
  10. text-transform:capitalize;
  11. }
  12. </style>
  13. <title>Chat</title>
  14. <link rel="stylesheet" type="text/css" href="reset.css" media="screen">
  15. <style type="text/css">
  16. body {
  17. font-family: 'Open Sans';
  18. }
  19.  
  20. * {
  21. box-sizing: border-box;
  22. }
  23.  
  24. .chatContainer {
  25. width: 100%;
  26. height: 550px;
  27. border: 3px solid #eee;
  28. }
  29.  
  30. .p:first-letter {
  31. text-transform:ucwords,capitalize;
  32.  
  33. }
  34.  
  35. .chatContainer > .chatHeader {
  36. width: 100%;
  37. background: #fff;
  38. padding: 5px;
  39. border-bottom: 1px solid #ddd;
  40. }
  41.  
  42. .chatContainer > .chatHeader h3 {
  43. font-weight: 400;
  44. color: #666;
  45. }
  46.  
  47. .chatContainer > .chatMessages {
  48. height: 470px;
  49. border-bottom: 1px solid #ddd;
  50. overflow-y: scroll;
  51. }
  52.  
  53. .chatContainer > .chatBottom form input[type="submit"] {
  54. padding: 6px;
  55. background: #fff;
  56. border: 1px solid #ddd;
  57. cursor: pointer;
  58. }
  59.  
  60. .chatContainer > .chatBottom form input[type="text"] {
  61. width: 85%;
  62. padding: 8px 8px 8px 12px;
  63. border: 1px solid #ddd;
  64. border-radius: 5px;
  65. margin: 5px;
  66. height: 40px;
  67. }
  68.  
  69. .chatMessages li:nth-child(2n) {
  70. background: #eeeeee;
  71. }
  72.  
  73. .msg {
  74. list-style: none;
  75. border-bottom: 1px solid #ddd;
  76. padding: 5px;
  77. color: #222222;
  78. }
  79. </style>
  80. <body>
  81.  
  82. <div class="chatContainer">
  83. <div class="chatHeader">
  84. <h3>Witaj <?php echo ucwords($username); ?></h3>
  85. </div>
  86. <div class="chatMessages"></div>
  87. <div class="chatBottom">
  88. <form action="#" onSubmit='return false;' id="chatForm">
  89. <p class="chatBottom p">
  90. <input type="hidden" id="username" value="<?php echo $username; ?>"/>
  91. <input type="text" username="text" id="text" value="" placeholder="Wpisz wiadomość" />
  92. <input type="submit" username="submit" value="Wyślij" />
  93. </p>
  94. </form>
  95. </div>
  96. </div>
  97.  
  98.  
  99.  
  100. <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
  101. <script>
  102. $(document).ready(function(){
  103. $(document).on('submit', '#chatForm', function(){
  104. var text = $.trim($("#text").val());
  105. var username = $.trim($("#username").val());
  106.  
  107.  
  108. if(text != "" && username != "") {
  109. $.post('ChatPoster.php', {text: text, username: username}, function(data){
  110. $(".chatMessages").append(data);
  111.  
  112. $(".chatMessages").scrollTop($(".chatMessages")[0].scrollHeight);
  113. $("#text").val('');
  114. });
  115. } else {
  116. alert("Musisz wpisac wiadomość!");
  117. }
  118. });
  119.  
  120. $(document).on('keyup', '#text', function(){
  121. var text = $("#text").val();
  122. String.prototype.ucfirst = function()
  123. {
  124. return this.charAt(0).toUpperCase() + this.substr(1);
  125. }
  126. $("#text").val(text.ucfirst());
  127.  
  128. });
  129.  
  130. function getMessages() {
  131. $.get('GetMessages.php', function(data){
  132. var amount = $(".chatMessages li:last-child").attr('id');
  133. $(".chatMessages").html(data);
  134. var countMsg = data.split('<li').length - 1;
  135. array = [countMsg, amount];
  136. });
  137. return array;
  138. }
  139.  
  140.  
  141. setInterval(function(){
  142. var num = getMessages();
  143. if(num[0] > num[1]) {
  144. $(".chatMessages").scrollTop($(".chatMessages")[0].scrollHeight);
  145. }
  146. },1000);
  147.  
  148.  
  149. });
  150. </script>
  151. </body>
  152. </html>
  153.  
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.