using angular ng-style on an image tag to call out a background image - css

I'm trying to conditionally display an image with ng-style.
I've tried all the suggestions listed here (and in the docs) but nothing seems to work.
first try:
<br/>
<img alt="" ng-style="{'background-image':'url(\'https://www.google.com/images/srpr/logo4w.png\')'}">
<br/>
second try:
<br/>
<img src="" alt="" ng-style="{'background-image':'url(\'https://www.google.com/images/srpr/logo4w.png\')'}">
<br/>
third try:
<br/>
<img src="" alt="" ng-style="{background-image:'url(https://www.google.com/images/srpr/logo4w.png)'}">
<br/>
fourth try:
<br/>
<img src="" alt="" ng-style="{background:'url(https://www.google.com/images/srpr/logo4w.png)'}">
Here's a JSFiddle

The background-image doesn't make sense with the <img> element so you need to use ng-src instead of ng-style.
Also, you're missing the ng-app attribute in your example so Angular isn't actually running.
So a working example would be:
<div ng-app>
<img ng-src="https://www.google.com/images/srpr/logo4w.png">
</div>
Although, I guess you can use ng-style on other elements, like a div. Just make sure it has content in it so the background actually shows up:
<div ng-app>
<div style="padding: 20px;" ng-style="{'background-image':'url(\'https://www.google.com/images/srpr/logo4w.png\')'}">This is some content</div>
</div>

Related

How to achieve equal spacing in same height columns bootstrap?

