I'm doing something like this however, the word world won't appear. having that rule declare in the head css, it works fine.
can anyone explain this to me?
<span id="aa" style="#aa::after{content=" world";}">hello</span>
No. The style attribute only defines style properties for a given HTML element. Pseudo-classes are a member of the family of selectors, which don't occur in the attribute.
The style attribute doesn't accept selectors. It only accepts the rules to apply to the current element. You can't do this with a style attribute.
Working jsFiddle Demo
You must separate your CSS from your HTML:
<!doctype html>
<html>
<head>
<title>My Web Page</title>
<style>
#aa:after {
content: 'world';
}
</style>
</head>
<body>
<span id="aa">hello</span>
</body>
</html>
It's also better to create a file with .css extension, for example styles.css,
and put the style in it:
#aa:after {
content: 'world';
}
And in your HTML, link to this file:
<!doctype html>
<html>
<head>
<title>My Web Page</title>
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<span id="aa">hello</span>
</body>
</html>
Be sure that your html and css file are in the same folder.
The style attribute applies styles to the current element; it cannot contain complete style sheet rules with selectors.
Although the selector in this case happens to match the same element, if it were possible, you would also be able to do this, which would make very little sense:
<div id="one" style="#two { display: none; }"></div>
... much content ...
<div id="two">Huh?</div>
Related
Summary of the problem
The following image is a description of bootstrap icon.
I don't know how to use "Code point".
Unicode: U+F120
CSS: \F120
JS: \uF120
HTML: 
For Using HTML code point, All you need is just set the the font-family of your element(or your body) to 'Bootstrap-icons' and then everything will work.
<!DOCTYPE html>
<html>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons#1.9.1/font/bootstrap-icons.css">
<style>
.test
{
font-family:'Bootstrap-icons';
}
</style>
<body>
<div class="test">

