2010-01-25 2 views
5

캡을 초기화하기 위해서 모두 대문자로 변환 (이 브라우저 별 CSS 가능) 만 처음에 예를 들어 대문자로 말을 모두 대문자로 텍스트를 변환 :에만 CSS를 사용하는 방법이 있다면 궁금 해서요

I Yell With My Keyboard

편집 : I YELL WITH MY KEYBOARD

가 변환 될 것입니다 나는 내 질문에 충분히 명확하지 않았다 실현, 텍스트를 소문자 처음 대문자로하지 입력 된, 텍스 t-transform : 이처럼 입력 된 데이터에는 capitalize가 작동하지 않습니다.

답변

8

텍스트 변환을 위해 CSS로 할 수있는 몇 가지 방법이 있습니다.

.Capitalize 
{ text-transform: capitalize } 

.Uppercase 
{ text-transform: uppercase } 

.Lowercase 
{ text-transform: lowercase } 

.Nothing 
{ text-transform: none } 

불행히도 카멜 케이스 텍스트 변환이 없습니다.

항상 JavaScript를 사용하여 텍스트를 적절히 변환하거나 PHP 또는 ASP와 같은 스크립팅 언어를 사용하는 경우 JavaScript로 변경할 수 있습니다. 대신 CSS로 변환의에서 온다 내가 텍스트를 포맷,이 길을가는 결국해야 할거야

function strtocamel($str, $capitalizeFirst = true, $allowed = 'A-Za-z0-9') { 
    return preg_replace(
     array(
      '/([A-Z][a-z])/e', // all occurances of caps followed by lowers 
      '/([a-zA-Z])([a-zA-Z]*)/e', // all occurances of words w/ first char captured separately 
      '/[^'.$allowed.']+/e', // all non allowed chars (non alpha numerics, by default) 
      '/^([a-zA-Z])/e' // first alpha char 
     ), 
     array(
      '" ".$1', // add spaces 
      'strtoupper("$1").strtolower("$2")', // capitalize first, lower the rest 
      '', // delete undesired chars 
      'strto'.($capitalizeFirst ? 'upper' : 'lower').'("$1")' // force first char to upper or lower 
     ), 
     $str 
    ); 
} 
+0

:

다음은 strtoupper PHP의 문서 페이지에서 촬영 한 예입니다. –

+0

도움이된다는 기쁜 마음. :) – David

관련 문제