Ways to stylize bullet points in lists with CSS in HTML document

I am currently working on a Q&A page using simple HTML.

This is the current appearance of my page. Check it out here on JSFIDDLE.

My task involves adding an 'A' to the answer for each question. Some answers have multiple paragraphs, so the 'A' should only be added to the first paragraph and aligned similar to the 'Q.'

You can see an example of this format by visiting this Link.

Here is the HTML structure:

<h4>Frequently Asked Questions </h4>
<div >
    <ul>
        <li style="color: blue">
            Question heading 1
            <p style="color: #000000">
              answer para  1
            </p>
            <p style="color: #000000">
               answer para 2
            </p>
        </li>

        <li style="color: blue">
           Question heading 2
            <p style="color: #000000">
              answer para  1
            </p>
        </li>

        <li style="color: blue">
            Question heading 3
            <p style="color: #000000">
                answer para  1
            </p>
        </li>

        <li style="color: blue">
            Question heading 4
           <p style="color: #000000">
              answer para  1
           </p>
        </li>
    </ul>
</div>

This is the CSS styling applied:

<style type="text/css">
    ol {
        margin-left: 0;
        padding-left: 0;
    }
    li {
        display: block;
        margin-bottom: .5em;
        margin-left: 0em;
    }
    li:before {
        display: inline-block;
        content: "Q:";
        width: 2em;
        margin-left: -2em;
    }
</style>

Answer №1

Implemented modifications to the code. You can view the revised CSS on this JSFIDDLE link

Answer №2

 ul li:first-child::before {
        display: inline-block;
        content: "Q:";
        width: 2em;
        margin-left: -2em;
    }

apply the following style to your list items

Answer №3

I decided to enhance the readability of each answer by adding an 'A' before the first paragraph, just for my own satisfaction :)

A great practice is to eliminate inline styles and utilize external CSS for styling both questions and answers.

Snippet of HTML code:

<h4>Frequently Asked Questions </h4>
<div>
    <ul>
        <li>Question heading 1
         <p>answer paragraph 1</p>
         <p>answer paragraph 2</p>
        </li>

        <li>Question heading 2
          <p>answer paragraph 3</p>
        </li>

        <li>Question heading 3
          <p>answer paragraph 4</p>
        </li>

    </ul>
</div>

CSS stylings:

*{
    font-family: Arial;
    font-size: 12px;
}
ol {
    margin-left: 0;
    padding-left: 0;
}
li {
    display: block;
    margin-bottom: .5em;
    margin-left: 0em;
    color: #626F74;
    font-weight: bold;
}
li:before {
    display: inline-block;
    content: "Q:";
    width: 2em;
    margin-left: -2em;
}
li p{
    color: #000;
}
li p:first-child:before {
    display: inline-block;
    content: "A:";
    width: 2em;
    margin-left: -2em;
}

Link to Updated JSFIDDLE

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

The PHP counter conceals the comma upon loading and does not display it permanently

I'm currently working on a PHP counter and encountering an issue with the comma display. I have implemented Number Format in a PHP function to print counter digits with commas every 3 digits, but the comma doesn't remain visible after the page lo ...

What is causing these headers for the children not to center properly?

I am trying to centrally align both vertically and horizontally the <div> element, with its child elements <h1> and <h2> being horizontally centered in relation to the parent <div>. To achieve this, I have created a specific class f ...

Guide on reusing javascript to toggle between image sources

I have a simple website with buttons that, when clicked, change the image being displayed. However, I find myself repeating code for each button, and I'm wondering if there is a more efficient solution to this problem. Here is an example of what I cu ...

Angular 2 ngIf displaying briefly before disappearing

Encountering a strange issue with an Angular 2 ngIf statement where it appears on the page for a brief moment and then disappears. The content is visible, but it doesn't remain on the page. I suspect it might be related to some asynchronous behavior. ...

issue with transparent html5