I am building a website to display images in an specific grid. I am using Laravel and Bootstrap for this project.
The goal is to create a grid with spacing that maintains the images heights. To create a space between the divs I added a border right to the images, but when I do that it also creates a border bottom at the first two divs, which makes the first two images have a smaller height than the last one.:
Image: https://gyazo.com/9bd97d19073a123966a652e3603ebfd4
[![As you can see the first two rectangles have a border bottom instead of just the border-right]
For reference this is the kind of grid that I am trying to create:
https://gyazo.com/337d9e044a56e327e0c7e69069ae5c17
https://www.zarahome.com/pt/%C3%BAltima-semana/cole%C3%A7%C3%A3o-c1020095502.html
This is the code I have so far:
<div class="row g-0 mx-0">
<div class="col-md-3">
<img src="https://i.ibb.co/Ky415Wt/imageonline-co-placeholder-image-2.jpg" alt="" class="img-fluid" style="border-right: 10px solid white;">
</div>
<div class="col-md-3">
<img src="https://i.ibb.co/Ky415Wt/imageonline-co-placeholder-image-2.jpg" alt="" class="img-fluid style="border-right: 10px solid white;">
</div>
<div class="col-md-6">
<img src="https://i.ibb.co/r5LDwny/imageonline-co-placeholder-image-3.jpg" alt="" class="img-fluid" style="border-right: 10px solid white;">
</div>
</div>
I simply dont understand why adding a border-right also adds a border-bottom. I tried adding a margin instead but this causes the bigger image to jump out of the row, like so:https://gyazo.com/5a785de16398756021dd843ba038cbc6
Could someone help me to achieve this result?
https://gyazo.com/337d9e044a56e327e0c7e69069ae5c17
I am assuming you are using Bootstrap 4 to create this since in your tags it shows bootstrap-4. The reason why your code would not work is that g-0 comes from Bootstrap 5. It might have been that you looked at the Bootstrap v5 documentation.
If you are using bootstrap 4 then you can add no-gutters to the div containing row.
To keep the images the same height I'd add some custom css and add the 40vh in there.
I have made an example for you to take a look at:
https://www.codeply.com/p/BqPXPxcP2j
A coleague helped me achieve the best solution, so I will post what sworked in case someone faces the same issue:
<div class="d-row d-flex gap-2 justify-content-center" style="margin-bottom: 100px">
<div class="col-md-3">
<img src="https://i.ibb.co/Ky415Wt/imageonline-co-placeholder-image-2.jpg" alt="" class="img-fluid">
</div>
<div class="col-md-3">
<img src="https://i.ibb.co/Ky415Wt/imageonline-co-placeholder-image-2.jpg" alt="" class="img-fluid">
</div>
<div class="col-md-6">
<img src="https://i.ibb.co/r5LDwny/imageonline-co-placeholder-image-3.jpg" alt="" class="img-fluid">
</div>
</div>

Styling lost when placing a <div> inside a <a> tag

Currently, I have a box which has some text inside it. Currently, the link is only applied to some text as below:
<div class="row text-banner-blocks">
<div class="col-sm-4 header-text-banner text-center">
<!-- gray-border -->
<div class="box">
<h3>Free delivery worldwide*</h3>
<a href="#">
*More info here
</a>
</div>
</div>
This is how it appears on the site:
https://snag.gy/sbC421.jpg
However, I want the whole link placed in the whole box and as with HTML I just place the tag inside the tag but I seem to lose all the styling and the padding goes I think? Code:
<div class="row text-banner-blocks">
<div class="col-sm-4 header-text-banner text-center">
<!-- gray-border -->
<a href="#">
<div class="box">
<h3>Free delivery worldwide*</h3>
<br/>
*More info here
</div>
</a>
</div>
This is how it looks after:
https://snag.gy/KZzSUv.jpg
Any help is greatly appreciated!
I think you are referencing the .box div using a css selector that requires the parent element to be a div
so you might have to change the css for the box element to something like
a > .box {
/* styles */
}
check this image for more info
Decided to do it with JavaScript inside using the below for the parameters of the div tag:
onclick="document.location='#'"
This solution is neater for what I am after and as I am using several style sheets it was difficult to spot the culprit.

Why won't my images center using Bootstrap?

I'm new to html/css and am trying to make a straight-forward webpage, which is just several images centered horizontally, each on their own row. I ended up using Bootstrap's basic html template, and can't figure out what's wrong with the code below. My images are stuck on the left edge of the page. The only CSS I'm currently using is the default linked one: "css/bootstrap.min.css"
This is all that's currently in my body:
<div class=“container-fluid”>
<div class=“row”>
<img src="..." class=“img-responsive center-block”>
</div>
<div class=“row”>
<img src="..." class=“img-responsive center-block”>
</div>
</div>
Your quotation marks ("") seem to be broken in your img's class. Don't know what your actually using but change them to normal quotation marks and it should work.
<div class="container-fluid">
<div class="row">
<img src="..." class="img-responsive center-block">
</div>
<div class="row">
<img src="..." class="img-responsive center-block">
</div>
</div>

Bootstrap 3: Centering an image

Here is my jsFiddle with full code example.
I couldn't figure out how to upload my placeholder.png image and so it appears broken, but nevertheless, I am trying to figure out how to get it centered underneath the <h3> tag. My attempt to center it:
<image src="placeholder.png" style="text-align: center;" />
...isn't working for some reason. Any idea as to why?
Add class text-center to parent container and remove style="text-align: center;" from image, it's not needed:
<div class="col-md-12 text-center">
...
<img src="placeholder.png" />
</div>
Demo: http://jsfiddle.net/kLzah1x4/1/
here you go - easy way of doing it.
http://jsfiddle.net/kLzah1x4/2/
<h3 style="text-align: center;">
<img src="placeholder.png"/>
</h3>

jQueryTools Scrollable - jumps to last image in circular mode

jQuery Scrollable (with the navigator plugin) is showing the wrong slide when it first loads.
It behaves normally when I use it like this:
$(".scrollable").scrollable({}).navigator();
…but as soon I enable the 'circular' mode (to allow looping from the final slide back to the first):
$(".scrollable").scrollable({ circular: true }).navigator();
on page load, the final item is the first one show, even though item 1 is highlighted in the navigator. If you go through the images, when you get to the final one, it's shown a second time, and you only see the actual first image at the beginning of the second loop.
Any suggestions?
Here's my HTML for completeness:
<div class="column two-thirds scrollable" id="scrollable">
<a class="prev browse left">Previous</a>
<div class="items">
<div><img src="1.jpg" alt="" /></div>
<div><img src="2.jpg" alt="" /></div>
<div><img src="3.jpg" alt="" /></div>
<div><img src="4.jpg" alt="" /></div>
</div>
<a class="next browse right">Next</a>
<div class="naviWrapper">
<div class="navi"></div>
</div>
</div>
Here is a link to the same issue, suggesting that you replace your <img> tags with <div> tags that have a background image.
https://github.com/jquerytools/jquerytools/issues/47
I could not do that as some of my images had image maps. However, all my images had the same dimensions, so I put in image dimensions, i.e.
<img width=730 height=360 alt="first image" src="/images/my-image.jpg" />
And that seems to have solved it.

Resources