CSS to be applied to DIV contents - css

I have a DIV like the following:
<td>
<DIV>
<script type="text/javascript">
// link to some js
</script>
</DIV>
</td>
The .js renders the latest article abstract inside the div. However it renders it in Calibri 10px.
I want that any content inside the DIV should be rendered as Verdana 10px. I am using a 3rd party .js so have no control over it. How to I force the DIV to render the content the way I want?

If the elements the Javascript is adding have their own style declarations, then you will need to use more Javascript to override them.
Otherwise, You should be able to give your div a class, apply your styles to that class, then they should propagate through to any contents inside.
e.g.
css:
.myClass {
font-family: Verdana;
font-size: 10px;
}
html:
<td>
<div class="myClass">
<script type="text/javascript">
// link to some js
</script>
</div>
</td>
If that doesn't work, change the CSS to this:
.myClass * {
font-family: Verdana;
font-size: 10px;
}

If the javascript only puts content and no style, you could do this:
<td>
<DIV style='font-family: Verdana; font-size: 10px;'>
<script type="text/javascript">
// link to some js
</script>
</DIV>
</td>

You need to check what elements the javascript generates. Use firebug in FireFox or "Inspect element" in Chrome.
When you know the element, specify something like this in your stylesheet.
body table tr td div elementOrClassNameThatYouFound {
font: verdana 10px;
}

You could also try something in your CSS like:
.myClass {
font-family: Verdana !important;
font-size: 10px !important;
}

Related

What's the proper way to style a page ? Create snippets of CSS and add corresponding classes to the HTML tags, or use CSS selectors/IDs to style?

Let me illustrate. Consider this :
<!DOCTYPE html>
<html>
<head>
<title>A page</title>
<link rel="stylesheet" href="mystylesheet.css">
</head>
<body>
<div id="title_div">
<h2>This title has style</h2>
</div>
<div id="content_div">
<h2>This is not styled.</h2>
</div>
</body>
</html>
Let's say I want to style the first h2 in my CSS stylesheet.
Which way is better ?
1:
redtext{
color: red;
}
italictext{
font-style: italic;
}
And then add the following attribute to the first div : class="redtext italictext"
Or 2:
#title_div h2{
color: red;
font-style: italic;
}
Personal but I would go for (if you need a uniform H2 through the site)
h2
{
color: red;
font-style: italic;
}
but the for you may need to integrate the other option for more custom parts of the site if you would like different H2 styles through the site.
However have you coincided using SASS sounds like it may be the answer for you.
I would use example #2 or change your html to by removing the surrounding div tag. The surrounding div tag seems to only be there to have a class.
<h2 class="title">This title has a style</h2>
And your css to
.title{
color: red;
font-style: italic;
}
The content <h2> should probably be an <h3> not an <h2> to keep the document structure clean.

How to override global Bootstrap Stylesheet?

I am trying to change width of a drop-down in my application by setting width attribute of select tag. But width provided by me does not have any effect as it is pre-specified in global style-sheet file for select tag. I Don't want to change the global CSS file. But is it possible to re-size my drop-down without changing global CSS?
I will disagree using !important should be used only when it is really needed, because in the longrun it will cause issues for people who will maintain the code.
1) Create a separate css file & and place your rules there.
2) Include it after bootstrap includes.
3) Make sure to be specific regarding the path of your html element you need to change
For example if this is specified
<!DOCTYPE html>
<html>
<head>
<style>
div#test table#sometable td#sometd{
color: #000;
}
td#sometd{
color: #fff;
}
</style>
</head>
<body>
<div id="test">
<table id="sometable">
<tr>
<td id="sometd">
hello
</td>
</tr>
</table>
</div>
</body>
</html>
The 'hello' text inside teh cell will remain black although you have td#sometd{color:#fff;}
This occurs because the prior css rule is more specific than the second one, hence your overriding rule could simply be:
div#test table#sometable td#sometd{
color: #fff;
}
You should use !important wisely & as a last resort if you want to override other !important rules or inline css.
Avoid using !important, try do overwrite the specificity.
https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity
You need to add !important after your definition:
.dropDownCustom
{
width: 100px !important;
}

Google Chrome seems to ignore cellpadding + cellspacing