Here is the code snippet I am struggling with: function clear(){ context2D.clearRect(0, 0, canvas.width, canvas.height); } function drawCharacterRight(){ clear(); context2D.setTransform(1, 0.30, 1, -0.30, 10, 380);//having issues here c ...

Hide the scroll bar in html/css while keeping the functionality of the arrows intact

Is there a way to remove the scroll bar but still be able to access overflown data using arrows? Any assistance would be greatly appreciated. Thank you in advance. ...

Adapt the dimensions of the iframe to perfectly match the content within

Looking for a way to dynamically adjust the size of an iframe to perfectly fit its content, even after the initial load. It seems like I'll need some kind of event handling to automatically adjust the dimensions based on changes in the content within ...

The changing of colors does not function properly when clicked in JavaScript

I am having an issue with a drop-down list that offers two options: blue and green. When I select blue and click on the text input field, its background color alternates between blue and black (the default text field color). The same applies when I choose ...

Discover the basics of incorporating libraries using npm

As a beginner in JavaScript, I am looking to incorporate moment.js or another library into my project. However, I am unsure of how to properly set up my project so that I can import from the library. Here is how I have structured my HTML: <!DOCTYPE html ...

Tips for creating a dynamic sidebar animation

I have recently delved into the world of web design and am eager to incorporate a sidebar into my project. While browsing through w3school, I came across a design that caught my eye, but I found myself struggling to grasp certain concepts like the 'a& ...

Tips for adding additional rows or cells to a table with jQuery

Similar Questions: How to Add Table Rows with jQuery Adding Rows Dynamically using jQuery. I am currently working with a table that contains one row and five editable cells for user input. My goal is to implement an "Add Row" feature using jQuery ...

Tips on customizing KendoUI-Dialog titlebar using CSS for a single component

I am struggling with styling the KENDO UI dialog in a unique way: Imagine I have a component named WatComponent. Inside this component, When the user clicks the "Forbidden" button, my goal is to make a warning styled dialog appear, with a yellow/orange ...

Encasing the bootstrap dropdown menu and trigger within individual parent divs for a tidier appearance

Is it possible to toggle a bootstrap dropdown when it is wrapped in another div by using attributes such as data-target or aria-labelledby? I have seen examples where data-toggle="dropdown" and class="dropdown-menu" are siblings. An example of what I am r ...

Add a new element to the page with a smooth fade-in animation using jQuery

var content = "<div id='blah'>Hello stuff here</div>" $("#mycontent").append(content).fadeIn(999); Unfortunately, the desired effect is not achieved with this code. I am trying to create a sleek animation when adding new content. ...

Ensuring the accuracy of user input in JavaScript, even after fixing a mistake and submitting again, will not cause the code to exit the else clause

I am currently working on a coupon code field that needs to accept a specific set of coupon keys. Below is the code I have written for validation. If a user enters an invalid key at first, they receive an alert saying "Invalid Key." However, if they corr ...

Ways to evenly distribute divs into rows

Greetings if this question has already been inquired about, but my search turned up nothing quite like it. My current setup is as follows: .main{ display: inline-flex; flex-direction: row; } <div class = "main"> <div class="sub-div ...

a pathway leading to the user's profile

I have successfully implemented a code that displays a list of people who are at level 8, which can be seen below Now, I want to make it so that when a user clicks on the username of the individuals listed, they will be redirected to their profile page. H ...

the hidden input's value is null

I am encountering an issue with a hidden input in this form. When I submit the form to my API, the value of the input is empty. Isbn and packId are both properties of a book model. However, for some reason, the value of packId is coming out as empty. & ...

Adjust the height of a div according to the width using CSS in a progressive manner

I'm looking to create a fluid container that adjusts its height gradually based on the width of the window (as the div's width is set to 100%). Similar to the behavior achieved with the aspect-ratio CSS rule, I want the height to smoothly increas ...

Open a file using the fs module while ensuring the original file is preserved

I've been working on a NodeJS API that sends emails. Each time I need to send an email, I use the index.handlebars template. To customize the template before sending the email, I utilize the Node File System (fs) module to readFileSync() and then ap ...