473,772 Members | 2,388 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Applying CSS file to a <div> section

Hi,

I have a web application which uses external CSS files extensively.
Now, I need to port this application to run inside a portlet. So, it
will not generate a complete HTML document, but just a fragment. How
can I apply an external CSS file not to the whole HTML document, but
just to a div section ?

I see 2 alternatives:
1) to use a system prefix in every ID and CLASS attribute. This will
be generate a lot of work for me.
2) to code a JavaScript code to load the CSS file and apply it to the
document. I think this is possible, but I don´t know how to do it.

Any ideas are welcome,

Alessandro Coelho Ribeiro
al************* ***@integritas. com.br
Integritas Technologies - Open Solutions

Dec 13 '05 #1
2 17501
"alexrib" <al************ ******@gmail.co m> wrote:
I have a web application which uses external CSS files extensively.
Now, I need to port this application to run inside a portlet. So, it
will not generate a complete HTML document, but just a fragment. How
can I apply an external CSS file not to the whole HTML document, but
just to a div section ?


If you are not able to write in the document's head section, your only
option is to supply inline styles via the style attributes in each HTML
element.

--
Spartanicus
Dec 13 '05 #2
alexrib napisał(a):
Hi,

I have a web application which uses external CSS files extensively.
Now, I need to port this application to run inside a portlet. So, it
will not generate a complete HTML document, but just a fragment. How
can I apply an external CSS file not to the whole HTML document, but
just to a div section ?

I see 2 alternatives:
1) to use a system prefix in every ID and CLASS attribute. This will
be generate a lot of work for me.
2) to code a JavaScript code to load the CSS file and apply it to the
document. I think this is possible, but I don´t know how to do it.


1)
I am not sure what you can do and what is not possible, but
instead of adding a prefix to each ID and CLASS attribute in
your code, you can convert it this way:

Let's say your CSS looks like

a { color: #00f; }
p { magin: 1em;
p.someclass { background:#eee ; }
h2 { border-bottom:solid 1px #000; }

you can change it to:

#portletId a { color: #00f; }
#portletId p { magin: 1em;
#portletId p.someclass { background:#eee ; }
#portletId h2 { border-bottom:solid 1px #000; }

and use <div id="portletId" > your code here.. </div>

Of course this solution will work if your stylesheet will be
linked in <head> section. If the only part you can modify is
your <div> content, I think you may try some Javascript to
add it to the <head>, for example:

2)

<script type="text/javascript">
//<![CDATA[
var csslink=documen t.createElement ('link')
csslink.setAttr ibute('rel','st ylesheet');
csslink.setAttr ibute('href','y our/css/url/path');
document.getEle mentsByTagName( 'head')[0].appendChild(cs slink);
//]]>
</script>

It worked in my Firefox but I can not guarantee it is
totally cross-browser solution.
Dec 13 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
6519
by: Jens Kristensen | last post by:
I have a problem displaying a divbox containing a html-textarea - everything works fine with "normal" characters. However, when the textarea contains special chars like <P> or ' , the box fails to show: function show(divbox) { divbox.style.display=''; } <div id="divbox" style="display:none" >
55
7308
by: Ton den Hartog | last post by:
Stupid basic question but I find it horribly imposible to find the answer elsewhere... :-( I want to have a piece of text in my HTML page and want to be able to change it in a Javascript function that is called from a button. I think I can use a <div id="t"></div> for this ? Something like
5
10030
by: Lilou | last post by:
Hello this page works : http://lilou.leuwen.chez.tiscali.fr/testlilou.htm the source : .... a.link:hover div.test2 {display : block; position: absolute; z-index: 1000;
2
2969
by: Nikolai Onken | last post by:
Hey, I am trying to learn the exact behavior of CSS and was just placing a couple of <div>'s after each other. Each of the <divhas a <pwithin and some text within the <p> Now when I add a background-color to the div, the color won't fill up the entire space I believe it should. The div only has color around the text though it has one line space to the above element. I hope it is clear what I mean:
28
5374
by: Kent Feiler | last post by:
1. Here's some html from a W3C recommendations page. <P>aaaaaaaaa<DIV>bbbbbbbbb</DIV><DIV>cccccccc<P>dddddddd</DIV> 2.Although I didn't think it would make any difference, I tried it with the </p>s included as well. <P>aaaaaaaaa</p><DIV>bbbbbbbbb</DIV><DIV>cccccccc<P>dddddddd</p></DIV>
0
2012
by: pravinnweb | last post by:
Hi, i have one table with <thead>,<tbody> and <tfooter> i have applying the overflow property for <tbody> section in firefox its working fine.but in IE6 the <thead> section is coming in the <tbody> section can anyone give me solution here is the code <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta...
8
10047
prino
by: prino | last post by:
Hi all, I've written code (in REXX) that takes files in legacy languages (PL/I, COBOL, z/OS assembler, etc) and converts them into HTML in a format similar to what's displayed in the z/OS ISPF editor. A fellow member of the PCG has helped me by creating a bit of Javascript to emulate the scrolling and using Google I've now gotten it into a state where it almost passes the W3C Markup Validation Service. However, the one error, Error Line 166,...
2
4464
Frinavale
by: Frinavale | last post by:
I've created a ASP.NET control that displays a "book" of schedules. It dynamically displays scheduling times and allows the user to page through the schedules. It also lets the user edit the schedule times if the user has permissions to edit schedules. When the user is not editing, or the user is not allowed to edit, the buttons that let the user edit are not displayed. If the user is allowed to edit schedules but they are not editing a link...
4
3624
by: ismailc | last post by:
Good day, RamananKalirajan helped me with a great script to do a popup div. The problem i now have is that the popup div within the div does not like any table><tr><td>, so itried using <div> in place of tr but not working to create nicely div, What can i use? all the bold text are the problem areas. <div id="light" class="white_content"> <div class="bgErrorMessage">
0
9621
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10264
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9914
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8937
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6716
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5355
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3610
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.