Fine-tuning components in HTML and CSS

Is there a way to align the asterisk symbol with the text and adjust the positioning of the Yes and No elements as depicted in the image?

https://i.sstatic.net/mCsUG.png

Check out this fiddle: https://jsfiddle.net/07bd0hda/ and snippet below:

<div class="dependents-covered-elsewhere">
  <div class="dependents-covered-elsewhere-asterisk">*</div>
  <label data-bind="text: i18n('dependents.coveredElsewhere')">Is the dependent covered elsewhere?</label>
  <input type="radio" name="coveredElsewhere" value="1" data-bind="checked: coveredElsewhereForBinding, enable: !(isTab() &amp;&amp; emprel_id &amp;&amp; vm.home.action() == 'life-events')" disabled="">
  <div data-bind="visible: field.isModified() && !field.isValid(), attr: {title: field.error}" class="info" style="display: none;">
  </div>

  <label>
    <!-- ko i18n:'yes' -->Yes
    <!-- /ko -->
  </label>

  <input type="radio" name="coveredElsewhere" value="0" data-bind="checked: coveredElsewhereForBinding, enable: !(isTab() && emprel_id && vm.home.action() == 'life-events')" disabled="">
  <div data-bind="visible: field.isModified() && !field.isValid(), attr: {title: field.error}" class="info" style="display: none;">
  </div>


  <label>
    <!-- ko i18n:'no' -->No
    <!-- /ko -->
  </label>
</div>

The CSS styles I applied:

.dependents-covered-elsewhere {
    max-width: 340px;
    margin-left: 5px;
}

Answer №1

To emphasize the importance of your *, I utilized a span element as it naturally displays inline

Additionally, a CSS rule was implemented with the first-of-type pseudo-class to target only the initial label and change its display to block

.dependents-covered-elsewhere label:first-of-type {
  display:block;
  }

.dependents-covered-elsewhere-asterisk{color:red;}
<div class="dependents-covered-elsewhere">

<label data-bind="text: i18n('dependents.coveredElsewhere')">Is the dependent covered elsewhere? <span class="dependents-covered-elsewhere-asterisk">*</span></label>
<input type="radio" name="coveredElsewhere" value="1" data-bind="checked: coveredElsewhereForBinding, enable: !(isTab() &amp;&amp; emprel_id &amp;&amp; vm.home.action() == 'life-events')" disabled=""><div data-bind="visible: field.isModified() &&!field.isValid(), attr: {title: field.error}" class="info" style="display: none;">
</div>

<label><!-- ko i18n:'yes' -->Yes<!-- /ko --></label>
        
<input type="radio" name="coveredElsewhere" value="0" data-bind="checked: coveredElsewhereForBinding, enable: !(isTab() &amp;&& emprel_id &amp;&amp; vm.home.action() == 'life-events')" disabled=""><div data-bind="visible: field.isModified() && !field.isValid(), attr: {title: field.error}" class="info" style="display: none;">
</div>
 
        
<label><!-- ko i18n:'no' -->No<!-- /ko --></label>
    </div>

Answer №2

Enhance your HTML structure by incorporating <div> for options and <span> for asterisks.

Take a look at the code snippet provided below or check out the revised version on JSFiddle:

<div class="dependent-info">
     <label data-bind="text: i18n('dependents.info')">Provide dependent information</label>
     <span class="dependent-info-asterisk">*</span>
     <div class="option-container">
       <input type="radio" name="infoStatus" value="1" data-bind="checked: infoStatusBinding, enable: !(isTab() &amp;&amp; emp_id &amp;&amp; vm.home.action() == 'info-events')" disabled=""><div data-bind="visible: field.isModified() &amp;&amp; !field.isValid(), attr: {title: field.error}" class="notification" style="display: none;">
</div>

<label><!-- ko i18n:'complete' -->Complete<!-- /ko --></label>
        
        <input type="radio" name="infoStatus" value="0" data-bind="checked: infoStatusBinding, enable: !(isTab() &amp;&amp; emp_id &amp;&amp; vm.home.action() == 'info-events')" disabled=""><div data-bind="visible: field.isModified() &amp;&amp; !field.isValid(), attr: {title: field.error}" class="notification" style="display: none;">
</div>
 
        
        <label><!-- ko i18n:'incomplete' -->Incomplete<!-- /ko --></label>
        </div>
    </div>

