How to find out the id of an element using css - html

I need to find out the id of an element on the page using CSS. I know about the # selector for styling things by their id, but I've got an element nested inside another element, and I need CSS to figure out what the id of the container element is. Then it uses the content attribute to do some other stuff related to the id. I hope that makes sense :)
EDIT: Sorry I didn't explain it well, I'll try better next time :)
What's happening is I've got a custom <window> tag that displays an on-screen window. Then I've got a <titlebar> tag that can drag the window around using a javascript function (onmouseout="dragwin(windowid)"). I want to make the <titlebar> tag automaticly have the onmouseout attribute and pass the windowid to javascript. I was trying to make this happen with the :before and :after pseudo classes and the content property (so basicly all CSS)

The question seems to be unclear but if you want to select child element of another element with known ID you should do this:
#someID <children tag>, for example: #myID div{ CSS styling goes here }

Not real clear, but I will take a shot:
Given this HTML:
<div class="class1">
<div id="element"></div>
</div>
CSS:
.class1 > #element

Related

HTML5 creates div I cant edit with CSS

I have some HTML as follows ( you can assume closing tags )
<ion-content>
<ion-tab>
The problem is, when the DOM is created, the HTML5 tag creates a div which I cannot edit using CSS
It becomes as so
<ion-content>
<div class="foo">
<ion-tab>
I need to edit the CSS of the div whose class is "foo", however, if i change the CSS of foo, i change the CSS of all the classes using "foo".
How do I specifically apply CSS to that specific div when I dont create it myself?
With the small amount off details you have given us, all I can do is refer to these CSS Selectors.
There are number off ways to style a specific element. All have been explained in detail in the link I have given you.
Edit: CSS Selectors explained in detail.
There are several ways to change the style of <div class="foo">.
You could give the div an (extra) #id or class. This makes it able to apply certain styles, just you would do normally, to this specify element.
Another option would be parent child {} where you could style all the children within parent. Note: you could add '>/+/~' to be more specific of the place of child within parent.
A third option would be to specify at what place the div is within its parent using :nth-child(n) or nth-of-type(n).
As I said before, there are many ways to style a specific element. Please take a look at the link I provided.

Broken HTML inside an HTML page

I have a page where I am reading an HTML from email.
Sometimes, the text which comes from the email has HTML and CSS and it changes my page style completely.
I don’t want my page style to be impacted because of this. How do I read the HTML and CSS strictly inside a particular div (box) and not let the page get impacted by this?
you have to write your css using some parent > child format. You might have to use !important.
May be you are using some kind of common selectors like "a", "p", "div". In these cases we can prevent the overriding by using parent class/id or with "!important.". I will not recommend the second one.
Ex. using parent className:
.parent-classname p{
/*style here*/
}
put that div in iframe so it behave like a seperate window so your html content not effected by loadded css.
You can use <iframe></iframe> tag instead of the <div></div>. Using Parent>Child Css format will also help make your styles more unique and protect them from being overridden.

how to apply css property to my first div class only

I am having two dhx_scroll_cont div class, when i write css code as bellow it working for two classes. Now i want to write a css code that apply for first div call
.dhx_scroll_cont:before{
//some code here
}
Demo Fiddle
Simply use:
.dhx_scroll_cont:first-of-type:before{
//some code here
}
more on first-of-type
The :first-of-type CSS pseudo-class represents the first sibling of
its type in the list of children of its parent element.
Update
According to the screenshot the OP posted the below should work:
.dhx_view_day_events .dhx_scroll_cont:first-of-type:before{
//some code here
}
Depending on the structure of your HTML the solution you require will change.
Would you be able to provide the HTML structure for us to work from?
Otherwise, you could:
Add another class to the div you want to change
By having <div class="dhx_scroll_cont"> you are only giving one targetable class. One way around this is having 2 classes separated by a space, such as:
<div class="dhx_scroll_cont OTHER_CLASS">
This will allow you to target the class OTHER_CLASS with the certain CSS values that you want effecting the first div.
Using :first-child or :first
:first-child and :first allow you to target the div that is the first child element of it's parent. For example:
<div class="surround">
<div class="dhx_scroll_cont">
</div>
<div class="dhx_scroll_cont">
</div>
</div>
dhx_scroll_cont:first-child {
CSS HERE
}
This will effect the first dhx_scroll_cont div.
As I said previously, if you can give some more information on the structure of your HTMl it would help us with your solution.
EDIT
Thanks for showing the HTML structure.
With that structure out of the methods that I have shown, adding another class to the first of the dhx_scroll_cont will allow you to specifically target that div, and not the other one.

