The presence of a display block property within a div contained inside an li element results in extra whitespace

I am presenting the code below:

<div class="settingsMenu" style="top: 135px; left: 149px; display: block;">
        <ul>
            <li class="download" onclick="downTemplate('template1')">Download</li>
            <li class="delete" onclick="showConfirmationDialog ($(this))">
                Delete
                <div class="deleteItemConfirmation">
                    <div class="confirmationText">Are you sure?</div>
                    <div class="buttons"><button onclick="deleteTemplate ('template1')">Yes</button> <button onclick="hideConfirmationDialog();">No</button></div>
                </div>
            </li>
            <li class="info">Info</li>
        </ul>
    </div>

CSS:

.settingsMenu{
    position: absolute;
    top: 0;
    left: 0;
    display: none;
    background-color: #FFFFFF;
    border: 1px solid #b5044a;
    border-radius: 5px;
    width: 150px;
    padding: 10px 0;
    margin: 0;
    z-index: 200;
}

.settingsMenu ul{
    list-style-type: none;
    width: 100%;
    margin: 0px;
    padding: 0;
}

.settingsMenu ul li {
    color: #000000;
    cursor: pointer;
    float: left;
    font-size: 14px;
    font-weight: normal;
    font-family: Arial;
    height: 18px;
    max-width: 100px;
    margin: 5px 20px;
    padding: 0;
    display: block;
    padding-left: 30px;
}

.settingsMenu ul li.edit{
    background: url("../img/edit-context-menu-icon.svg") no-repeat scroll center left white;
}

.settingsMenu ul li.delete{
    background: url("../img/delete-context-menu-icon.svg") no-repeat scroll center left white;
}

.settingsMenu ul li.info{
    background: url("../img/info-context-menu-icon.svg") no-repeat scroll center left white;
}

Issue is: when div.deleteItemConfirmation has "display: none;", everything displays correctly. But, when its display property changes to "display: block," a strange space appears before the text of

<li>Delete</li>

Answer №1

Consider making a modification

<li class="delete" onclick="showConfirmationDialog ($(this))">
    Delete

Instead of

<li class="delete" onclick="showConfirmationDialog ($(this))">Delete

Answer №2

Here is a helpful tip:

<ul>
<li>
one</li><li>
two</li><li>
three</li>
</ul>

You could also try this alternative:

<ul>
  <li>one</li
  ><li>two</li
  ><li>three</li>
</ul>

Or if you prefer with comments...

<ul>
  <li>one</li><!--
  --><li>two</li><!--
  --><li>three</li>
</ul>

This technique was inspired by an article I found at http://css-tricks.com/fighting-the-space-between-inline-block-elements/ and has been useful in similar situations.

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

React Material-UI eliminates the 'content' property from the CSS pseudo-element

Creating a React MUI Box and styling it like this: <Box id='my-box' sx={{ '&::before': { content: 'Yay! ', backgroundColor: 'red' } }} >Life is beautiful</Box> However, duri ...

After uploading the WordPress theme, the wp_enqueue_style() function fails to work properly

I recently developed a new WordPress theme and encountered an issue while trying to load specific stylesheets for my child sites using the is_page(array('')) function in my function.php file. Surprisingly, only the files that were added to all of ...

What causes TypeScript to interpret an API call as a module and impact CSS? Encountering a Next.js compilation error

My website development process hit a roadblock when I tried integrating Material Tailwind into my project alongside Next.js, Typescript, and Tailwind CSS. The compilation error that popped up seemed unrelated to the changes, leaving me baffled as to what c ...

What is the best method for automating the transfer of data from a database to the user interface of a website using html and javascript?