I have a table with a tr and two tds. First td contains an input(text), the second another input (image). The second input is supposed to be a button. I've set cellpadding and cellspacing to zero so that the text input and the image button can be attached with no spaces in between. This works fine in IE and Firefox but not in Chrome. Chrome keeps leaving a few pixels of space between the text input and the button. I tried using CSS but nothing seems to work. Any idea what Chrome's problem might be?
<head>
<style type="text/css">
.search{
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 14px;
font-weight: normal;
color: #4D4D4D;
border: 1px solid #CCCCCC;
height: 21px;
outline: none;
}
</style>
</head>
<body>
<table cellpadding="0" cellspacing="0">
<form method="post">
<tr><td><input type="text" size="30" class="search"></td>
<td><input type="image" src="button.gif" name="submit" id="submit" width="77px" height="21px"></td></tr>
</form>
</table>
</body>
First off, you need to move the <form> tag outside of the <table> you're going to cause yourself trouble that way.
Next, you need to set the padding on your tds to 0:
form td {
padding: 0;
}
That should get rid of any extra spacing you're seeing.
A stackoverflow user said:
Just mentioning that cellpadding and cellspacing have been made obsolete, and I received a shock when Google Chrome 23 didn't support it.
Anyway I can't find any reference on the internet!
For what you want, try border-collapse: collapse on the table via css.
Also, you might want to look into other means as using a table for layout is not the way forward these days and it sounds like that's what you're doing.

Getting different font size with same css file in IE

I have created a couple of ASP.Net (aspx) pages which are supposed to run with existing ASP pages in a website.
Both ASP and ASP.Net pages use the same css file. In both the pages, there are headings which are styled using tag from css file.
The problem is that headings in .asp and .aspx pages are rendering in different size in Internet Explorer. It works fine in FF and Chrome.
Please suggest some workaround for this, as I have to make my .aspx pages similar in look and feel to the existing .asp pages.
Thanks in advance!
Updated:
I can paste a part of css file here, since it is a large file:
TH, FONT, TD, P, B, I, STRONG, U, EM, BLOCKQUOTE, LI, OL, CAPTION, DL, DT, DD,select,pre {font-size:11px;font-family:Arial, Helvetica, sans-serif;}
body{
font-family: Arial, Helvetica, sans-serif;
color: #000000;
line-height: 1.166;
margin: 0px;
padding: 0px;
}
h2{
font: bold 150% Arial, Helvetica, sans-serif;
color: #000000;
margin: 0px;
padding: 0px;
}
The aspx page (heading part) looks like this:
<table style="left: 35px; position: static; top: 231px">
<tr>
<td style="height: 85px; width: 2087px;">
<h2><asp:Localize id="lblHeading" runat="server" Text="Welcome to XYZ" meta:resourcekey="lblHeading"></asp:Localize>
</h2>
</td>
</tr></table>
ASP page has a simple tag:
<h2>Welcome to XYZ</h2>
Updated:
The weirdest thing happened. I tried stripping down the css file and started adding each style one by one, and refreshing the page to check which styles are getting applied to the heading. I noticed that if I remove the first line of css (keeping all the other styles intact):
<STYLE type="text/css">
then the headings look same in both asp and aspx pages. As soon as I add the above line in css file, the heading in aspx page becomes bigger.
Any comments as to why this is happening?
Make sure you are using the proper and the same Doctype at the top of the ASP and ASPX pages. You can also use the developer tools in FF and in IE to make sure that the same styles are applied to headings on ASP and ASPX pages in both browsers. What version of IE are you using?
You might be interested in section about w3schools recommendation for font-size
The suggested way, as I understand is to declare in body:
body{
font-size: 100%; // which default is 16px
}
and everywhere else use em (instead of % or px), as explained in the link.
So in your header you should not have 150%, but instead DesiredSizeInPx divded by 16, for example if you want to have 24px you write 24/16em, which is 1.5em
The problem could be that two different styles are being applied.
The ASP page is getting the straight h2 style
h2{
font: bold 150% Arial, Helvetica, sans-serif; etc.
Whereas the ASPX might be getting another style
id="lblHeading"
Check to see if #lblHeading is giving a different size.

how to write a proper selector for what is inside input box?

I have a form of inputbox and i need to write a good selector. I need to assign attributes only to what is inside inputbox. form looks like this:
<label></label>
<input type="text" disabled="disabled" name="xxx" size="100" value="abcd" class="yyy" />
however, i have more elements of this class on my page.
what is the best way to go?
As you've added a class "yyy", you can just go ahead and do the following:
<style type="text/css">
.yyy {
font-size: 14px;
font-family: Arial;
color: #FF0000;
}
</style>
You can of course paste that HTML code above and plant it in your HTML document, but it's best practice to keep HTML and CSS away from each other.
So add this code in your head tag:
<link href="some/style.css" type="text/css" rel="stylesheet" />
And inside of style.css:
.yyy {
font-size: 14px;
font-family: Arial;
color: #FF0000;
}
You could use either input.yyy {}, which will work on all browsers but if you have more than one input element on the page with a class of yyy, it will select all of them.
An alternative is input[name=xxx], using a new CSS3 selector, but this won't work in older browsers, so it depends how important it is that the style works everywhere.

Resources