Aligning/spacing the items in a list vertically

Is it possible to add vertical spacing between specific <li> tags in a navigation list using CSS only, without relying on JavaScript or JQuery?

For example: http://jsfiddle.net/ssqnY/

The spacing should adjust responsively based on the height of the containing div or window.

Here is the structure of the navigation list:

<ul>
    <li><a href="#">Link</a></li>
    <li class="spacer"></li>
    <li><a href="#">Link</a></li>
    <li><a href="#">Link</a></li>
    <li class="spacer"></li>
    <li><a href="#">Link</a></li>
    <li><a href="#">Link</a></li>
</ul>

Answer №1

Take a look at this: http://jsfiddle.net/ssqnY/1/

li.spacer {
  margin: 0 0 30% 0;
}

It also functions well for responsive design.

Answer №2

To add vertical spacing to specific li elements using CSS, follow these steps: Assign your desired li with a class named spacer and then:

li.spacer {
  margin: 15% 0;
}

You can also add space to the first li:

li:first {
  margin: 15% 0;
}

Alternatively, you can give space to all li elements:

li {
  margin: 15% 0;
}

Note: The value of 15% is just an example; you can adjust it according to your preference, such as using a percentage or pixel value for responsiveness like 10px.

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

Is there a way to pause Javascript execution until all images are fully pre

Currently, I am using JavaScript to preload a series of images with the following code snippet: // Iterate through each image path and preload it (new Image()).src = this; Although this method works well and I can observe each image download being trigge ...

The disparity in responseText and statusText in AJAX can vary across various servers

In my ASP.NET MVC project, I have an action that returns the following: public ActionResult MyAction() { return new HttpStatusCodeResult(HttpStatusCode.NotFound, "custom err msg"); } This response is sent to an ajax function and caught by the fail ...

Adjust the size of an SVG to perfectly fit within a designated div

I've looked through several discussions here, but none of the suggested solutions seem to work for my specific situation. My issue involves an SVG that was created on a different website. It contains three elements, and I'd like to embed it whil ...

What is the best way to implement a date range filter in AngularJS for a specific year or month?

I am just starting to learn AngularJS. I have a date formatted as follows: d MMM y. However, I have two fields - one called "from" and the other "to" - that should act as filters for the date range, based on a year range or month range. Here is how I am or ...

How to flexibly show one item on the top line and two items on the bottom line using CSS

I've been trying to solve a simple problem with my flex container layout. I want to display 3 items in 2 rows - one item in the first row and the other 2 in the second row. However, no matter what I try, the items all end up on a single line due to th ...

The content inside a Textbox cannot be clicked on. I am seeking help with implementing JavaScript to enable it to be

As a newcomer in the world of programming, I am sharing a snippet of my JavaScript and HTML code with you. I am facing an issue where I want to enable users to start typing in a text box upon clicking on the text "User Name", without deleting any existing ...

Unraveling a Java String with HTML elements into a JsonObject: Step-by-step Guide

Hey there, I have a Java String that was received from an HTTP request and it looks like this: {SubRefNumber:"3243 ",QBType:"-----",Question:"<p><img title="format.jpg" src="data:image/jpeg;base64,/9j/4AAQSkZJRgAB..."></img></p>"} ...

How to maintain the side padding of a table within a Bootstrap 4 card?

JSFiddle: Click Here In my design, I have a table within a card element. However, when the window size is reduced to mimic a mobile device, the left padding remains intact while the right padding disappears. How can I ensure that the right side padding is ...

Actions for jQuery's mouseenter and mouseleave events

I've implemented a jQuery script that controls the visibility of elements based on mouse events: $("#divid").mouseenter(function() { $('#divid').show(1000); }).mouseleave(function() { $('#divid').hide(1000); }); $("#hldiv" ...

Create a social chat platform similar to Facebook by implementing a chat box feature with the help of AJAX, jQuery

Currently, I have developed a chat box with two persistent issues. Despite my attempts to rectify them, I am unable to find a solution. Below, I will outline my code, focusing on the HTML section where the chat box, chat text area, and chat members are dis ...

Changing the color of text in an HTML input field using CSS and JavaScript depending on the input value

Looking for a solution! // Getting user input values var input1 = parseInt(document.getElementById("input1").value); var input2 = parseInt(document.getElementById("input2").value); var input3 = parseFloat(document.getElementById(" ...

Utilize jQuery to trigger video playback based on the horizontal movement of the mouse

Utilizing this jQuery script to navigate back and forth in a video as the cursor moves along the x-axis. var mouseX; $(document).mousemove( function moveFunc(e) { mouseX = e.clientX; var timV = $("#deko_vid").get(0).duration; var valV = (timV*mouseX/$(do ...

Utilizing jQuery DataTable with an AJAX call to retrieve data from a JSON

I am facing an issue while trying to retrieve data from Entity Framework in ASP.NET MVC using a jQuery data table with AJAX. The data is not displaying in the table as expected. I need assistance in identifying the mistake in my approach. Upon executing t ...

How can I use Moment.js to show a custom message based on the current day of the week?

Currently, I am utilizing Moment.js to dynamically showcase various messages based on the day of the week. For instance, if it's: If it's Monday, I want it to display "It's Monday!" If it's Tuesday, I'd like it to show "Happy Tu ...

Bootstrap 4 Tooltip Continues to Show, Appears Unsightly

Can you please execute the following HTML test case in order to help identify a solution for making a Bootstrap 4 tooltip disappear when a button is disabled while the tooltip is hovering over the button? The specific issues I am facing are outlined within ...

Clearing Results Section Using JQuery and Ajax: A Guide to Implementing a Reset Button

Currently, I am diving into the world of Jquery and got stuck on a particular issue. The example I found online consists of a JSP form (a simple addition calculator) and a Servlet that adds two numbers together and displays the result upon clicking the "Ca ...

Is it possible to capture every ajax request?

My goal is to intercept all AJAX calls and check for specific error codes (ACCESS_DENIED, SYSTEM_ERROR, NOT_FOUND) in the response JSON sent from my PHP script. One approach I've seen is: $('.log').ajaxSuccess(function(e, xhr, settings) { ...

Is there a way to dynamically count the length of an element or class in realtime using JavaScript?

If there are currently 5 divs with the class name "item" and a new unknown number of divs with the same class name "item" are dynamically added in real time, I want my result to display the total number of divs present at that moment (i.e., 5 + n). Note: ...

"HTML Parsing with Simple DOM: Dealing with Class Names Containing Spaces

I am currently utilizing PHP Simple HTML DOM to extract elements from the source code of a website (which is not my own). However, when attempting to locate a ul class named "board List", it is not being found. It seems like there may be an issue with spac ...

Refresh the mouse's vertical position every 100 milliseconds

I'm facing an issue with saving the mouse Y coordinates to the variable startPosition every 100ms while the .mousemove event is active. When the mouse button is held (mousedown), my current code doesn't seem to be functioning correctly. Could som ...