CSS inline-block element disregarding margins and padding

Recently, I've been delving into the world of CSS and trying out "display:inline-block" as an alternative to "display:float". The general consensus from documentation is that properties commonly used on block elements can also be applied to inline-block elements. Things like "height", "width", "margin", and "padding" are usually mentioned.

While setting height and width has worked without issues for me, it seems that setting margin or padding doesn't have any effect in IE9 or Firefox 32. I haven't come across any examples where these properties are set either.

I prefer using margins and padding, especially since my content varies in width. Have I missed an example somewhere that addresses this issue?

Here's a snippet of code that I've been working with:

.lnk2 a {
display: inline-block;
margin: 2px 1em;
padding: 2px 2em;
}

<div class="lnk2">
 <a href="rates/minneapolis-55401.htm">55401</a>
 <a href="rates/minneapolis-55402.htm">55402</a>
 <a href="rates/minneapolis-55403.htm">55403</a>
</div>

Regardless of the values assigned to "margin" or "padding", the display remains unchanged in both browsers.

In my original HTML, the "div" was actually an "ol" and each "a" tag was enclosed in an "li" pair. However, the outcome was the same - I simplified the above HTML structure to troubleshoot the problem.

Answer №1

Utilizing floated elements is another effective method for eliminating unnecessary gaps

.nav-link a {
display:block;
float:left;
margin: 3px 1em;
padding: 3px 2em;
}

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

How to position a div in the center of another div using HTML

I'm struggling to center the bottom div within a container that includes 3 other divs. Despite trying multiple solutions found online, nothing seems to work. This task should be simple, but for some reason, I can't get it right. .container { po ...

How do I modify the sidebar width with CSS code?

I am trying to adjust the width of the right sidebar on my website. The current layout leaves too much empty space on the right side and makes it appear crowded next to the main content and images in the center. Despite exploring various solutions provide ...

Troubleshooting Problems with Positioning and Floating in HTML and CSS

I'm facing some challenges with clearing floats (or it could be something else?). My goal is to have the #newsbar div free from the previous floats so that its width can extend 100% across the page/browser. I believe I've tried everything within ...

Delete the line-height property from the initial line

I have created text that is aligned using the "justify" option, and I would like to add some leading to the text. However, I want the first line of the text to remain at x:0px y:0px. Does anyone know how to remove the line-height from the first line of a ...

obtain the image number by extracting a portion of the text

How can I extract the image number from a string using the sub-string function? I have applied the sub-string function to the property below. It returns 3 at the end in Chrome, but it does not work properly in Mozilla. Issue : After "-->", when I chec ...

Ways to align radio buttons vertically

I am currently working with three radio buttons that are initially aligned horizontally, but I would like to change their alignment to be vertical instead. What is the best way to achieve this? * { margin: 0; padding: 0; box-sizing: border-b ...

Is there anyone who can assist in refining the padding and margin issues within this Galleria.js implementation?

I am struggling to understand why the padding and margins around the images in this slideshow theme on PregoApp are uneven. Despite my attempts to adjust the CSS, the issue persists. You can view the site here. Another website using the same implementati ...

Easy ways to manipulate the style of array components in Vue.js

Hey there all you programmers, I'm reaching out to see if any of you have insight on how I can modify the style of a specific component within an Object array. This is the code snippet: <template> <div> <ul> <li v-fo ...

How to show a tooltip inline by utilizing CSS styling

Working on a sticky side bar menu with a tooltip feature. While it appears correctly in Chrome and Safari, the tooltip is off-center in IE. This snippet seems to be causing the issue: /* Vertically center tooltip content for left/right tooltips */ .tool ...

Enable the text to wrap around an interactive object that the user can freely manipulate

Looking for a solution where I can have a floating div that can be moved up and down using javascript while the text wraps around it seamlessly. Similar to how an object positioned in a word document behaves, I want the text to flow around the div both ab ...

Arranging links in a horizontal line (JSFiddle)

CodePen: https://codepen.io/example/abc123 I am attempting to align the elements "Favourite", "0", and "Reply" next to each other so they appear as: Favourite 0 Reply ...

Selecting the first child within a table using the first-child

I recently set up a login portal page for three different websites. The layout consists of three separate login portals displayed neatly in two columns within a table named "loginPortals". I am currently working on styling the page using CSS, aiming to enh ...

Troubleshooting Problem with Web Forms and Bootstrap Form Design

Currently, I am utilizing a simplified version of the Admin LTE Bootstrap Theme in an ASP.NET Web Forms Project. In this project type, only one form tag can be used per page. The form tag must encapsulate both the Top (Nav) and Bottom (Side Bar Left & Mai ...

The vertical-align property fails to properly align the list-style-image with the text

My HTML list is structured like this: <ul id="remove"> <li id="rm_txt_1" onClick="remove_1();">Remove </li> </ul> <ul id="move"> <li id="mv_txt_1" onClick="position();">Move Down</li> </ul> It is styled u ...

What is the most effective method for creating a dark background with light text in Bootstrap without using SASS?

I recently created a new website using Bootstrap 5 and set the background color to black (#000000) by adding some CSS styling. However, I noticed that this change had unintended consequences on the appearance of various elements such as drop shadows, modal ...

How can I design a custom status update box inspired by the look and feel of Facebook

I have searched extensively online for a guide on creating a CSS box similar to Facebook's status update callout box. This box features a square shape with a small notch at the top. Could someone assist me in crafting a CSS design for this type of bo ...

What is the best way to specifically target header elements within article elements using a CSS selector?

As someone who is not well-versed in CSS, I am looking to target specifically the header elements within article elements. I have some understanding of selectors such as #, ., or ,. article header article, header article.header article#header I believe t ...

Using CSS to style multiple IDs within a class group

Can someone help me get this css code functioning properly? #inventoryGarbageSpot .id1,.id2,id3,id4{ padding:0px; padding-top: 0px; width:35px;} When I use a single id instead of multiple ids, it works fine. Appreciate your assistance, Rotem ...

Having trouble understanding why the border-radius attribute is not being applied to tables?

I've been trying to give the outer corners of tables a rounded appearance in HTML/CSS, but I can't seem to get the border-radius property to work properly. After inspecting the elements in Chrome's computed section, I noticed that the eleme ...

What is the process for modifying a Joomla plugin?

Just starting out with Joomla development and recently installed Joomla 2.5 on my local computer for some practice. I have a question about editing Joomla plugins - specifically the layout of the Content - Pagebreak plugin (the pagination that appears wh ...