The art of expertly placing the arrow in <details> with CSS

I'm looking to adjust the placement of the arrow within details. I've experimented with using float:left, but when the line is too long, like in the example provided, the arrow shifts to the beginning of the line below when I resize the window. I want it to remain next to the very first letter on the first row.

Is there a way to achieve this?

For instance:

<details>
  <summary>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut 
  gravida iaculis arcu, et hendrerit arcu. Morbi rhoncus ex quam, quis. 
 </summary>
  Content goes here.
</details>
<style>
 summary::-webkit-details-marker {
 display: none
}
 summary:after {
 content: "+";
 color: #fff;
 float: left;
 }

 details[open] summary:after {
 content: "-";
 }
</style>

Answer №1

try using :before instead of :after

 summary::-webkit-details-marker {
 display: none
}
 summary:before {
 content: "+";
 color: red;
 float: left;
 margin-right: 10px;
 }

 details[open] summary:before {
 content: "-";
 }
<details>
  <summary>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut 
  gravida iaculis arcu, et hendrerit arcu. Morbi rhoncus ex quam, quis. 
 </summary>
  Content goes here.
</details>

Answer №2

To adjust the marker's position, utilize absolute positioning.

details {
  width: 25em;
  margin: auto;
}

summary {
  position: relative;
  padding-left: 1.5em;
}

summary::-webkit-details-marker {
  color: blue;
  position: absolute;
  left: -1em;
}
<details>
  <summary>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque at volutpat libero.</summary>
  Insert your content here.
</details>

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

Synchronize two slideshows in a cycle with timed delays between each cycle

Is there a way to add a sequential delay between slideshows in the synchronized slide show example from cycle2 API? For example, having each div.cycle-slideshow start at 5s intervals (5s, 10s, 15s, 20s...). The cycle would then repeat with the first div st ...

Is it feasible to exclusively apply Twitter Bootstraps .navbar-fix-to-top on mobile devices?

I am working on a website using Twitter Bootstrap 3 and I have implemented the following navbar: <div class="col-xs-12 col-md-10 col-md-offset-1"> <nav class="navbar navbar-inverse" role="navigation"> <div class="navbar-header"> ...

Activate the function for items that are overlapping

Here is a scenario I am working on: HTML <body> <div> <p>Text</p> </div> <body> JQuery $('div').click(function(){ $(this).find('p').fadeToggle('fast'); }); $('bo ...

jQuery interprets every PHP response as having a status of 0

I've been working on a way for javascript to verify the existence of a user in a MySQL database. My method involves using jQuery to send the user details to a PHP script that will then check the database. The data is successfully sent to the PHP scr ...

Designing HR components using Bootstrap and CSS

Trying to integrate Bootstrap into my portfolio website, but struggling with styling the hr elements. They keep coming out like this: https://i.sstatic.net/IApoi.png They also refuse to center align, always sticking to the left. No idea why this is happe ...

Issues arise with table-cell and table-row when implementing a navigation bar using the CSS table-layout property

Looking to create a dynamic navigation bar that adjusts to different screen sizes? On the left side, you want an undetermined number of links, while on the right side there should be a search button. The challenge is to ensure that all links have equal wi ...

Converting Latin numbers to Arabic using PHP

Looking for a way to convert English numbers to Arabic within specific elements in an HTML page using PHP? Here's my attempt at some code, but it ends up converting all numbers in the page. I only want to convert numbers between certain elements. Any ...

Tablist with interactive Bootstrap navigation on both the left and right sides

How can I create interactive navigation tabs with two tabs aligned to the left ("First" and "Second") and one tab aligned to the right ("More")? Currently, I can switch between "First" and "Second" without any issues. However, once I select "More," I can s ...

Whenever I select an item from one dropdown menu, it should automatically disappear from the other dropdown menu

I'm currently working on an HTML and PHP exercise that involves calculating distances between cities. My professor has requested the implementation of a select element in such a way that if "City A" is selected in one dropdown, it cannot be chosen aga ...

Unable to align text in the middle of the header

Seeking help with my design flaws, I have created a fiddle to showcase the issues that arise when attempting to make it responsive. The main problem is that the HEADING IN CENTER text is not aligned properly in the center. If I remove the position attribut ...

Issue with Relative Div Rendering Correctly in Firefox and IE

I have a picture nested in two divs and I wanted to overlay a piece of tape in the corner of the picture. I created a div for the tape image and positioned it at the bottom of the document with the following attributes: #tape { width: 100px; heig ...

Using auto margins does not properly align the image in the center of the page

I noticed that in this specific example, the image is not centered properly. Can someone explain why this might be happening? For context, I am using Google Chrome v10 on a Windows 7 machine, not Internet Explorer. <img src="/img/logo.png" style="mar ...

Accessing the parent element within a hover declaration without explicitly naming it

I am facing a challenge with three nested divs, where I want to change the color of the children when the parent is hovered. However, I prefer not to assign a specific class name to the parent element. The issue arises because the children have their own ...

Circular picture contained within a Bootstrap column on an irregularly-shaped image file

I am looking to create a circular effect for an image that is originally rectangular, resembling a typical profile picture. I have come across several sources on how to do this. The challenge arises in trying to achieve this effect within a bootstrap colu ...

What is the best way to update a canvas chart when the side menu is hidden?

I am facing an issue with the layout of my webpage, which includes a left side menu and a canvas chart. The left side menu occupies the first 155 pixels of the width, leaving the rest for the canvas chart set to a width of 100%. However, when I close the ...

Display the second dropdown after the user has made a selection in the first dropdown

Recently, I've been delving into the world of html/javascript and navigating through the process of implementing the code found in this specific link. While I can see the solution outlined in the link provided below, I'm struggling with how to i ...

What is the best way to incorporate CSS into this HTML document?

Content has been omitted. It is crucial to review documentation in advance in order to reduce repetitive inquiries. Check out the Webpack v2 documentation. ...

By utilizing the body element as the container instead of a div, the content shifts to the left by eight pixels

When the body is used as the wrapper instead of a div, the content shifts eight pixels to the left (on a 1920×1080 display) when it extends below the fold. The examples below illustrate this difference in code snippets. Please note that the variance is on ...

Enhancing list item appearance by replacing bullets with Font Awesome icons

I need to create a list similar to this example https://i.sstatic.net/w84xS.png Although I successfully replaced the bullet with a fontawesome icon, the result is not quite right as shown here https://i.sstatic.net/yqnbJ.png You may notice a difference ...