I'm using Play framework.
In a template it is possible to do the following to include css.
<link rel="stylesheet" media="screen" href="#routes.Assets.at("stylesheets/main.css")">
But what I would like to do is to include the css right into the webpage
<style>#[include the static file contents]</style>
Is that possible?
As others mentioned it is NOT preferred way, anyway you can use common 'tags' technique for doing this,
just create a file views/tags/yourStyles.scala.html with content:
<style>
* {
background: orange;
}
</style>
so in your template/view you can use it as (sample):
<head>
<title>#title</title>
<link rel="stylesheet" media="screen" href="#routes.Assets.versioned("stylesheets/main.css")">
<link rel="shortcut icon" type="image/png" href="#routes.WebJarAssets.at("images/favicon.png")">
#tags.yourStyles() <!-- <-here ->
</head>
Related
CSS is working when i write route
Route::get('/showproduct', [ShowController::class,'index'])->name('showproduct');
Also Controller: ShowController
public function index()
{
//
return view('home.showproduct');
}
But in that way
Route
Route::get('/showproduct/{id}', [ShowController::class,'index'])->name('showproduct');
And Controller: ShowController
public function index($id)
{
//
return view('home.showproduct',['id'=>$id]);
}
Just html is comes, css and javascript not installing.
View folder name also showproduct.blade.php in home folder.
It seems you include css and js is reference to relative/current directory like below:
<link rel="stylesheet" type="text/css" href="style.css">
<script src="script.js"></script>
You should add a leading slash (/) to the path like below:
<link rel="stylesheet" type="text/css" href="/style.css">
<script src="/script.js"></script>
or could be better use asset() to use a full URL
<link rel="stylesheet" type="text/css" href="{{asset('css/layouts/style-horizontal.css')}}">
<script src="{{asset('js/plugins.js')}}"></script>
I have a simple MVC project and I want to start design it with CSS file,
I created a Style/StyleSheet.css file with this content:
body {
background-color:green;
}
and added the link to it inside _Layout.cshtml, with this line:
<link href="#Url.Content("~/Style/StyleSheet.css")" rel="stylesheet" type="text/css" />
I don't see any change of the background color, what am I doing wrong ?
Help will be Appreciated ! Thanks !
Try basic html:
<link href="/Style/StyleSheet.css" rel="stylesheet" type="text/css" />
or change "..." inside the string to '...' :
<link href="#Url.Content('~/Style/StyleSheet.css')" rel="stylesheet" type="text/css" />
I have a large ASP.Net app to which I am trying to add a JQuery/Bootstrap multiselect dropdown (can't add this to Fiddle - to large). I am using a Bootstrap CDN/API to add the multiselect and generic Bootstrap css and js. There is a table in my application. Before I added the Bootstrap, it looked like this.
After I add the bootstrap, it looks like this:
Basically, the word-wrap: break-word; attribute seems to be getting messed up. I have the Boostrap added before my custom css stylesheet as recommended by other posts:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css"/>
<script type="text/javascript" src="//d3js.org/d3.v3.min.js"></script>
<script type="text/javascript" src="//code.jquery.com/jquery-1.12.4.js"></script>
<script type="text/javascript" src="//code.jquery.com/ui/1.12.0/jquery-ui.js"></script>
<link href="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.3/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-multiselect/0.9.15/css/bootstrap-multiselect.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-multiselect/0.9.15/js/bootstrap-multiselect.min.js" type="text/javascript"></script>
<link rel="stylesheet" href="//js.arcgis.com/3.26/esri/css/esri.css?parameter=1"/> <%--"parameter= 1" prevents intellisense error --%>
<link rel="stylesheet" href="Content/Style/Style.css"/>
The table has its own id's for the element and children called #checkBoxesTable.
#checkBoxesTable > tr > td {
word-wrap: break-word;
}
...
.bootstrap-overrides #checkBoxesTable > tr > td {
padding: 10px;
word-wrap: break-word;
}
I've even tried to create a class (see above and below) to override any Bootstrap ids or classes but it doesn't seem to work (the table is dynamically created under the scenarios id in the Default.asmx file). Is there anything else I can try to get the word-wrap to work?:
<div id="scenarios" class="bootstrap-overrides"></div>
After much research, the problem here was the version of generic bootstrap I was using. I went to the multi-select gitHub documentation and looked in the index.html file for their example, which used the following:
<link href="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.2/js/bootstrap.min.js"></script>
Once I upped the version to 3.3.2, it worked (with my override class of course).
I'm creating an express app and my CSS code stops working whenever i add an ":ID" parameter to the URL. I know it's a filepath issue because bootstrap still comes in fine, but on the page with the ID parameter it shows this: "Refused to apply style from 'https://XXXXXX.c9users.io/unapproved/main.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled."
main.css is in my /public folder, but it looks like it's looking in a folder titled "unapproved".
I've tried changing the routing order, i've tried changing my app.use(express.static(__dirname)) code.
here's my app.get:
app.get("/unapproved/:id/", function(req, res){
var invoiceID = mongoose.mongo.ObjectId(req.params.id);
InvoiceObj.findById(invoiceID,function(err,foundInvoice){
if(err){
console.log(err);
}else{
res.render("invoiceScreen",{invoice:foundInvoice});
}
});
here's my html:
<% include partials/header %>
<h1><image src="<%= invoice.imageUrl %>"</h1>
<% include partials/footer %>
here's my header:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Invoice system</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="main.css">
<link href="https://fonts.googleapis.com/css?family=Cabin" rel="stylesheet">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr" crossorigin="anonymous">
<script src='https://code.jquery.com/jquery-2.1.4.js'></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
</head>
<body>
I think change to css path absolute path will solve your problem
<link rel="stylesheet" href="/main.css">
In this kind of situation, it's better to use virtual path for your static files because relative path doens't work very well; like:
Assuming folder structure:
app.js
public
| +-- main.css
app.use('/static', express.static(__dirname + "/public"))
And in you html, make path absolute
<link rel="stylesheet" href="/static/main.css">
instead of using ./ or ../ before your assest(images / css / js ) for example.
./css/style.css or css/bootstrap.css ../images/example.png
you can use / for example
/css/style.css or /css/bootraps.css /images/example.png
/ will tell your app to look from root dir.
How do I add a class in html2pdf?
I have tested
$stylesheet = file_get_contents('../printpdf.css');
but this does not work.
Please try with add css with type="text/css" to your html
<link rel="stylesheet" type="text/css" href="style.css">