Steps for setting a background image behind radio buttons

I am currently facing a challenge in adding a background image to a div that contains some radio buttons and updating it dynamically with Angular based on the current page.

app.controller('thingCtrl', function ($scope, $rootScope, $routeParams) {
    console.log("Inside thingCtrl");
    $scope.title = "Thing";
    $scope.talkingPointsImage = "img/thing.svg";
}
main:after {
  opacity: 0.25;
  width: 200px;
  height: 200px;
  top: 0;
  left: 0;
  position: absolute;
  z-index: -1;
  content: "";
}
<div class="main" style="background: url({{talkingPointsImage}});">
<div class="talking-points">

<h2>{{title}}</h2>
<ul>
    <li ng-repeat="issue in subCategories">
        <input type="radio" name="radio" ng-model="question.stance" ng-value="-1"> {{issue.issue}}
    </li>
</ul>


</div>
</div>

<!-- begin snippet: js hide: false -->

I am encountering difficulties in achieving the desired display. The data binding using {{}} is functioning properly, but I am struggling to achieve the correct sizing.

The image is being displayed without transparency and is not correctly sized.

1) It should have transparency to create a faint appearance and stay in the background without obstructing the foreground information, which should remain clickable.

2) It should be resized appropriately to fit behind the information, possibly around 200px by 200px.

Answer №1

This answer may not be optimal due to a particular limitation.
It is necessary to define a fixed size for the height and width of the background image if you intend to accomplish this solely using CSS.
A solution is available, but it involves a bit of jQuery manipulation. Although I personally prefer alternative methods, I will provide it here in case you wish to experiment with it.
If you want the image's width and height to match those of the content div, simply uncomment the jQuery code below:

/*$(document).ready(function() {
    $("#first").css("height", $("#second").height());
    $("#first").css("width", $("#second").width());
});*/
#main {
    position:relative;
}
div#first {
    background-size: cover; /* use this to stretch the background */
    opacity: 0.2;
    width: 500px;
    height: 300px;
    overflow: auto;
}
div#second {
    position: absolute;
    top: 0;
    left: 0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="main">
    <div id="first" style="background-image: url('http://placehold.it/500x500');"></div>
    <div id="second">
        <div class="talking-points">
            <h2>{{title}}</h2>
            <ul>
                <li ng-repeat="issue in subCategories">
                    <input type="radio" name="radio" ng-model="question.stance" ng-value="-1">{{issue.issue}}
                </li>
            </ul>
        </div>
    </div>
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for preventing harmful messages in a chat room app

As I am working on a chat room website, users are able to input any content they want into the entry field and then send it to all online users. However, I have concerns about security - what if malicious individuals try to inject harmful HTML or JavaScrip ...

Variables for Angular Material themes

My app has multiple theme files, and I select the theme during runtime. .client1-theme{ // @include angular-material-theme($client1-theme); @include all-component-colors($client1-theme); @include theme-color-grabber($client1-theme, $client1-a ...

How to Retrieve Data from a JSON Object in AngularJS Using $http.get

I am attempting to access the JSON object generated by the Google API. function getMarvelHeroes() { return $http.get('https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA') .then(getM ...

CSS margin-left causing issues in Chrome Extension

My current situation is incredibly puzzling, as I am at a loss for what is happening. I developed a Firefox add-on using jQuery and CSS to revamp a website. When attempting to transfer the add-on to Chrome (which was relatively straightforward due to the s ...

Enhance your viewing experience by magnifying a specific element, all while maintaining full control to navigate

Is it possible to create a zoom effect on a webpage that focuses on one specific element while still allowing for navigation and scrolling? I have searched online for plugins like Fancybox and Zoomooz, but none of them offer the functionality I need. I sp ...

Tips for ensuring responsive images do not cause blocks to jump down

How can we address the issue of blocks jumping after an image loads while still maintaining responsiveness? Codesandbox. Key points to consider: The image should resize when the window is resized. The maximum width of the image is its own width. We do n ...

Encountering unexpected behavior with the .data() method

I'm encountering an issue with my code <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv= ...

How can I prevent opening duplicate tabs of the same website simultaneously?

Is there a way to prevent users from accessing the same website page from multiple tabs? Could this be accomplished using JavaScript? ...

Enroll a nearby variable "Data" to an Observable belonging to a different Component within an Angular application

Looking to update the HTML view using *ngIf, depending on a local variable that should change based on an observable variable from a shared service. HTML <div class="login-container" *ngIf="!isAuthenticated"> TypeScript code for the same componen ...

Images that have been resized on Android appear blurry when viewed on the second page

Customizing the Toolbar: #main_bar { background: url(../images/logo.jpg) 99% 50% no-repeat; background-size: auto 80%; } The original size of logo.jpg is 220x266px The toolbar has a fixed height of 46px Therefore, the background image appears t ...

Utilizing background image CSS class repetitively

I have a button background class that I want to reuse multiple times. How can I keep all the common styles separate and only change the URL multiple times? Here is my CSS: .menuBtnColour{ position: relative; //common top: 0;//common left: 0;/ ...

Tips for relocating several buttons to the upper right corner

I have a dilemma with the positioning of 10 buttons on my webpage. Specifically, I would like to place them in the top right corner, but they are currently at the bottom. Can you assist me with moving the buttons? My desired outcome can be seen here. I s ...

Learn the process of moving the focus to the next input type using AngularJS

There are four input text boxes for entering credit card numbers. I am looking to automate shifting focus to the next input field. I know how to do this using normal jQuery, but I want to achieve it using Angular. Can anyone offer some guidance? Thank you ...

Having trouble getting my angular form validation to function properly

Even though I disabled Bootstrap's validation while using Angular, the validation for every input field still doesn't work. It seems like I have everything set up correctly. My code looks like this below with no success on input validation: < ...

Can you provide me with a variable that will give me the total size of the scrollbar?

How can I determine the maximum number of pixels scrolled on a webpage? I attempted using window.pageXOffset, but it only gives the current scrolled amount. I require the total size at all times. ...

Combining AngularJS promises with jQuery AJAX promises

After successfully processing the data sent from the factory to the server, the ".then" in the controller is not being executed as expected. I would appreciate it if you could provide insight into why the "then" part is not triggering in the controller fo ...

Disable the click event using jQuery

$("button").click(function (){ $("<button>Start</button>).appendTo('main'); }); The code above introduces a functionality where clicking a button generates another button dynamically. However, each subsequent click kee ...

Enhancing image clips using jQuery techniques

Could someone help me figure out why the image clip value isn't changing when I move the range slider in the code below? $('#myRange').on('input', function() { var nn = $(this).val(); $("img").css({ 'clip': ...

Image not found in PDF created from HTML to PDF conversion

I am currently utilizing the HTML-pdf library to convert an HTML page into a PDF format. While the dynamic content is being displayed in the generated PDF, there seems to be an issue with the image not appearing as expected. Despite trying various methods, ...

Material UI - Array of Chips

I have been working on creating a ReactJS component that displays an array of chips with unique styling for each one. To achieve this, I created individual makeStyles classes for the chips. However, I encountered difficulties in dynamically changing the cl ...