CSS notation: the meaning of ">"

In my website, I have the following structure on some html page:
<html>
<head><!-- All the usual information here, including the link to the css file --></head>
<body>
<div id="splash">
<!-- The good stuff -->
</div><!--End of Splash-->
</body>
</html>
Now that #splash div only appears on that one html page, and I need the css affecting that page's html {} to be a little different. Is the below notation going to do what I need?
html>body#splash {/* CSS that only affects the html that contains div #splash */}
I think you're looking for a parent selector; sadly this doesn't exist in CSS, so you're out of luck.
This is, from what I understand, mostly for performance reasons -- Jonathan Snook's article goes into a little more detail.
It's either time to change your page generation so that a class or ID gets added to the html element on your "splash" page, or resort to JavaScript, such as the jQuery cssParentSelector library that arkanciscan mentions.
Since IDs are unique, you can just do:
#splash {
/* stuff */
}
About your question:
html>body#splash
Will not work; try
html>body #splash
The > is basically the same this as a space, but selects only direct children.
(I'm assuming you're trying to select #splash; that's how I read your question. If you want to select body if #splash exists, then... well, you can't.)
Like others have said, you can't do this is CSS... yet! In the next version of CSS you'll be able to add an exclamation point to any part of a compound selector to indicate which element of the selector your rules should apply to. This will be called a "subject" (http://www.w3.org/TR/selectors4/#subject)
If you want to use this today you can try this polyfill https://github.com/Idered/cssParentSelector
Child selectors are indicated by >: http://www.w3.org/TR/CSS2/selector.html#child-selectors
It means you are selecting a first-level descendent.
Your code needs this space:
html>body #splash
This reads: "Select the element with the id of splash that is a descendent of body which is a child of html."
Your code is this:
html>body#splash
Your current code reads: "Select the body element with the id of splash that is a child of html.
As has been said, this can't be done in current CSS.
But just to give you a suggestion: you could add a unique ID or a class to the HTML in question; if you know which one it is ahead of time, just add it statically; if not, you'll have to actually look (with JS) if there's a div like you describe in the body, you can't do it with CSS alone.

Is it possible to call an inner div within an outer div on a stylesheet in one line?

i'm using wordpress and i have an element i want to style... it's called...
<h2 class="widgettitle">
now, i know i can do,
h2.wigettitle {
whatever:css;
}
however, the problem i have is that i have multiple widgets with the same title and it effects all of them.
but, this h2.widget title is within another div called "headerarea".
so, in my file it's like...
<div id=headerarea">
<h2 class="widgettitle">
whatever title
</h2>
</div>
so is it possible to make this specific element do something like, #headerarea.h2.widgettitle or something in my element?
i tried styling the outer div independently, but the inner div is still grabbing styling from somewhere else, so i need to override all of them.
hope this makes sense... thanks for any help guys.
Use #headerarea h2.widgettitle. Including a space means to look in the children. If you include a > this means only look in direct children. Note that if your overrides do not work, add !important at the end to ensure they will override any other styles applied.
You can use the child or descendant selectors to accomplish this. Child selector > #headerarea > h2.widgettitle select h2 elements with class widgettitle that is a child of element with id headerarea. Descendant selector a space #headerarea h2.widgettitle select h2 elements with class widgettitle that is a descendant of element with id headerarea.
Also see http://www.w3.org/TR/css3-selectors/#selectors
#headerarea .widgettitle {
/* Put your styles here */
}