0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Webブラウザ上で直接、コンテンツを編集できるcontenteditable属性

Posted at

Notion内で、Webブラウザ上で直接、文字を編集できるのを見て、どのような仕組みで動いているのかチェックするためにソースコードを覗いてみました。

Notionはブロック単位、ブロックの集合体で、コンテンツを形成していて、個別のブロック内は、以下のようなHTMLになっていて、

<div class="notranslate" (中略) contenteditable="true">

</div>

その中の、contenteditable属性をtrueとすることで、編集ができそうです。そこで、自分でも、ソースコードを書いてみて、編集することにしました。

<!DOCTYPE html>
<html lang="ja">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>編集可能ページ</title>
    <style>
        .content{
            width:100%;
            height:100%;
            background-color:beige;
        }
    </style>
</head>
<body>
    <div class="content" contenteditable="true">

    </div>
</body>
</html>

ブラウザで直接、アクセスしてみると、以下のような、まっさらなブロックになっていて、
image.png
ブロックを操作してみると、直接、文字を入力できたり、ブロックの終端まで、エンターキーで改行すると、ブロックの高さがどんどん伸びたり(CSSのheight属性がパーセントなどの相対的な値の場合)、文字だけじゃなくて、画像も直接貼ることができます。
image.png

何か新しいWebサービスを作るためのヒントになりそうです。:grin:

リンク

0
0
0

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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?