Skip to content
Advertisement

Tag: css

Get the Size of a CSS Background Image Using JavaScript?

Is it possible to use JavaScript to get the actual size (width and height in pixels) of a CSS referenced background image? Answer Yes, and I’d do it like this… Some notes… We need to remove the url() part that JavaScript returns to get the proper image source. We need to split on , in case the element has multiple

Align div with fixed position on the right side

I want to show a div which is always visible even as the user scrolls the page. I have used the CSS position: fixed; for that. Now I also want to show the div at the right hand corner of the parent div. I tried to use this CSS code to achieve the goal: But it doesn’t align the element

jQuery’s offset() function

I know jQuery does most when it comes to cross-browser issues. I just wanted to know if offset() method of jQuery serves the purpose of cross-browser compatibility, I mean top, left, etc properties that can be derived from it? Basically once I apply top, left, etc properties (which are derived from offset() function) to an element, I need to make

How to create an on/off switch with Javascript/CSS?

I want to have a sliding switch. On the left would be Off and on the right would be On. When the user toggles the switch, I want the ‘slider’ portion to slide to the other side and indicate it is off. I could then have a callback that takes as input the state of the toggle switch so I

Can we create onclick popup without Javascript in CSS?

Can we create onclick popup without Javascript in CSS? Answer No, you can’t. You have to use script to wire an event handler for onlcick. and the user agent decides whether the page should be opened in a new window or tab. If you need a new popup window with custom size you have to use window.open and you can’t

What are the reasons to use the id attribute for CSS purposes? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 10 years ago.

Ellipsis in the middle of a text (Mac style)

I need to implement ellipsis (“…”) in the middle of a text within a resizable element. Here is what it might look like. So, becomes When the element is stretched out to the width of the text, I want the ellipsis to disappear. How can this be done? Answer In the HTML, put the full value in a custom data-*

How do you add CSS with Javascript?

How do you add CSS rules (eg strong { color: red }) by use of Javascript? Answer You can also do this using DOM Level 2 CSS interfaces (MDN): …on all but (naturally) IE8 and prior, which uses its own marginally-different wording: There is a theoretical advantage in this compared to the createElement-set-innerHTML method, in that you don’t have to

Advertisement