WEB/HTML

[HTML] contenteditable

S0PH1A 2020. 12. 4. 11:47
๋ฐ˜์‘ํ˜•

contenteditable

 

๐Ÿ‘ contenteditable

์‚ฌ์šฉ์ž๊ฐ€ ์š”์†Œ๋ฅผ ํŽธ์ง‘ํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•˜๋Š” ์˜ต์…˜์ด๋‹ค.

HTML ํƒœ๊ทธ๋ฅผ ์ž…๋ ฅํ•˜๋”๋ผ๋„ vue์˜ v-html๊ณผ๋Š” ๋‹ฌ๋ฆฌ ๋ฌธ์ž์—ด ๊ทธ๋Œ€๋กœ ํ‘œ์‹œํ•œ๋‹ค.

https://developer.mozilla.org/ko/docs/Web/HTML/Global_attributes/contenteditable

  • true: ํŽธ์ง‘ ๊ฐ€๋Šฅ / false: ํŽธ์ง‘ ๋ถˆ๊ฐ€๋Šฅ
  • ex) textarea ์˜ ๊ฐ’๋งŒ ํ‘œ๊ธฐํ•˜๊ณ , ๋ณ€๊ฒฝ ๋ถˆ๊ฐ€๋Šฅํ•˜๊ฒŒ ํ•  ๊ฒฝ์šฐ
    • contenteditable = false
    • disabled

์˜ˆ) textarea ์— ์ž…๋ ฅํ•œ ๊ฐ’์„ div ์— ํ‘œ์‹œ (vuejs)

<template>
	<div>
		<textarea v-model="contents" />
		<div contenteditable="false" disabled>{{ contents }}</div>
	</div>
</template>

<script>
export default {
	name: 'Textarea',
	data() {
		return {
			contents: '<span>ํ…Œ์ŠคํŠธ์ฝ”๋“œ</span>'
		}
	}
}
</script>

 

  • contenteditable์— css ์†์„ฑ ์ ์šฉ
// .scss
div[contenteditable] {
	border: 1px solid #eeeeee;
	max-height: 150px;
	overflow: auto;     // height ๋„˜์–ด๊ฐ€๋ฉด X,Y ์ž๋™ ์Šคํฌ๋กค
	white-space: pre;   // \n ์ค„๋ฐ”๊ฟˆ
	padding: 3px;

	&:disabled {   // disabled ์ธ ๊ฒฝ์šฐ
		cursor: default;
	}

	&:empty {      // ํ‘œ์‹œํ•  ๊ฐ’์ด ๋นˆ ๊ฒฝ์šฐ
		border: transparent !important;
	}
}

 

๋ฐ˜์‘ํ˜•