Using both em and px units to add padding in CSS styling

Can padding be achieved using a combination of pixels and em units? For example, is it viable to apply padding-left with 2em plus 1px? Here's an illustration:

padding-left: 2em + 1px;

Answer №1

If you're searching for the calc expression, look no further.

https://developer.mozilla.org/en-US/docs/Web/CSS/calc

Here's an example to illustrate:

padding: -webkit-calc(2em + 1px);
padding: calc(2em + 1px);

Note that as of now, this property is still considered experimental. Before implementing it, make sure to consult caniuse to ensure compatibility with all browsers you are targeting.

Answer №2

Here's an example of how you can achieve this:

<div id="el">asdfasd</div>

#el {
    background-color:green;
    padding-left: 2em;
    margin-left: 1px;
}

See it in action on Fiddle!

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

Performance issues with jquery addClass and removeClass functions observed in Internet Explorer 11

I am currently working on an application that monitors nodes within a cluster, and I have created a visual state example to demonstrate this. Each small box in the grid represents a node, and when hovering over a node, the rest of the nodes in that particu ...

Having issues with -ms-filter not functioning in IE while using Angular 4

Having trouble with filters not functioning in IE browser when using angular 4. Below is the CSS code snippet: .style{-ms-filter: grayscale(50%); -ms-filter: brightness(70%);} ...

Django, nginx, and gunicorn team up but fail to load or serve any static files

As I prepare to make my page public, I encountered an issue after setting up nginx + gunicorn. The page loads fine, but the CSS is not loading despite no errors being shown in the nginx log file. Here is a snippet from my nginx.conf: server { listen ...

Divs that are floated and only partially visible at the end

My layout consists of 6 Divs floated left to create 6 columns. The width of all these floats combined may extend beyond the window width for most users, especially with the 6th column included. Is there a way for this 6th column to be partially visible ( ...

Print out - find elements by class name in the console

I'm currently learning how to use HTML5 Drag and Drop. I have a table created with PHP that generates HTML elements. echo "<li class='elements' id='".$row['id']."' draggable='true'>".$row['element_n ...

Developer server experiencing CSS issues in Django admin interface

Experiencing some odd issues with the Django admin application here. I've got everything up and running on the manage.py runserver development server, but for some reason it looks like this: This obviously isn't what I want, so I'm trying t ...

HTML: Trim the perimeter borders

My goal is to recreate the design shown in the image. I attempted to achieve this using the border-radius property, but unfortunately I could not replicate it accurately. ...

Is it possible to apply a CSS transition to a div when hovering over a specific area of the

Allow me to elaborate on the current project I am working on. I am in the process of creating an index on a website that is contained within a div element positioned off-screen using CSS margins, with only a portion of it visible. When you hover over the v ...

Achieving flexbox's equal height for Bootstrap's Navbar and content

I am faced with the challenge of designing a layout where a content grid occupies the entire remaining page, while also incorporating a navigation bar. To achieve this, my approach involves placing the navigation bar within a flex container and the conten ...

Error: The render function in ReactJS components did not return anything

While attempting to create a new component and call it within App.jsx (another component) for rendering, an error is being encountered. Error: Error: App(...): Nothing was returned from render. This usually means a return statement is missing. Or, to rend ...

Executing Basic Authentication in Javascript through window.open()

After a user logs into my app, they have the option to download a CSV file from the server by clicking on a button. The URL for the download is secured with basic authentication. When attempting to open the URL using the code below: window.open('http ...

Navigating sections of a webpage in IIS

My IIS server hosting a "dummy" website on a 2008 server redirects users to the correct web page. Due to historical reasons, this server is known as "mail.abc.com". Although "mail" has taken on different meanings now, people still type in that name or ha ...

Eliminate the ending question mark when using the form method=get

Whenever I click a form button that redirects me to a page, it keeps adding a trailing question mark at the end of the URL. Here's an example: http://example.com/folder/upload/? This is how my code currently looks: <form method="get" act ...

When Angular fails to bind the correct values in *ngIf

I'm currently utilizing the code below within ngOnInit() in order to bind content in the HTML, but I'm facing an issue where nothing is being displayed on the webpage! Can someone offer some guidance or assistance, please? TypeScript: public ngO ...

Showing a solo item from an array in HTML using Angular

How can I display the account name instead of the accountId property value from my list of transaction items? I have a list of transactionitems with an accountId property, and all accounts are loaded in the accounts$ array. However, I am having trouble us ...

The CSS flex display is not evenly aligned on the second row

I recently started learning about display: flex, and I'm still trying to get the hang of it. As you can see in the screenshot below, even after removing some content, the last two items are not behaving like the first row. I've tried different th ...

Learn the process of implementing typewriter animation across multiple strings with CSS

Looking to achieve a typewriter animation effect on multiple strings? While most developers use JavaScript for this, I managed to create it using CSS. However, I've only been successful with two strings so far. Whenever I attempt a third string, it en ...

Increasing the nth-child Selector in Jquery

Referring to this I am looking to cycle through the nth-child selector, which involves: var i = 1; var tmp = $(this).find('td:nth-child(i+1)'); // I wonder how this can be achieved i++; I have rows with dynamically generated columns i ...

The HTML button with Google's material-icons appears noticeably small when displayed on mobile devices

Looking to design a basic HTML page with a button placed in the lower right corner? Check out the code below: <!DOCTYPE html> <html> <head> <title>Sample Page</title> <style> /* Styles for the container * ...

Elements are receiving CSS properties from other elements within the same component

I'm encountering an issue with my components: 1. I cannot seem to style html and body in signin.component.css for some reason. The workaround I found was using: encapsulation: ViewEncapsulation.None ==> This works perfectly However, when I switch ...