We trust this will be beneficial for you!

Answer №3

All you need to do is enclose the div that contains the asterisk within a span element:

<div class="dependents-covered-elsewhere">
  <span class="dependents-covered-elsewhere-asterisk">*</span>
  <label data-bind="text: i18n('dependents.coveredElsewhere')">Is the dependent covered elsewhere?</label>
  <input type="radio" name="coveredElsewhere" value="1" data-bind="checked: coveredElsewhereForBinding, enable: !(isTab() &amp;&amp; emprel_id &amp;&amp; vm.home.action() == 'life-events')" disabled="">
  <div data-bind="visible: field.isModified() &amp;&amp; !field.isValid(), attr: {title: field.error}" class="info" style="display: none;">
    </div>

  <label>
    <!-- ko i18n:'yes' -->Yes
    <!-- /ko -->
  </label>

  <input type="radio" name="coveredElsewhere" value="0" data-bind="checked: coveredElsewhereForBinding, enable: !(isTab() &amp;&amp; emprel_id &amp;&amp; vm.home.action() == 'life-events')" disabled="">
  <div data-bind="visible: field.isModified() &amp;&amp; !field.isValid(), attr: {title: field.error}" class="info" style="display: none;">
    </div>


  <label>
    <!-- ko i18n:'no' -->No
    <!-- /ko -->
  </label>
</div>

Answer №4

Is this enough?

CSS:

.dependents-covered-elsewhere-asterisk { position: absolute; top: 0px; left: 0px; }

Answer №5

Here are some alternative approaches that can be used without altering your markup structure:

  1. You can position the asterisk element to the right of the label using absolute positioning

  2. To create a clear visual separation, convert the yes-or-no checkboxes into block elements by applying display: block

Refer to the demonstration below for implementation details:

.dependents-covered-elsewhere {
  position: relative;
  display: inline-block;
}
.dependents-covered-elsewhere-asterisk + label {
  display: block;
}
.dependents-covered-elsewhere-asterisk {
  position: absolute;
  right: 0;
  transform: translateX(100%);
}
<div class="dependents-covered-elsewhere">
  <div class="dependents-covered-elsewhere-asterisk">*</div>
  <label data-bind="text: i18n('dependents.coveredElsewhere')">Is the dependent covered elsewhere?</label>
  <input type="radio" name="coveredElsewhere" value="1" data-bind="checked: coveredElsewhereForBinding, enable: !(isTab() &amp;&amp; emprel_id &amp;&amp; vm.home.action() == 'life-events')" disabled="">
  <div data-bind="visible: field.isModified() &amp;&amp; !field.isValid(), attr: {title: field.error}" class="info" style="display: none;">
  </div>

  <label>
    <!-- ko i18n:'yes' -->Yes
    <!-- /ko -->
  </label>

  <input type="radio" name="coveredElsewhere" value="0" data-bind="checked: coveredElsewhereForBinding, enable: !(isTab() &amp;&amp; emprel_id &amp;&amp; vm.home.action() == 'life-events')" disabled="">
  <div data-bind="visible: field.isModified() &amp;&amp; !field.isValid(), attr: {title: field.error}" class="info" style="display: none;">
  </div>


  <label>
    <!-- ko i18n:'no' -->No
    <!-- /ko -->
  </label>
</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

Changing the margin-top of a nested div within a parent container div will cause both elements to be displaced downwards from the main body

I am facing an issue that I believe is a result of something silly I may have done, but I can't seem to pinpoint it. Here's a demonstration page illustrating my problem. Below is the source code for the page: <html> <head> <ti ...

How can I effectively showcase the content of a text file in HTML using Flask/Python?

Let's discuss the process of displaying large text/log files in HTML. There are various methods available, but for scalability purposes, I propose taking a log file containing space-separated data and converting it into an HTML table format. Here is ...

Generate a custom JavaScript file designed for compatibility with multiple servers

I am looking to develop a JavaScript file that can be easily added to other websites, allowing them to access functions within my database using an API similar to the Facebook like button. This API should display the total likes and show which friends have ...

What is the reasoning behind beginning the transition with autofocus enabled?

After creating a contact form with autofocus="autofocus", a strange behavior was noticed. It seems that when the form has autofocus, the transition effect on the navigation bar is triggered in Firefox only. Is this an error on my end or just a bug specific ...

