Ways to align elements vertically in a container without using flexbox?

I am working with a ul element that has a height of 270px and contains 10 li elements. My goal is to have all the li elements vertically justified, meaning the top and bottom li elements should touch the container's top and bottom respectively, while the rest adjust their spacing accordingly. The display type of the elements is not an issue as they can be inline, inline-block, or block level. Here is the current code snippet:

* { margin: 0; padding: 0; }
ul {
  height: 270px;
  width: 250px;
  color: #afafaf;
  border: 1px dotted red;
}
li {
  width: 240px;
}
<ul>
  <li>- Web/UI Design</li>
  <li>- Web Development</li>
  <li>- CMS Integerations(WP, Joomla)</li>
  <li>- Logo & Banner Design</li>
  <li>- PSD to XHTML, CSS 3.0, HTML5</li>
  <li>- PHP & MySQL</li>
  <li>- jQuery, Ajax, Flash(ActionScript)</li>
  <li>- Landing Page Design & SEO</li>
  <li>- SEO(Search Engine Optimization)</li>
  <li>- E-Commerce & Shopping Cart</li>

</ul>

I have explored various resources on how to vertically align elements, but my specific requirement is to have them justified. While I understand this can be achieved using display: flexbox, I need a solution that also caters to older browsers lacking support for flexbox.

Answer №1

Here is a solution to your request:

* { margin: 0; padding: 0; }
ul {
  height: 270px;
  width: 250px;
  color: #afafaf;
  border: 1px dotted red;
  display: table;
}
li {
  width: 240px;
  display: table-row;
}
<ul>
  <li>- Web/UI Design</li>
  <li>- Web Development</li>
  <li>- CMS Integerations(WP, Joomla)</li>
  <li>- Logo & Banner Design</li>
  <li>- PSD to XHTML, CSS 3.0, HTML5</li>
  <li>- PHP & MySQL</li>
  <li>- jQuery, Ajax, Flash(ActionScript)</li>
  <li>- Landing Page Design & SEO</li>
  <li>- SEO(Search Engine Optimization)</li>
  <li>- E-Commerce & Shopping Cart</li>

</ul>

Answer №2

To easily adjust the line height of your list items, simply add "line-height: 1.7;" to your CSS for the li elements.

* { margin: 0; padding: 0; }
ul {
  height: 270px;
  width: 250px;
  color: #afafaf;
  border: 1px dotted red;
}
li {
  width: 240px;
    line-height: 1.7;
}
<ul>
  <li>- Web/UI Design</li>
  <li>- Web Development</li>
  <li>- CMS Integerations(WP, Joomla)</li>
  <li>- Logo & Banner Design</li>
  <li>- PSD to XHTML, CSS 3.0, HTML5</li>
  <li>- PHP & MySQL</li>
  <li>- jQuery, Ajax, Flash(ActionScript)</li>
  <li>- Landing Page Design & SEO</li>
  <li>- SEO(Search Engine Optimization)</li>
  <li>- E-Commerce & Shopping Cart</li>

</ul>

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 is the best way to scale down my entire webpage to 65%?

Everything looks great on my 1920x1080 monitor, but when I switch to a 1024x768 monitor, the content on my webpage becomes too large. I've been manually resizing with CTRL+Scroll to reduce it to 65%, which works fine. Is there a code solution using CS ...

Seamlessly transition between various states within a React component for a fluid user experience

I'm currently working on a simple component structured like this: var component = React.createClass({ render: function(){ if (this.props.isCollapsed){ return this.renderCollapsed(); } return this.renderActive() }, ren ...

Conceal/reveal div with initial partial visibility

http://jsfiddle.net/7RDBk/1/ At the moment, I am using slideUp and slideDown functions to hide and display a div. My goal is to have 25px of the div showing initially before expanding and going back to 25px when clicked. It seems like a simple task, but I ...

My Tailwind CSS toggle button disappears in dark mode, why is that happening?

