Issues with the left and top margins of table cells persisting

Despite my attempts to add margin top and margin left, it doesn't seem to be working.

<li>li 1 <br/> new line</li>
<li>li 2 <br/> new line</li>

Here is the CSS code:

li {
    list-style: none;
    counter-increment: foo;
    display: table-row;
}

li::before {
    content: "-";
    display: table-cell;
    text-align: right;
    padding-right: 5px;    
}

You can view the example on this link.

Answer №1

Applying margins on a table-cell is not possible, and the approach you are taking seems unconventional. Consider utilizing CSS positioning techniques for a more efficient solution, like in this example:

Check out the demo here.

Another demo (Using margin on li elements)

li {
    list-style: none;
    margin-left: 15px;
    position: relative;
}

li::before {
    content: "-";
    position: absolute;
    left: -10px;
}

In this instance, CSS positioning techniques are employed to move the `-` prefixes outside the list item by applying a negative value for the left property. This allows for the use of margin-top and margin-left properties on your li elements, with the flexibility to adjust the position of the `-` as needed.

A helpful tip: Instead of using li for text wrapping, consider using p tags or <h2> / <h3> tags for better semantic structure. By doing so, you can eliminate the need for unnecessary <br> tags to separate lines, as these block-level elements will automatically create space for your content.

Answer №2

When styling a 'table-row', keep in mind that margin, padding, and height will not impact it. It is recommended to set the display property of your li elements to 'block' for proper alignment.

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

Can someone explain the purpose of `svg:not(:root) {overflow: hidden}` in simple

I am facing an issue with displaying my .svg file in my next-js project. It seems that the CSS code svg:not(:root) { overflow: hidden; } is causing the problem. Could someone explain what this particular CSS rule is for? After changing the code to svg:no ...

Why does my navbar seem to turn transparent when I hover over the cards?

Throughout this question, I will be using the following Codepen as a reference: https://codepen.io/zarif-codes/pen/OJOBmLV In my project for creating a product landing page (an FCC assignment), I've implemented a fixed navbar. Below is the HTML code ...

Customize the CSS styling of third-party components in different pages using NextJS

When working with third-party components, you can include their styles by importing their stylesheet into your component or _app.tsx file. For detailed instructions on how to do this, you can refer to Next.js documentation. Another option is to add the sty ...

Turn off HTML hyperlinks in Internet Explorer

I've been facing an issue in my application where I need to disable an HTML anchor using CSS. I found a solution on Stack Overflow that works perfectly in Chrome and Firefox. However, when I tried it in Internet Explorer, the link could not be disable ...

Creating an HTML email table that appears at the bottom when viewed in Outlook desktop

I am currently working on creating a responsive html email layout. Within the parent table, I have two nested tables - one on the left side and one on the right side. The issue I am facing is that in Outlook Desktop, the table on the right side is being pu ...

Mouse over effect to highlight the crosshair on a table

My code currently enables a crosshair function, but I am looking for a way to limit the highlight effect only within the cursor (hover) area. Instead of highlighting in a "cross" shape, I would like it to show a backward "L" shape. This means that the hig ...

Creating an HTML file with a Windows-inspired icon and file name design using CSS

I searched everywhere on the internet but couldn't find a solution. If anyone knows of a similar link to my question, please share it with me. I am trying to achieve a design similar to Windows icons and file names in HTML using CSS. Please refer to ...

Trouble receiving a reply from the Angular controller

I'm a newcomer to AngularJS and I'm currently working on integrating AngularJS into one of my existing applications. Below is the provided HTML and JavaScript code: <!doctype html> <html ng-app="ldlApp"> <head> <script src= ...

Is it possible to utilize Angular's structural directives within the innerHtml?

Can I insert HTML code with *ngIf and *ngFor directives using the innerHtml property of a DOM element? I'm confused about how Angular handles rendering, so I'm not sure how to accomplish this. I attempted to use Renderer2, but it didn't wor ...

Tables that adapt to different screen sizes, displaying perfectly on desktop but with slight variations on mobile devices

I recently experimented with a demo to enhance the performance of tables on my website in development. The demo worked flawlessly on my desktop when I resized using a responsive tester extension for Chrome: https://i.stack.imgur.com/KzFiR.jpg However, u ...

Tips for showing an image in a PHP document

UPDATE: Successfully resolved the issue by avoiding absolute file paths (../Images\City of Bath College Logo.jpg). 2nd UPDATE: Also implemented the same fix for the CSS file and now it functions "the HTML way". I'm encountering a problem displa ...

Using Python for text-to-speech with iSpeech

Can someone provide a sample code for using the iSpeech API (www.ispeech.org) to convert text to speech in my project? I am looking for examples in JavaScript, jQuery, or Python. ...

Function for when Tic Tac Toe results in a tie

I have developed a tic tac toe game using Javascript and now I have two questions. 1. How can I add a "start" button so that the game can only be seen or played after clicking on the button? And now for the challenging part: In case of a draw, I want t ...

What is the best way to display table rows for a specified date range?

I am working with a table and need to display only the rows that fall between two specific dates. <table id ="Table"> <thead> <tr> <th>Date</th> <th>Name</th> <th>Desc</th> </tr> </thead> ...

Utilize the :not() selector in combination with the :first-child() selector

Currently, I am seeking a method to merge two css selectors together in order to target specific elements. The selectors I am attempting to combine are ':not' and ':first-of-type'. Here is the code snippet that represents my current sit ...

``Why isn't the Bootstrap dropdown menu button displaying properly on a Leaflet map?

I am currently in the process of developing a LeafletJS Map integrated with Bootstrap buttons. I have successfully configured the map to be fullscreen and positioned the buttons on top of it. Below is the code snippet that I utilized for this setup: <! ...

What could be the reason behind the malfunctioning of my media query in the

I am trying to connect an external stylesheet to my React component in order to apply different styles based on screen width. Specifically, when the screen width is less than 300px, I want the logo to have a height of 100vh. However, it seems that the medi ...

Disable the time selection feature in the text input field

Despite seeing the same question asked before for this issue, I am looking for a solution that does not involve replacing the textbox with the same ID. When Timepicker is selected in the dropdown menu timepicker, it should activate in the textbox (which i ...

The z-index property seems to be malfunctioning when used in conjunction with the relative and absolute positioning

I have created a dropdown menu using pure CSS3, but I am facing an issue with the z-index property. The dropdown list is appearing above the menu when it should be dropping below it. I have spent all day trying to troubleshoot this problem to no avail, so ...

Changing Parameters in Absolutely Positioned Sections

I have successfully created a fixed header with a higher z-index than the body content, allowing the content to slide underneath it. To position the content div directly below the fixed header, I applied a position:relative and specified a top value. Init ...