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>
Related
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'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.
I need compress CSS and JS files without "multiple css files to one".
My IDE: PhpStorm
My Framework: Laravel 5.3
For example:
I need compress this file:
<link rel="stylesheet" href="/fonts/fonts.css">
<link rel="stylesheet" href="/site/css/menu.css">
<link rel="stylesheet" href="/site/css/select2.css" />
<link rel="stylesheet" href="/site/css/bootstrap.css">
to:
<link rel="stylesheet" href="/fonts/fonts.min.css">
<link rel="stylesheet" href="/site/css/menu.min.css">
<link rel="stylesheet" href="/site/css/select2.min.css" />
<link rel="stylesheet" href="/site/css/bootstrap.min.css">
I use this code in Gulpfile.js:
gulp.task('BootstrapCss', function () {
gulp.src('public/site/css/bootstrap.css')
.pipe(cssmin())
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest('public/site/dist/css'));
});
Is a code should be written for each file?
Fixed Answer
You can try the foreach gulp module to iterate over all files and minify each separately.
var foreach = require('gulp-foreach');
gulp.task('BootstrapCss', function () {
gulp.src('public/site/css/*.css')
.pipe(foreach(function(stream, file){
return stream
.pipe(cssmin())
.pipe(rename({suffix: '.min'}))
}))
.pipe(gulp.dest('public/site/dist/css'));
});
Old Answer
Just use a catch-all *.css. I've replaced bootstrap.css with *.css below:
gulp.task('BootstrapCss', function () {
gulp.src('public/site/css/*.css')
.pipe(cssmin())
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest('public/site/dist/css'));
});
I am new to Spring MVC and i am having a problem with CSS. When the URL ends with slash CSS does not work.
link goes like this
<link rel="stylesheet" href="themes/style.css">
mvc:resources mapping
<mvc:resources mapping="/themes/**" location="/WEB-INF/themes/"/>
and requestMapping goes like this
#RequestMapping("/login")
public ModelAndView loginPage() {
ModelAndView model = new ModelAndView("login");
return model;
}
So the problem is when i enter a URL like ../login the css loads normally, but when i enter ../login/ with ending slash, then the css does not load.
Well there are many similar questions in here, but none of them is for Spring MVC.
Instead of
<link rel="stylesheet" href="themes/style.css">
try this:
<link rel="stylesheet" href="/themes/style.css">
When you use href="themes/style.css" then for url like: .../login/ the request url for css file looks like:
.../login/themes/style.css
which is incorrect. When you use href="/themes/style.css" then it always should result with:
.../themes/style.css
Update:
If it is jsp page, then add
<%#taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> on top of the page
and change:
<link rel="stylesheet" href="themes/style.css">
into
<link rel="stylesheet" href="<c:url value="/themes/style.css" />">
it will work 100%
step 1
<mvc:resources location="/WEB-INF/assets/" mapping="/resources/**"></mvc:resources>
setp 2
<spring:url var="css" value="/resources/css/"/>
<spring:url var="js" value="/resources/js/"/>
<spring:url var="image" value="/resources/image/"/>
add a slash after value
step 3
add your style sheet like this
<link rel="stylesheet"
href="${css}/common/bootstrap.min.css">
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>