</div>
</body>
</html>
I managed to find how to use CSS of "code point".
Add following html into the head element of document.
Set font-family to be Bootstrap-icons.
And you can use css code point \F120 to fill the value of content property.
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons#1.8.0/font/bootstrap-icons.css">
<style>
h3::before {
font-family:'Bootstrap-icons';
content:'\F120';
}
</style>
The otheres (Unicode, JS, HTML) are still ununderstood.
Thank you for reading my broken English! :)
I have a css class .menu-bar.
<style>
.menu-bar { width: 100%; text-align: center; }
</style>
If I place the class in external stylesheet, it won't load ( has no effect in html file ).
If I place the class in local stylesheet (in head tag), it only works if the class is also defined in the external stylesheet. I know this, because I removed the class from external stylesheet and the local class did nothing. My observations have been, this is being caused by text-align. What is going on?
My implementing code:
<div class="menu-bar">
<div> Content </div>
</div>
My intention is to place my css code in external stylesheets. In this scenario, I am having to duplicate this code which seems to demean the point of having external stylesheets. Any thoughts would helpful.
I personally Use VS code as far I can see your problem is that you are not able to link your external stylesheet (CSS file) If You use vs code you can use this.
Maybe some problem in the live server or anything if the code doesn't work the problem maybe something else.
Correct me if I am wrong!
MY CODE
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<div class="menu-bar">
<div>
<p>Content *Text align - center Text horizontally*. </p>
</div>
</div>
</div>
</body>
</html>
CSS CODE (External Sheet)
.menu-bar{
width: 100%;
height: 100%;
text-align: center;
background-color: aqua;
}
Click me to view result
The external CSS code did not run because you did not import it in your HTML.
Add this to the start of your HTML:
<link rel="stylesheet" href="PATH_TO_CSS.css">
I'm trying to include CSS in Phoenix templates (EEx) so that I can define components (that render on the server) that not only include HTML but also their own CSS. For that I would like to include a tag with the CSS for that template (component) hoping it would be injected in the <head> but that's not what happen. I made a few experiences and wasn't able to achieve that (weird enough when I did that my webpage didn't break and I could see <head> and <style> tags inside the <body>).
A sample templateXYZ.html.eex code could be:
<style>
.main {color: red;}
</style>
<div class="main">
<!-- Html code goes here -->
</div>
Note that the main goal of this is to allow me to write all the "component" code in one template (Html, CSS and Javascript - with the later there's no problem so I'm omitting it in the example/question) in a way that I only need to place the template in the proper place inside my other templates (rendering a template inside another template is also not a problem) and do nothing more (like as when I have a separated CSS file and need to import it in the <head>).
As a comparison, I can do what I want in the client side with raw Javascript that places my <style> and HTML in the DOM like this:
function f_auxButton(imgpath,id){
if (document.getElementById('auxButtonId')){} // <style> is only created on first component instanciation to avoid duplication
else {
$('<style id="auxButtonId">\
.auxButton {\
width: 25px;\
height: 25px;\
margin: 10px;\
}\
<\style>').appendTo("head")}
return '<img src="'+imgpath+'" class="auxButton" id="'+id+'">'
Then I just have to call <script>f_auxButton(arg1,arg2)</script> where I want to place the HMTL and I get it (plus the <style> tag that goes into the <head>.
So, is there a way of doing this?
app.html.eex
<!doctype html>
<html>
<head>
<title></title>
<%= render_existing view_module(#conn), "_styles.html", assigns %>
</head>
<body>
<div class="main">
<%= render_existing view_module(#conn), "_component.html", assigns %>
</div>
</body>
</html>
/web/templates/shared/_components.html.eex
<%= render MyApp.PageView, "_styles.html" %>
<img src="<%= static_path(MyApp.Endpoint, "/path/example.png")%>", class="auxButton">
/web/templates/page/_styles.html.eex
<style>
.auxButton {width: 25px;height: 25px;margin: 10px;}
</style>
Final Result
<!doctype html>
<html>
<head>
<title>My App</title>
<style>
.auxButton {width: 25px;height: 25px;margin: 10px;}
</style>
</head>
<body>
<div class="main">
<img src="/path/example.png" class="auxButton">
</div>
</body>
</html>
i use the CSS selector xmlns\:div for XMLNS to style my elements, but i cant use the tag elment selectors... for example div{color:#fff;}
NB: the XMLNS prefixes is generated automatically so i can't predict the string and use it like so prefix1\:div{color:#fff;}
xml file :
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns:aa='zz' xmlns:ee='rr'>
<head>
<title></title>
<style type="text/css">
/* it work */ aa\:span{background: #00ff00;}
/* it doesnt work */ span{background: #00ff00;}
</style>
</head>
<body>
<div>
<aa:span id="span1">
<aa:p>aaa</aa:p>
</aa:span>
</div>
<div>
<ee:span id="span1">
<ee:p>aaa</ee:p>
</ee:span>
</div>
</body>
</html>
it's kinda weird because in the html render (browser) there's no more prefixes.
But, can you use a nasty trick like instead to build css on tag, you can build with ID.
Like :
// ninja coding =D
#span1{
color : black;
visible : hidden;
}
Maybe something interessant four you here
The below code is not working in Internet Explorer 6. I can't put class or id in it. Are there any CSS hacks for that?
This code is in WordPress. I can't modify the code; I can only modify the CSS.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<style type="text/css">
form input[type=submit]{
background-color:#FE9900;
font-weight:bold;
font-family:Arial,Helvetica,sans-serif;
border:1px solid #000066;
}
</style>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<FORM action="">
<INPUT type=text name=s>
<INPUT type=submit value=Search>
</FORM>
</body>
</html>
Instead, give the input a class, and then style it from there. Like this:
<input type="submit" class="myClass" value="Search" />
And then style the .myClass in your CSS. This should also work in IE6.
You're right, it doesn't work.
Quirksmode.org is an excellent site with browser compatibility info:
http://www.quirksmode.org/css/contents.html
The Internet Explorer 6 doesn’t support the attribute selector [attr="value"]. So there is no way to address that submit input element with CSS only (IE 6 doesn’t support the adjacence selector + and :last-of-type selector neither that would help in this case).
So the only options you have is to either make that element uniquely addressable by adding a class or ID or wrapping it into an additional span element.
Or – as you’ve already stated that you can’t do that – use JavaScript to select that element and apply the CSS rule to it. jQuery can make this fairly easy:
$("form input[type=submit]").css({
"background-color": "#FE9900",
"font-weight": "bold",
"font-family": "Arial,Helvetica,sans-serif",
"border": "1px solid #000066"
});