LoginSignup
1
0

More than 1 year has passed since last update.

CSSで文字数をカウントして、幅を100%使い切る

Posted at

CSSって、文字数カウントできないんです。

それなら、文字数をカウントできるようにすればよいのです。

test.css
.test {
	width: 95w;
}

この95wの大きさの中に、
例えば、5文字を
もしくは25文字を可能な限り大きな可変で文字で1行でいれなければなりませんでした。

答えはこれしかなかったです。

test.php
	$plength=mb_strlen($title);
	$pspace=".1rem";

	if($plength<6) {
		$pspace=(6 - $plength) * 1 . "rem";
		$plength=6;
	}

	// 一応、body の適当など真ん中に style があっても認識はしてくれます
	echo '<style>';
			echo 'section.head h2 div p {';
				echo 'font-size:calc(30vw/'.$plength.');';
			echo '}';
			echo '@media (min-width: 991px){';
				echo 'section.head h2 div p {';
					echo 'letter-spacing:' . $pspace . ';';
				echo '}';
					echo 'letter-spacing:' . $ispace . ';';
				echo '}';
			echo '}';
	echo '</style>';
1
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0