HTML5 Style of iframe - css

I have an iframe, and I want to set the style inside attribute srcdoc using only CSS.
<iframe name="myFrame" srcdoc="<span>Hi</span>"> </iframe>
Is it possible to set the style of span inside srcdoc without using inline style but only style sheet?
If not, I can only put the whole html coding inside srcdoc to change the style?

CSS styles of an iframe are independent from main page appearance. And it is not possible to manipulate externally its design.
Relating to srcdoc attribute, I do not understand what you want. About it, MDN says: "This attribute is expected to generally be used together with the sandbox attribute".

You could try to do it with Javascript by changing the attribute. I am not sure if that is a possible solution for you. But if it is, create a function that can dynamically change the attribute to whatever you want. That way you don't have add it statically inline.
I will give you an quick example below.
document.getElementsByTagName("iframe")[0].setAttribute("srcdoc", "demoValue");
And to change the style of the inner span all you have to do is assign it an id. And make a rule in your CSS, this will alow you to manipulate it both in Js and CSS.
If the iframe is not in the same domain you will not be able to modify the content client side. You will have to read the page using PHP and echo it from your domain.

Related

How defile CSS rule path for iframe in cascade style sheet (CSS)?

I have a html page and i insert a iframe in this page.
I have a problem with iframe contants. In iframe show a button which have link to go on website anywhere, i want to that button does not show how set in CSS
{display: none}
but how in iframe button no detect any css rule for displaying none.
Help me CSS MASTERS
You must use seamless attribute:
This Boolean attribute indicates that the browser should render the
inline frame in a way that makes it appear to be part of the
containing document, for example by applying CSS styles that apply to
the <iframe> to the contained document before styles specified in that
document, and by opening links in the contained documents in the
parent browsing context (unless another setting prevents this). In
XHTML, attribute minimization is forbidden, and the seamless attribute
must be defined as <iframe seamless="seamless">.
The problem is that browser support is currently negligible. Meanwhile, you can watch Seamless iframes. The future, today!, a slideshow which can give you some ideas of how to implement those functionalities.

Applying css in iframe without using javascript or jquery

How can I inject css into iframe content without using javascript or jquery.
Without direct access to the child page, you cannot modify its style. If you can, you can modify the style like any other page. Only the iframe tag itself can be subjected to styling without any javascript.
For styling with javascript see here.

wikia template style attribute

I have made some templates on wikia.com, which contain only CSS code (key:value;).
My problem is having another template use these style templates in a style attribute tag.
style="{{MyTemplateStyle}}"
This code does not evaluate as expected. The CSS code is outputted before the element and the style attribute is not included inside the element.
Am I trying something not possible for a wiki ?
I merely want to be able to change styling on certain templates in one place, like regular HTML & CSS pages.
CSS styling specified from the style="" attribute always takes priority over any other css, even if you use !important in a CSS specification.
Therefore any edits you make to your CSS on Wikia will not ever override the CSS specified inside an attribute.
Kim, you were right to switch to classes instead of embedding in-line styles via templates.
The very idea of using templates suggest that this was going to be re-used in more than one place, applying styles to a group or, in fact, a class of elements.
This approach is much simpler to read and maintain (as you only have one, central place to edit), and also, if done right, will enable you to seamlessly change the colour scheme via Special:ThemeDesigner.

Real Nested CSS? (Not Selector)

I am first time poster. A question. How do a make a css declaration that only works within one DIV, but, not overwriting the global css? I want to jQuery loading a page into a DIV, however, the page's CSS changed my own site's CSS. I don't want that. Also I can't just take out CSS because I want them looked as intended from the source.
Basically we are going to load an external HTML with its CSS style applied locally ONLY without it changing the style elsewhere. The external HTML is not using inline CSS since we don't have control over it. They are applied to class values or even all element type. We don't want their CSS declaration modifying our own existing CSS outside of the DIV container.
Is this even possible?
Thank You?
If I understand your question correct you would place an id in the div <div id="mystyle"> content </div>. In your CSS you would write #mystyle p { color:red; }. which have no effect on global paragraphs outside the "mystyle" div.
I guess you are asking how to apply an external stylesheet to just one div. There is no way to do this using just CSS. You might be able to emulate this using JavaScript, but it's going to take quite a bit of work. Here's an outline of how you might go about doing this:
Grab the stylesheet filename from the loaded HTML and then get the contents of the CSS file via AJAX.
Somehow parse the CSS and prefix your div ID to each CSS rule, so that it applies only within your div.
Inject the modified stylesheet as inline text into the loaded HTML.
Steps 1 and 3 are relatively simple, step 2 requires a CSS parser written in JavaScript. (There seems to be one available here although there is no documentation.)

How do I apply inline CSS to an ASP.NET server control?

Based on a simple test I ran, I don't think it's possible to put an inline <style> tag into an ASP.NET server control. The style did not end up rendering to the output HTML. Even if it was possible, I'm sure it is bad practice to do this.
Is it possible to do this? I can see it being useful for quick prototypes that just have 1 or 2 CSS classes to apply.
Intellisense won't give you hints but you can do this:
<asp:Label ID="Label1" runat="server" Text="Label" style="color:Red;"></asp:Label>
According to www.w3schools.com:
The style element goes in the head section. If you want to include a style sheet in your page, you should define the style sheet externally, and link to it using <link>.
So it's not a good idea to include style elements (e.g. a <style type="text\css"></style> block) in a control. If you could, it'd probably have an effect in some browsers but it wouldn't validate and is bad practice.
If you want to apply styles inline to an element then either of these would work:
C#
myControl.Attributes["style"] = "color:red";
myControl.Attributes.Add("style", "color:red");
VB.NET
myControl.Attributes("style") = "color:red";
myControl.Attributes.Add("style", "color:red");
But bear in mind that this will replace any existing styles that are set on the style attribute. This may be a problem if you try setting styles in more than one place in the code so is something to watch out for.
Using CSS classes would be preferable as you can group multiple style declarations and avoid redundancy and page bloat. All controls derived from WebControl have a CssClass property which you can use, but again be careful not to overwrite existing classes that have been applied elsewhere.
If you use Attributes["style"], you are overwriting the style each time you call it. This can be an issue if you are making the call in two different sections of code. As well, it can be an issue because the framework includes properties for basic settings like border and colour that also will be applied as inline styles. Here is an example:
// dangerous: first style will be overwritten
myControl.Attributes["style"] = "text-align:center";
// in some other section of code
myControl.Attributes["style"] = "width:100%";
To play nicely, set styles like this instead:
// correct: both style settings are applied
myControl.Attributes.CssStyle.Add("text-align", "center");
// in some other section of code
myControl.Attributes.CssStyle.Add("width", "100%");
I think you will have to add it as an attribute to the server control... for it to render to HTML.
So basically (in C#),
ControlName.Attributes["style"] = "color:red";

Resources