I am learning Blazor and at the moment I am trying to set an image as the background. I thought I would try display it first as the background-image css didnt work. I have attached a picture of my index.razor page and the img tag i am using is as follows:
<img src="file:///C:/Development/CsharpApplications/Portal/AlbertBartlettPortal/AlbertBartlettPortal/Pages/hero-range-1.jpg" alt="Background Image" />
It allows me to ctrl+click the file path and opens the image right away so it can see the image, but it wont display at all when the website is ran.
HELP!
Page Image Here
I put it in wwwroot\images and then used src="images/aaa.jg". No leading / OR ~/
I am trying to build a portfolio website, with a moving gallery but the image is not displayed, it shows the alternative image instead. Any help is appreciated.Here is the code:
<div class="section1">
<img class="imgr"src="photo_1.jpg" alt="nothing">
</div>
I even copied the relative path from Vscode, but it is still not working.
It must be the path to the image. Try replacing "photo_1.jpg" with "./photo_1.jpg".
item.imgSrc has a URL which takes time to load on screen. Is there any way to add a placeholder image or default image until the item.imgSrc image is fully loaded?
<div class="style" *ngFor="let item of array;
<div [style.backgroundImage]="url('+ item.imgSrc +')" class="image"></div>
</div>
You can use [ngStyle]="{'background-image':'url(' +imageUrl+ ')'}"
One way, You can create a directive to set a placeholder image for an element in html.
in your case, you can do as below also :
<div>
<img src="img/placeholderDefault.jpg" ng-src="{{item.imgSrc}} " height="150px " width="300px ">
</div>
where when your real image is loaded then it will replace the placeholderDefault image. and you can set the ng-src image base on your need in your desired scope.
If ng-src does not work in angular 2+ then, try
<img src="{{item.imgSrc}}">
or
<img [src]="item.imgSrc">
in this case, declare an object in your scope in the controller as
$scope.item={} and set $scope.item.imgSrc="defaultImagePath" and when your new
original image loads then replace with the original image path.
Hope this idea can help you
I am working on a sightly component using AEM 6.1. I have a dialog from where I am getting an image url and I want to set that image as background of a div.
What I am doing is:
<div class="hero" style= "background-image:url('/content/dam/home/hero.jpg');" >
So, /content/dam/home/hero.jpg value is coming as dialog property
I am trying as..
<div class="hero" style= "background-image:url('${properties.bgimage}');" >
Its not working. How can I set the background image from the dialog property?
Sightly doesn't detect the context of expressions within style and scripts automatically. We need to provide it explicity.
<div class="hero" style="background-image:url('${properties.bgimage # context='styleString'}');" >
More about Display Context here.
#context='uri' would also be an option, since it's technically a URI that the css property is expecting.
I've started using Bootstrap for a project, and in particular, the Thumbnails component. On the thumbnails example on the documentation, the following sample code is shown:
<ul class="thumbnails">
<li class="span4">
<a href="#" class="thumbnail">
<img data-src="holder.js/300x200" alt="">
</a>
</li>
...
</ul>
Notice the use of data-src to replace the usual src attribute on the <img> tag.
I assumed that to get my thumbnails working, I should use data-src instead of src for the images, but that does not seem to be the case. I've only been able to load images by defining the src attribute. It seems others are having the same problem.
Is this a typo in the documentation, or did I not understand correctly how to use data-src?
I believe that the only reason of why bootstrap guys are using data-src instead src, it's because of holder.js. You should use src instead of data-src because data-src is only used for the javascript library that generates the example images of a certain size, and src is the normal attribute for specifying the location of an image (Source: W3C)
Why are they using in the documentation data-src? I suppose that even the syntax <img src="holder.js/100x200"></img> is accepted by the library as it is in the holder.js documentation, when we access to the page it throws a 404 error in the image even when the image is displaying, because there is not any file in the specified path, what it's weird.
Why do they put that in the documentation code? I really don't know. Probably it's a mistake. But I am sure that you should use src instead data-src in thumbnails.
How to use it
Include holder.js in your HTML:
<script src="holder.js"></script>
Holder will then process all images with a specific src attribute, like this one:
<img src="holder.js/200x300">
The above tag will render as a placeholder 200 pixels wide and 300 pixels tall.
To avoid console 404 errors, you can use data-src instead of src.
Holder also includes support for themes, to help placeholders blend in with your layout. There are 6 default themes: sky, vine, lava, gray, industrial, and social. You can use them like this:
<img src="holder.js/200x300/industrial">
Bootstrap uses Holder for thumbnails in its documentation.
It's pretty well explained on the Holder github page.
Include holder.js in your HTML. Holder will then process all images with a specific src attribute... The tag will render as a placeholder. To avoid console 404 errors, you can use data-src instead of src.
In order for me to get this to work, I had to call the run() function in holder.
I am using require to load backbone views, inside my view I include holder
var Holder = require('holderjs');
Then inside render I can run
Holder.run();
And in my template I have
<div class="row">
<div class="col-sm-6 col-md-4">
<div class="thumbnail">
<img data-src="holder.js/200x200/text:hello world">
<div class="caption">
<h3>Thumbnail label</h3>
<p>...</p>
<p>Button Button</p>
</div>
</div>
Hope that helps.
I couldn't figure it out either, as far as I understand it holder.js is actually a completely separate js file to act as an img placeholder from http://imsky.github.io/holder/
data-src is used to pass to the javascript, the /100x200 is the dimension of the picture you want the javascript 'holder.js' to take up for the real img.
I think the idea is to prototype using this (data-src="holder.js/300x200") and then replace it with sized pictures (src="Logo.png") afterwards.
For future Googlers looking for how to use with NPM/build jobs this worked in my case:
window.Holder = require('holderjs').default;