<button aria-label="Toggle Dark Mode" type="button" className="lg:inline-flex lg:w-40 md:w-screen p-3 h-12 w-12 order-2 md:order-3" onClick={() => setTheme(theme === 'dark' ? &ap ...

"Exploring the best locations for storing CSS, JS, and image files in Spring

Having trouble figuring out where to place my public files. I attempted the solution mentioned in this thread on Stack Overflow but it didn't work for me. I've tried putting my public folder in various locations within the WEB-INF directory, but ...

What steps can be taken to enlarge the select button within a <select> field?

Is there a way to enlarge the size of the downward-pointing arrow button within a <select> element? Here is an example of what my code looks like: <select> <option>Select City</option> <option>City1</option> <o ...

How do I incorporate left, right, and top labels with Material-ui Toggle switches?

My goal is to create a unique toggle switch design with labels positioned on each side as well as on top. For example, I am working on a left/right switch. The desired output should resemble this:          Side Left [Toggle] Right Below is ...

Iterating through a variety of selectors on a webpage to consolidate and save into a single large data frame

I need help with a project and got a quick response last time, so here I am again. The code below is scraping data from a website and adding a column to indicate which instance of the table it is extracting. My current challenge is loading all Game Recency ...

Prevent event propagation in jQuery by using .stopPropagation() when hovering over a

When trying to implement event.stopPropagation() in a specific scenario, I encountered an issue with a blinking background image on my submenu. To address this, I added a pseudo-element (background:green) to the parent element by toggling a new class using ...

What is the best way to delete previously entered characters in the "confirm password" field after editing the password

Is there a way to automatically remove characters in the confirm password field if characters are removed from the password field? Currently, when characters are entered into the password field, characters can also be entered into the confirm password fiel ...

What is the best way to enclose text within a border on a button?

I am trying to create a button with a colored border around its text. Here is the code for my button: <input id="btnexit" class="exitbutton" type="button" value="Exit" name="btnExit"></input> Although I have already added CSS styles for the ...

Adjusting the width of titles in a CSS menu upon hover

I am currently creating a basic CSS menu. However, I am facing an issue where selecting a menu title in the menu bar causes the width of the title to extend to match the width of the associated menu, which is not my desired outcome (the title's width ...

Guide on transferring three js variable to an HTML label element

For my project, I am looking to pass three js values to the label of a div. The desired output is: stWay: stProposer: stTime: hello John 2017-09-07 I have successfully programmed a button to make div1 a ...

Achieve the effect of bringing the div and its contents to the top when hovered over, all while keeping

I have designed a popup that includes multiple boxes. I want the width of the box to expand and be visible over all content on the webpage when a user hovers over any ".deviceboxes". I tried using ".deviceboxes:hover" which worked fine for the first box in ...

Can a link be stored in a table using PHP?

I need assistance in organizing a page with a sidebar containing about 20 links as the code appears messy. Is there a way to store all <a href=.... in a table, an array, or another method for better organization? If anyone could provide an example, it ...

Reposition HTML content using regular expressions

My objective is to locate a block of HTML that contains comments and relocate it after the header section. The comment itself remains constant, but the content within the block varies across different pages and needs to be replaced using Dreamweaver' ...

Numerous covert fields within HTML

I am currently working on a popup dialog box where I need to include a set of values in hidden format. However, when I retrieve the value through AJAX post, only the last value is returned. In my PHP code snippet: $plan_ids=array(); foreach($test_plan as ...

What is the best way to add a right-hand side navigation bar without blocking the scrollbar from view?

Take a look at this webpage: I am designing a website that includes a header, a footer, and a central container with left and right navigation bars surrounding a content area. However, I want the scrollbar for the content to appear on the right side of th ...

The response contains a JSON object with the values [object, Object]

I am attempting to showcase JSON data in an HTML table. Here is the code I have been using: <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script> $(document).ready(function(){ ...

What is the best approach in Ruby for managing an unordered list with split columns and counting each

I am currently in the process of strategizing the layout for a webpage utilizing Bootstrap 4 within Ruby on Rails. Specifically, I need to create a sidebar submenu that can expand and collapse, feature bullet points, and include a counter. The desired out ...