[HTML/JS] ExecCommand fontname/size contenteditable

Pagina: 1
Acties:

  • Guillome
  • Registratie: Januari 2001
  • Niet online
Hoi

Ik wil in mijn contenteditable div de fontname en size kunnen aanpassen.
Maar waarom doet hij met deze code niets?

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
      function change_font(obj)
      {
        document.getElementById("textveld").focus();
        var range = document.selection.createRange();
        range.execCommand("FontName", false, 'arial narrow');//fontarray[obj.selectedIndex]);
        obj.focus();
      }
      function change_font_size(obj)
      {
        document.getElementById("textveld").focus();
        var range = document.selection.createRange();
        range.execCommand("FontSize", false, "5");//obj.options[obj.selectedIndex].innerText);
        obj.focus();
      }


de div
code:
1
<div id="textveld" contenteditable="true" name="textveld" style="border:3px groove; background-color: white; padding:5px; height:100%; width:100%;">asdasd</div>


De overige dingen doet ie wel, zoals bold of insertimage.

Bij voorbaat dank.

If then else matters! - I5 12600KF, Asus Tuf GT501, Gigabyte Gaming OC 16G 5080 RTX, Asus Tuf Gaming H670 Pro, 48GB, Corsair RM850X PSU, SN850 1TB, Arctic Liquid Freezer 280, ASUS RT-AX1800U router


  • Guillome
  • Registratie: Januari 2001
  • Niet online
Ik weet het al, het komt omdat ik dit in mijn stylesheet heb staan:
*
{
font-family:arial;
font-size:12px;
}

Hoe kan ik dit omzeilen? Zodat alleen de div deze style niet heeft?

If then else matters! - I5 12600KF, Asus Tuf GT501, Gigabyte Gaming OC 16G 5080 RTX, Asus Tuf Gaming H670 Pro, 48GB, Corsair RM850X PSU, SN850 1TB, Arctic Liquid Freezer 280, ASUS RT-AX1800U router


Verwijderd

Gebruik maken van cascade i.p.v. dat soort rare styles gebruiken?

  • Guillome
  • Registratie: Januari 2001
  • Niet online
Hoe bedoel je cascade?

If then else matters! - I5 12600KF, Asus Tuf GT501, Gigabyte Gaming OC 16G 5080 RTX, Asus Tuf Gaming H670 Pro, 48GB, Corsair RM850X PSU, SN850 1TB, Arctic Liquid Freezer 280, ASUS RT-AX1800U router


Verwijderd

Euh grondbeginselen van CSS? Enig idee waar die C voor staat? ;)

Dus bijvoorbeeld
code:
1
2
3
html{
 font:.9em/1.4 Arial,sans-serif;
}
Alle dieper gelegen elementen nemen automatisch de stijl van dit element over (cascade), i.p.v. dat je voor elk element zegt welke stijl ze moeten hebben.

  • Guillome
  • Registratie: Januari 2001
  • Niet online
Dat heb ik nu toch ook met *.
Dan hebbe alle objecten die eigenschappen.
En zoals jij het doet, dan zou mijn div ook nog steeds die eigenschappen krijgen.
En dat moet niet. Die moet kaal blijven.

If then else matters! - I5 12600KF, Asus Tuf GT501, Gigabyte Gaming OC 16G 5080 RTX, Asus Tuf Gaming H670 Pro, 48GB, Corsair RM850X PSU, SN850 1TB, Arctic Liquid Freezer 280, ASUS RT-AX1800U router

Pagina: 1