问题
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