Laravel: Background image will not appear - html

Right, so I'm trying to add a background image to my website. However, The image just won't appear. The path is correct but it just comes up blank when I load the page. Do you have to do something special to the path in Laravel for it to work? I am also using a master blade file which all other views extend, I'm not sure if this affects it.
Here is my CSS:
html {
background: url("/storage/background/background_1.jpg");
}

You are not able to find the image because /storage is not accessible from the server. How to fix it is to make a symlink via the artisan command:
php artisan storage:link
Or you could ofcourse store your image in public/img/yourimage.png and call it like this:
html {
background-image: url("/img/yourimage.png");
}

Here is the working code:
style=" background:url('<?php echo "/yourFolderOfImage/$item->item_img1" ?> ')"

try adding the style of the background image on the head section of the page. works for me.

Related

Adding Background Image Using CSS

In my django project I try to add background image to html template. But it does not work my code is like this
background-image: url("/img/bg.jpg");
error
GET http://127.0.0.1:8000/img/bg.jpg 404 (Not Found)
Please help me to fix this
I try it different ways...
Project Structure
Try this:
background-image: url("./img/bg.jpg");
Also can you post an image showing structure of your project?
replace your bakground- image with this code
background-image: url("{% static "/img/bg.jpg" %}");
after that add this in your setting file
STATICFILES_DIRS = [ os.path.join(BASE_DIR, 'templates').replace('\\','/'), ] follow this answer in stackoverflow [stackoverflow link][1] hope it works.

Change title of Keycloak login

I want to know how to change title on login page via Keycloak?
The easiest way is to change the following line in themes/base/login/messages/messages_[your_language].properties.
loginTitle=Log in to {0}
However, I suggest you should read the official document and create your original theme.
You can change to themes[your theme]\login\resources\css\login.css
You can add like this
/* Title */
#kc-page-title::after {
content: " to MyHomeLogin"
}
I suggest the following if you are working with a custom theme.
Go to themes/base/login.
Copy the file template.ftl
Go to themes/custom/login -> 'custom' or the name of your theme
Paste the template.ftl file there
Open template.ftl
Search for the element
Replace the content with your desired text
Save it and reload the page
I prefer this method because it only overwrites the base theme at runtime without making any changes to the base theme directly. Thanks.

cant add background image in rails

I've been trying to add a background image to my rails app but no matter what I try I cant get it to work, this is basic stuff and I don't know what's going wrong. I had it working yesterday but my computer crashed and I hadn't saved my view file after adding the background image.
I've tried:
<body background="bg.png">
as well as:
background-image: url(/assets/bg.png);
and even:
body {
background: url(bg.png);
}
but nothing will work, what am I doing wrong?
To serve the image from asset-pipeline do the following:
body {
background: image-url(bg.png);
}
To use it inline under .erb files:
<div style="background-image: url('<%= asset_path('some_image.jpg') %>') ">
What you are trying to do would work if the image was placed under public folder.
Similar questions: How to set a background image in rails from css?
If the image is in public directory then
background-image: url('/bg.jpg')
If image in app/assets/images/bg.jpg
background-image: url('/assets/bg.jpg')
Also, set the below mentioned setting in developement.rb(or other environment on which you are running the code)
config.serve_static_assets = false
config.assets.compress = true
config.assets.compile = false

how to add background in Django2.0 using html or css

I want to add an image inside my django homepage, but I always cannot get the correct location of the image file I want(yellow high light)
The picture below are the thing I type so far:
https://i.stack.imgur.com/ecyQu.png
also in the same file
{% load static %}
body {
background-image: url('{% static "/bitcoin.jpg" %}');
}
Do I need static whenever I want to insert image in Django2.0? also,
I see some people open separate static file and some ppl put image inside the templete. I am confused where I should put? How can put the background image inside the html??
thank you so your answering!!!!
update ** this is what I have so far
enter image description here
updat2 ** the only refer to admin file only,
enter image description here
You can use inline CSS just for that case. You already have a .wrapper element, so if you want to put a static served image you'd do something like this:
<div class="wrapper" style="background-image: url('{% static 'default_page/bitcoin.jpg' %}');">
Your content here
</div>
If you want to use in your CSS files, just use the absolute path according to your static configuration. If you serve your static files using /static (that means, the path /static/default_page/bitcoin.jpg is correct and shows you the desired image), you can just put into the CSS something like:
body {
background-image: url('/static/default_page/bitcoin.jpg');
}
Hope that works!
EDIT:
As Thomas said, you've placed the image in the wrong folder (inside templates instead of on your static files folder). Refer to this to configure your project the right way.
You've placed your bitcoin.jpg in the same folder as your templates. Django serves all static file, such as pictures, from the static directory. Only templates go in the template directory. Create a directory called static inside your hompage app, create a directory inside that called default_page, and place your background image there. Restart the dev server, and your image should appear.

html img tag not working because wrong path generated Rails 4

I have a div tag in my rails application (new.html.erb):
<div style="background: url(images/background.jpg) no-repeat;">
</div>
The image is not appearing and I get a ActionController routing error No route matches [GET] "/locations/images/background.jpg"
The problem is that Rails is adding locations/ to the file path which is wrong since my image is correctly located in app/assets/images/background.jpg.
Even if I include the absolute path of the file I'll get locations added to the beginning of it.
Here are my routes (not sure if that helps but it won't hurt!):
locations GET /locations(.:format) locations#index
POST /locations(.:format) locations#create
new_location GET /locations/new(.:format) locations#new
edit_location GET /locations/:id/edit(.:format) locations#edit
location GET /locations/:id(.:format) locations#show
PATCH /locations/:id(.:format) locations#update
PUT /locations/:id(.:format) locations#update
DELETE /locations/:id(.:format) locations#destroy
You need to generate the url using the image_path helper inside your view:
<div style="background-image: url('<%= image_path('background.jpg') %>'); background-repeat: no-repeat">
</div>
The helper is important, because in production your assets could be fingerprinted or hosted remotely (e.g. on a CDN). The helper will always generate the correct url.
Edit:
To reference a background image in a css file, you have two choices. Using base rails, you can add .erb to the end of your css filename and use code substitution as above.
stylesheet.css.erb:
.myclass {
background-image: url(<%= asset_path 'background.png' %>);
}
Alternatively, if you are using the sass-rails gem, you can use image-url or asset-url helpers:
stylesheet.scss:
.myclass {
background-image: image-url('background.png'); // or asset-url('background.png');
}
See the Asset Pipeline Guide for more information.