Skip to content

Instantly share code, notes, and snippets.

@devlights
Created April 3, 2013 01:37
Show Gist options
  • Save devlights/5297764 to your computer and use it in GitHub Desktop.
Save devlights/5297764 to your computer and use it in GitHub Desktop.
htmlとjavascriptで3点リーダー表示 (text-overflow: ellipsis)
<html>
<head>
<meta charset="utf-8">
<title>3点リーダー</title>
</head>
<body>
<div id="container">
<span>日本語での文字列1文字列2</span>
</div>
<style scoped>
#container {
margin-top: 10em;
margin-left: auto;
margin-right: auto;
width: 10em;
height: auto;
border: thin solid #000;
font-size: large;
/* 以下の3つを指定しないと3点リーダーにならない */
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
</style>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script>
$(function() {
var $span = $("#container span");
$span.attr("title", $span.text());
});
</script>
</body>
</html>
@devlights
Copy link
Author

対応しているブラウザ
https://developer.mozilla.org/ja/docs/CSS/text-overflow

IEは6.0からFirefoxは7.0から対応している。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment