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

Replace existing styled-component CSS properties with custom ones

One of my components includes a CheckBox and Label element. I want to adjust the spacing around the label when it's used inside the CheckBox. Can this be achieved with styled()? Debugging Info The issue seems to be that the className prop is not b ...

Navigating Dynamically between tabs - A How-to Guide

I am working on a mat-tab Angular app where I need to dynamically generate links and transfer them to a navLinks object. Despite ensuring that the concatenation is correct, it seems like my approach is not working as expected. Here's a glimpse of what ...

Utilizing AngularJS Factory to Share Data Among Controllers

Following a tutorial on YouTube for Sharing Data between Controllers, I am facing an issue where the two inputs do not return shared data that is bind-able. Can someone please help me identify what might be wrong in my code? <!DOCTYPE html> ...

When using the GET method to load a PHP file via AJAX, the page may not display certain jQuery plugins even after the file

Hello, I am a beginner learning AJAX and JQuery. Maybe this is a silly question, but please bear with me. I am trying to dynamically show data without refreshing the page using AJAX. I have a function loaded in the body tag which handles this. Everything ...

Challenges Encountered with AngularJS $http Service

How do I pass my data from the http request to the $scope in the MainCtrl? The code below should fetch data from a MySQL Database with an $http-service, but somehow the data provided by the service doesn't go to the controller or gets displayed incor ...

The web server is now serving Index.html instead of main.js for AngularJS 2

Transitioning from an angular1 application to an angular2 one, I encountered an error after removing the ng-app directive and adding the system.config: Error: SyntaxError: Unexpected token < Evaluating https://localhost:8080/contents/app/main.js Error ...

Creating characters dynamically based on the length of user input in VSCode Snippet

Here is a simple vue-html snippet: { "BANNER1": { "prefix": "banner", "body": ["<!-- ----------------", "/// $1", "--------------------- -->"] } } This sni ...

Issue with ng-checked not detecting boolean values retrieved from local storage

I'm working on a code snippet in my controller where I have a checkbox in my HTML with "ng-checked="enterToSend" and "ng-click="enterToSendCheck()" attached to it. $scope.enterToSend = localStorage.getItem('enterToSend'); $scope.enterToSen ...

Elemental SVG Animation

I'm currently exploring the world of animating svg objects using CSS. I have successfully learned how to animate a path with: @keyframes stroke_fill { 0% { fill: white; } 50% { fill: white; stroke-dashoffset: 0; ...

Retrieve the data file using input text with jQuery

Is there a way to extract data like this? data:application/pdf;base64,JVBERi0xLjQKJeHp69MKMSAwIG9iago8PC9UeXBlIC9DYXR…AKdHJhaWxlcgo8PC9TaXplIDE4Ci9Sb290IDEgMCBSPj4Kc3RhcnR4cmVmCjg4MzEzCiUlRU9G from an input file? $('#file').change(functio ...

Tips for preventing a table from showing up while scrolling unnecessarily when utilizing a heading with the CSS position property set to 'sticky'

Currently, I am facing an issue with creating a sticky header for my table. The problem arises when the header of the table has rounded edges (top right and top left) along with a box-shadow applied to the entire table. As the user scrolls through the tabl ...

Is it possible to retrieve JavaScript object properties using HTML elements?

I have fetched an array of objects using jQuery.getJSON(). Each object should be represented by an HTML div element, allowing users to click on the element and access all properties of the corresponding object. What is the most efficient approach for achie ...

Guide to transmitting HTML form information to a different web server with the click of a button

I operate two distinct web servers. One is responsible for the front-end (example.com), and the other manages the back-end (api.example.com). On my front-end server (example.com), there is a simple HTML website with a form that includes an input field and ...

Transforming Symbol Characters into HTML Using VB.NET

I want to make sure that any characters in my database entry that are not numeric or alphabetic get converted to HTML code. After doing some research, I came up with the following function: Public Shared Function HTMLEncodeSpecialChars(text As String) As ...

Create an HTML form that sends email notifications using a third-party form backend platform

I recently designed a form using Webflow and integrated it with Getform.io for the backend platform. Everything is running smoothly, including data collection and file uploads. However, I now want to enhance the form by enabling it to automatically send ...

What's the reason the element inside the <div> is not displayed when a value is selected in the dropdown box?

I am perplexed as to why the element inside the does not appear when a value is selected in the drop down box. However, it works perfectly fine in JSFiddle: JSFiddle Below is my HTML code and Jquery script that functions properly in my own system: <t ...

The AngularJS 2 application reports that the this.router object has not been defined

My function to sign up a user and redirect them to the main page is implemented like this: onSubmit(){ this.userService.createUser(this.user).subscribe(function (response) { alert('Registration successful'); localStor ...

Is it possible for my OAuth2 callback page to share the same HTML page? Also, what is the process for obtaining the token?

In my setup, I am working with static html and javascript along with C# Web API. One of the scenarios I encountered involves a link that triggers an oauth2 server from my HTML file named index.html. The question arises: Is it appropriate to establish the c ...

Div refuses to clear floats

Working on an app at and encountering an issue with the main container not clearing floats, causing overflow on the content. Attempted to use this CSS: .clearfix:after { content:""; display: table; clear: both; } Added the class to the main ...

Discover the ultimate guide to harmonize IE 9 with the ingenious Bootstrap Multiselect plugin developed by davidstutz

I've come across an amazing plug-in developed by David Stutz that allows for a Bootstrap and jQuery multi-select options list. Here are some resources: Check out the source code on Github Find documentation and examples here This plug-in works fla ...