Как добавить пробел до и после отредактированного текста в contenteditable области - PullRequest
0 голосов
/ 02 июля 2019

Я хочу добавить пробел до и после отредактированного текста в contenteditable области, как один пробел до и после, так как я могу сделать это с помощью CSS.это мой сценарий: jsfiddle

[contenteditable="true"] {
    background-color: DodgerBlue;
    
}

[contenteditable="true"]:focus {
    background-color: white; 
	color : black; 
}
span.a {
  border: 1px solid white;
  
}
span.a:empty {
  padding-right:10px;
}
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
   Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, 
   <span  class="a" contenteditable="true">
    when an unknown printer
    </span> took a galley of type and scrambled it to make a type specimen book. 
   It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. 
   It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages,
   and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

1 Ответ

0 голосов
/ 02 июля 2019

Вы можете добавить это:

[contenteditable="true"] {
  margin: 0 5px 0;
}

Это добавит интервалы по обе стороны от contenteditable области.

[contenteditable="true"] {
    background-color: DodgerBlue;
    
}

[contenteditable="true"]:focus {
    background-color: white; 
	color : black; 
}

[contenteditable="true"] {
  margin: 0 5px 0;
}

span.a {
  border: 1px solid white;
  
}
span.a:empty {
  padding-right:10px;
}
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, <span  class="a" contenteditable="true">when an unknown printer</span> took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
...