As a volunteer coordinator for a non-profit organization, I have some basic experience working with Python. I am willing to dedicate fewer than 8 hours of learning time to my current project in order to automate certain tasks (or else I will do them manual ...

Setting a fixed height for layout with scroll functionality in Twitter Bootstrap 3.2.0

I am currently working on a design layout using bootstrap 3.2.0. I have managed to create a Fixed header and footer, and I am now facing the challenge of having a full-height container with independent scrollbars. Are there any effective methods in Twitter ...

Combining different HTML table borders

Here is some example code: <!DOCTYPE html> <html> <body> <h4>Creating a table with nested tables:</h4> <table border="1"> <tr> <td>100</td> <td>200</td> <td> </td> < ...

Steps for altering the primary color in PrimeNG__Changing the primary color

What is the most effective way to modify the default primary color for primeNG (saga-blue theme)? Altering --primary-color does not have the desired effect, as elements in node_modules/..../theme.css are styled using the main color hex rather than '-- ...

Guide to showing an HTML string retrieved from MongoDB with the help of Express

I need help with displaying or rendering an HTML string retrieved from the database. Any assistance would be greatly appreciated. Below is the controller function responsible for rendering the data: exports.previewPageView = (req, res, next) => { / ...

Place a material-ui React component at the center of a footer section

I'm facing a challenge with centering a material-ui Simple Breadcrumbs component within a footer as opposed to having it aligned to the left. Even though I'm new to this, I thought it would be straightforward but I can't seem to figure it ou ...

The jQuery function fails to execute when the script source is included in the head of the document

I'm relatively new to working with scripts and sources, assuming I could easily add them to the header and then include multiple scripts or functions afterwards. Everything seemed to be working fine at first, but now I've encountered a problem th ...

prevent parent jQuery functions from interfering with child function execution

I am facing an issue with conflicting jQuery functions between parent and child elements. The child function is a bootstrap function, while the parent is a custom function. The main objective is to limit the height of the parent div (refer to the code belo ...

Creating code to ensure a div element is displayed only after a specific duration has elapsed

Can anyone help me with coding to make a div appear on a website after a specific amount of time? Here's an example of what I'm trying to achieve: <div class="container"> <div class="secretpopout"> This is the hidden div that should ...

What could be causing my SVG bezier curves to malfunction in Firefox?

Encountered an issue today where diagrams I have generated are not functioning properly in Firefox when created using the getPointAtLength method. Here is a demonstration of the problem: http://jsfiddle.net/xfpDA/9/ Please take note of the comments at th ...

Different ways to manipulate the CSS display property with JavaScript

Having trouble changing the CSS display property to "none" using JavaScript. Check out my code: <div class="mydiv" onClick="clickDiv1()">hello</div> <div class="mydiv" onClick="clickDiv2()">hi</div> <div class="mydiv" onClick=" ...

ways to run php script based on screen resolution or size

I have 2 php files that I need to execute based on screen size. include_once('large.php'); include_once('small.php'); The condition is to run large.php when the screen size is greater than 992px, and small.php when the screen size is ...

The select2 plugin seems to be having trouble recognizing the Li click functionality

I have a select menu that is using the select2 plugin. I am trying to add a class to the <select> element when a menu option is clicked, but it doesn't seem to be working as expected even after testing with an alert. https://jsfiddle.net/ysm4qh ...

How can Selenium in Python be used to click a JavaScript button?

I need help automating the click of a button on a webpage using selenium Here is the HTML for the button: <div class="wdpv_vote_up "> <input value="7787" type="hidden"> <input class="wdpv_blog_id" value="1" type="hidden"> </div& ...

Determine whether to show or hide a div based on the width of the

Is there a way to dynamically hide a div using Bootstrap 4 based on the screen width? Can this be achieved without using JavaScript? I am particularly interested in hiding certain text elements that are not relevant on smaller screens, such as mobile de ...

The document.write function in JavaScript is malfunctioning

I've been attempting to utilize the javascript function document.write to incorporate an external css file in my template. However, I am aiming to achieve this using Twig, like so: document.write('<link href="{{ asset('bundles/activos/cs ...

Wrapper Div at the Center

I'm currently working on aligning my webpage in the center using the following CSS: .wrapper { display: flex; align-items: stretch; background: #fafafa; /*max-width: 1520px; */ box-shadow: 1px 1px 12px rgba(0, 0, 0, 0.1); text ...