What is the orientation of the opening direction for the HTML details tag? Is it possible

I'm currently exploring options for reversing the direction of an open <details> tag in HTML, positioning the summary ABOVE instead of the default BELOW.

Is it achievable with CSS alone? Or would CSS combined with Javascript be needed?

Check out this straightforward JSFiddle:

Answer №1

If you want a set size, simply adjust the details element with position: relative. Specify its dimensions for both closed and open states, and fine-tune the positioning of its child elements using top and bottom:

details { height: 20px; position: relative; width: 100%;}
details[open] { height: 40px;}

details span {position: absolute; top: 0;background-color: red;}
summary {background-color:blue; position: absolute; bottom: 0;}

details[open] ::-webkit-details-marker
{
    transform: rotate(180deg);
}
<body>
    <p>Hello there!</p>
    <details>
                
        <span>Trying to display this element upwards</span>
<summary>Example</summary>
        </details>
</body>

Make sure to include the ::-webkit-details-marker rule to correctly adjust the arrow direction ;)

Answer №2

styles {background-color:white; color:white;}
styles[open] {background-color:red;}
summary {
    background-color:blue; 
    position: relative;
    top: calc(1em + 4px);
}
span {
    position: relative;
    top: calc(-1.2em + 4px);
}

view demo

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

What are the steps to create an SQL query using the PHP CodeIgniter framework?

Is there a way to convert this SQL statement to CodeIgniter framework PHP? SELECT COUNT(`id`) AS `c` FROM `products` WHERE `valid` = 1 AND `sticky` = 2 How can this be implemented in the model? Could it be done like this? $this->db->get('pro ...

Creating a personalized avatar display with Bootstrap 5

I'm trying to create a display that resembles a rounded avatar with text next to it. While I've successfully made the rounded avatar, an issue arises when I place text beside it where the avatar sometimes appears oval instead of round. What could ...

I seem to be missing something, as the client_id is required for Next Auth. What could it

I seem to be facing some confusion with where the communication breakdown is occurring. [...nextauth].js import NextAuth from "next-auth" import GoogleProvider from "next-auth/providers/google" export default NextAuth({ provider ...

Customizing Names in AngularJS Based on Selected Options in Dropdown Menu

I have encountered a slight problem that I am hoping someone can assist me with. It is quite simple if I only needed to take the ID, but unfortunately, I require another piece of information. I have labels for each of my drop-down lists and for one of them ...

Getting access to a JavaScript class from TypeScript and initializing it

I have integrated jsPDF by adding its jspdf.min.js file to my project. However, I am facing an issue when trying to use it within a TypeScript class. The error message states that jsPDF is unknown: btnPrintReportClick() { var pdf = new jsPDF(); ...

Highlight particular words within a string by assigning them specific colors

WordPress is my platform of choice. Initially, I crafted an HTML template and established a class for specific words within strings, which has proven to be successful. However, I am now contemplating whether it's feasible to apply this technique afte ...

Can someone explain the purpose of this line of code: `/[\/]electron-prebuilt[\]/.test

After cloning a repository for an Electron React Boilerplate on GitHub, I came across this code snippet in the main.js file: if ( process.defaultApp || /[\\/]electron-prebuilt[\\/]/.test(process.execPath) I understand that this is reg ...

What is the best way to align a <div> element below another without being on the same line?

I'm currently working on developing a snake game. My focus right now is figuring out how to make the body parts of the snake follow the head and be positioned after it. <!--Player--> <div class="snake"></div> So here we have the sn ...

Do React and Node require separate codebases and servers to function?

Here is a question that delves into the complexities of setting up a website with NodeJS and React. Many tutorials show creating two separate programs or servers, one on port 3000 and the other on 3001. But, is this really necessary? Considering that Reac ...

What is the best method for incorporating a data-* attribute to every option while configuring a select2 input field?

Currently, I am utilizing the select2 plugin to enable the selection of an image from a list to display on the screen. In order to achieve this functionality, I must assign a specific attribute to each option: s3_key. My requirement is to set this attribu ...

How can Selenium locate the Button element in a web page?

How can I locate and click this button in my Selenium Webdriver window? I usually use find_element_by_id, but what other methods can I try? <button role="button" data-testid="uc-accept-all-button" class="sc-gsDKAQ cYtWkK" s ...

Triggering successive jQuery confirm boxes once the previous one has finished processing

I am facing an issue with my API call response where I receive an array and need to open jQuery Confirm one by one for each item in the response. The problem is that they all open at once. Below is the code snippet: axios.post('/orders/ask-for-or ...

Transitioning towards elements in a newly opened tab using Selenium

When a selection is made from a dropdown using Selenium WebDriver, the resulting link opens in a new tab. Due to this behavior, I am encountering a null pointer exception while attempting to locate elements. How can I switch to the new tab in order to fin ...

Arrange ten objects in each of the four JavaScript arrays in ascending order based on a specific value

model with sample data -> [{ date: '13413413', name: 'asdfasdf', other: 'kjh' }] The getJSON function returns 4 arrays, each containing 10 model objects. array1 = 10 resultsObj sorted by date from newest to o ...

Display information from Node.js on an HTML page

I am working on a nodejs project where I need to login on one page and display the result on another page using expressjs. Below is my code for login.ejs: <!DOCTYPE html> <html lang="en" dir="ltr"> <body> <form method="PO ...

Steps for creating a TypeScript project for exporting purposes

Forgive me for my lack of experience in the js ecosystem. Transitioning from static languages to typescript has been a positive change, though I still find myself struggling to grasp the packaging/module system, especially when coupled with typescript defi ...

Analyzing an array of ObjectIds in relation to a single ObjectId

Recently, I encountered a scenario where code that used to work perfectly needed adjustments due to an issue. If anyone can provide insights into why this change occurred and now requires an additional check, it would be greatly appreciated. Here is my sit ...

Tips for individually collapsing dynamic accordion panels within a Vue.js v-for loop

Is there a way to collapse accordions individually that are created inside a Vue.js v-for loop? I believe assigning a dynamic id to each accordion will help with this, but I am not sure where to add this id. Below is my HTML code: <div role="tablist"& ...

Issues with Angular service functionality

I've been working on an application using Angular for the client side and Node for the server side. I've incorporated some API's into my Angular code, but I'm encountering difficulties with retrieving data from a specific API. Can someo ...

Navigation bar featuring various distinct webpages

Apologies for the novice question, but as a beginner, I'm seeking help. I've created a navigation bar with text such as About and Projects, but no links attached (i.e., no pages for users to navigate to). How can I add these missing pages so that ...