CSS and TWebbrowser delphi

荒凉一梦 提交于 2019-12-03 22:21:42

问题


I was wondering if it was possible to manipulate the CSS of websites. For example color in the input fields? I had a look at several questions, but its not clear to me if it is possble at all.

For Example in Google Chrome, Whenever a field is selected it shows a golden line around the outsite. Is it possible to do this and other things in delphi, with any website. Writing CSS code that gets applied to the website opend in Twebbrowser? Just for personal viewing only

Thx

Can I change the color of an input field background with this code as well? I can change background colors and change font size, but cant seem to figure out to color in or border an input field. This is the code:

http://www.delphidabbler.com/tips/58


回答1:


It is possible to modify CSS by adding a stylesheet from code, after the page is loaded:

var
   document: IHTMLDocument2;
   stylesheet: IHTMLStyleSheet;
   stylesheetIndex: Integer;
begin

   // Inject CSS Style Sheets
   document := webBrowser1.Document as IHTMLDocument2;

   stylesheetIndex := document.styleSheets.length;
   if stylesheetIndex > 31 then
      raise Exception.Create('Already have the maximum amount of CSS stylesheets');

   stylesheet := document.createStyleSheet('', stylesheetIndex);
   stylesheet.cssText := ...




回答2:


Using @jasonpenny's answer to add a stylesheet, what you need next to change the border around the input element that has focus, is what in CSS is called the focus pseudo class or selector. For more information see these articles:

  • http://www.w3schools.com/css/css_pseudo_classes.asp
  • http://www.w3schools.com/css/sel_focus.asp
  • http://www.w3schools.com/css/css_border.asp

The http://www.w3schools.com site has a wealth of information on web development. It also allows you to play with many examples so you can see what the effects would be when you change things. If you are trying to learn how to do css styling you might be better of getting to grips with all the information there, instead of trying to learn programming and a programming language at the same time.



来源:https://stackoverflow.com/questions/5107369/css-and-twebbrowser-delphi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!