Customizing the Appearance of HtmlEditorExtender

Having an ajax HtmlEditorExtender featured on my webpage has been quite a challenge. I followed the instructions provided here: http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/HTMLEditorExtender/HTMLEditorExtender.aspx The issue arises from t ...

"Animating an HTML element to track the movement of the mouse pointer

I'm currently working with an html element that looks like this: <img src="./pic/char.png" width="30" height="30" alt="me"> I'm wondering if anyone knows how to make this html element move towards the cursor using javascript. Any help wou ...

How to avoid clipping in Bootstrap 4 when a row overflows with horizontal scrolling

In order to allow for horizontal scrolling of all contained columns, I created a row using the row class. To implement this feature, I followed advice from a contributor on Stack Overflow. You can view their answer by following this link: Bootstrap 4 hori ...

Modify CSS to switch body background image when a DIV is hovered

Feeling a bit lost on where to start with this issue. My divs are positioned as desired on the page. Just to clarify, I am utilizing CSS Grids for this. In short, all I'm wondering is if it's possible to change the background of the body elemen ...

What are some ways to ensure text stands out against a gradient backdrop?

Is there a way to ensure that text adjusts automatically to a background transition from one color to another using only CSS? I've tried using "mix-blend-mode:difference" from a forum, but it had no effect on the text. .container{ color: white; ...

JQuery button refusing to trigger点击

I've searched high and low on various coding forums but still can't find a solution. My HTML code is as follows: <input type="button" value="Sign Up Here" id="buttonClick"> and I have a script at the top that looks like this: < ...

Navigating to a specific page based on the selected option is the key to efficient web browsing

I'm currently working on a form development project and I'm looking for guidance on how to navigate to different pages based on the selection made in a radio button. Here's the current form setup with two radio buttons: .sh_k .sh_sl { ...

Form submission not functioning within a bootstrap popover

I'm having trouble saving a URL from an input field (the form is inside a Bootstrap popover) - nothing happens when I click the save button. Below is my HTML code: <div id="popover-content" class="hide"> <form name ="bform" method = "post" ...

Solutions for altering the appearance of a combobox using CSS

Currently, I am experimenting with javafx 2 and trying to modify the background color of the menu/list through CSS. Despite attempting the code snippet below, nothing seems to be working as expected. Do you have any suggestions or insights on how to achi ...

Is there a delay when dynamically filling out an input field in a form with the help of the jquery .keypress() function?

I have a form that I want to populate dynamically with the values from another form. It's almost working as intended, but there seems to be a delay of some sort. For example, if I enter "ABCDE" in field1, field2 will only populate with "ABCD". It ne ...

What could be causing justify-content: flex-start; to not function as expected?

Can someone help me with my flexbox navbar? I set the justify-content property to flex-start, but the content inside the container is not aligning correctly. You can see the output and code here: output html, body { backgr ...

"Exploring the differences between an ASP.NET checkbox and an HTML

I have encountered an issue with an HTML checkbox with the ID "notice" in the code behind file. How should I declare it? I have written the code as follows, but it is showing an error that "notice" does not exist in the current context. notifying = ((noti ...

Connecting CSS styles and images to my EJS templates on a distant Express server using Node.js (Ubuntu 18.04)

I have been hunting for a solution here extensively, but every attempt has failed. So, here's the issue I'm facing: I have created a basic Express server locally to display a static page until I finish full integration. The structure of my site ...

What could be causing my AJAX form to refresh the page upon submission?

I have been working on a basic Follow/Unfollow system, and although the functionality is working correctly in terms of inserting and deleting rows when following/unfollowing, I'm facing an issue where the page refreshes every time despite using e.prev ...

PrimeFaces: Achieving Conditional Coloring Based on Status (Passed/Failed)

Attempting to dynamically change the color of a column based on its status value (Passed/Failed/InProgress) using jQuery. I tried copying and pasting the table into jsfiddle, where it worked. However, when implemented in the actual XHTML file, the jQuery ...

Safari showing white flash upon setting background-image src using Intersection Observer?

I've done extensive research but I'm still struggling to solve this issue. It only seems to be happening on Safari (Mac & iOS), while everything works smoothly on Chrome, Firefox, Edge, and other browsers. UPDATE: The flickering problem also per ...