Align the bottom borders to the lowest content on each line

I am working on designing my homepage using HTML, CSS, JSP, and JavaScript, focusing on the sale of musical instruments and facilitating communication among users.

Right now, I am in the process of creating a site-map for my menu configuration chart using div, ul, li, and h tags. My goal is to add bottom borders under the last submenu items (last li tags) as shown in the image below (refer to the blue markings). These borders should align with the lowermost li tag.

https://i.sstatic.net/XEpdN.jpg

Here is what I have developed so far:

#sitemap_menu_container {
  width: 980px;
  height: 200px;
  border: 1px solid violet;
}


.sitemap_menu {
  width: 150px;
  height: 180px;
  float: left;
  margin-left: 5px;
  margin-right: 5px;
  margin-bottom: 5px;
  border-bottom: 1px solid #cbcbcb;
}

.sitemap_menu_header1 {
  font-size: 15pt;
  font-family: Arial;
  padding-bottom: 7px;
  border-bottom: 1px solid #cbcbcb;
}

.sitemap_menu_header2 {
  font-size: 15pt;
  font-family: Arial;
  color: red;
  padding-bottom: 7px;
  border-bottom: 1px solid #cbcbcb;
}

.sitemap_menu ul li {
  list-style: none;
  font-size: 11pt;
  font-family: Arial;
  background: url(../images/bullet1.png) no-repeat 0px 50%;
  padding-left: 10px;
  margin-left: 10px;
  cursor: pointer;
}
<div id="sitemap_menu_container">
  <div class="sitemap_menu">
    <h2 class="sitemap_menu_header1">About</h2>
    <ul>
      <li>P&G introduce</li>
      <li>P&G history</li>
      <li>location</li>
    </ul>
  </div>
  <div class="sitemap_menu">
    <h2 class="sitemap_menu_header2">Piano goods</h2>
    <ul>
      <li>All kind of piano</li>
      <li>Upright</li>
      <li>Grand</li>
      <li>Electronics</li>
      <li>Synthesizer</li>
      <li>Management Tools</li>
    </ul>
  </div>
  <div class="sitemap_menu">
    <h2 class="sitemap_menu_header1">Guitar goods</h2>
    <ul>
      <li>Acoustic</li>
      <li>Classic</li>
      <li>Electrics</li>
      <li>Ukulele</li>
      <li>Management Tools</li>
    </ul>
  </div>
  <div class="sitemap_menu">
    <h2 class="sitemap_menu_header2">Community</h2>
    <ul>
      <li>Free Board</li>
      <li>Reviews</li>
      <li>Gallery Board</li>
    </ul>
  </div>
  <div class="sitemap_menu">
    <h2 class="sitemap_menu_header1">Event</h2>
    <ul>
      <li>Ongoing Event</li>
      <li>Announcement</li>
    </ul>
  </div>
  <div class="sitemap_menu">
    <h2 class="sitemap_menu_header2">Help you</h2>
    <ul>
      <li>Guide</li>
      <li>Notice</li>
      <li>FAQ</li>
      <li>Q&A</li>
      <li>Sitemap</li>
    </ul>
  </div>
</div>

Answer №1

To increase flexibility, consider utilizing flexbox. Remove height constraints in #sitemap_menu_container and .sitemap-menu, while adding display: flex to #sitemap_menu_container. Here's the code snippet for reference:

#sitemap_menu_container {
  width: 980px;
  border: 1px solid violet;
  display: flex;
}

.sitemap_menu {
  width: 150px;
  float: left;
  margin-left: 5px;
  margin-right: 5px;
  margin-bottom: 5px;
  border-bottom: 1px solid #cbcbcb;
}
/* Additional CSS rules have been omitted for brevity */

It's important to note that this solution is optimized for modern browsers supporting flexbox, as listed on Can I use - Flexbox. For older browser compatibility, a table layout may be necessary.

I hope this information proves helpful!

Answer №2

To apply a bottom border to the final <li> in your sub-menu, simply insert the following CSS:

.sitemap_menu ul li:last-child{border-bottom:1px solid #000;}

Answer №3

You may opt for using <hr> instead, just make sure to adjust the height of the columns accordingly

#sitemap_menu_container {
  width: 980px;
  height: 200px;
  border: 1px solid violet;
}

.sitemap_menu {
  width: 150px;
  height: 180px;
  float: left;
  margin-left: 5px;
  margin-right: 5px;
  margin-bottom: 5px;
}

.sitemap_menu_header1 {
  font-size: 15pt;
  font-family: Arial;
  padding-bottom: 7px;
  border-bottom: 1px solid #cbcbcb;
}

.sitemap_menu_header2 {
  font-size: 15pt;
  font-family: Arial;
  color: red;
  padding-bottom: 7px;
  border-bottom: 1px solid #cbcbcb;
}

.sitemap_menu ul li {
  list-style: none;
  font-size: 11pt;
  font-family: Arial;
  background: url(../images/bullet1.png)no-repeat 0px 50%;
  padding-left: 10px;
  margin-left: 10px;
  cursor: pointer;
}
<div id="sitemap_menu_container">
  <div class="sitemap_menu">
    <h2 class="sitemap_menu_header1">About</h2>
    <ul>
      <li>P&G introduce</li>
      <li>P&G history</li>
      <li>location</li>
    </ul>
    <hr>
  </div>
  <div class="sitemap_menu">
    <h2 class="sitemap_menu_header2">Piano goods</h2>
    <ul>
      <li>All kind of piano</li>
      <li>Upright</li>
      <li>Grand</li>
      <li>Electronics</li>
      <li>Synthesizer</li>
      <li>Management Tools</li>
    </ul>
    <hr>
  </div>
  <div class="sitemap_menu">
    <h2 class="sitemap_menu_header1">Guitar goods</h2>
    <ul>
      <li>Acoustic</li>
      <li>Classic</li>
      <li>Electrics</li>
      <li>Ukulele</li>
      <li>Management Tools</li>
    </ul>
    <hr>
  </div>
  <div class="sitemap_menu">
    <h2 class="sitemap_menu_header2">Community</h2>
    <ul>
      <li>Free Board</li>
      <li>Reviews</li>
      <li>Gallery Board</li>
    </ul>
    <hr>
  </div>
  <div class="sitemap_menu">
    <h2 class="sitemap_menu_header1">Event</h2>
    <ul>
      <li>Ongoing Event</li>
      <li>Announcement</li>
    </ul>
    <hr>
  </div>
  <div class="sitemap_menu">
    <h2 class="sitemap_menu_header2">Help you</h2>
    <ul>
      <li>Guide</li>
      <li>Notice</li>
      <li>FAQ</li>
      <li>Q&A</li>
      <li>Sitemap</li>
    </ul>
    <hr>
  </div>
</div>

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

"Troubleshooting cross-domain issues with iframes in Internet Explorer

My application is built with angularjs and we offer the option to embed it on other websites. Everything works well in IE11, but when the application is iframed onto a different domain's website, it stops working. I've tried adding <meta htt ...

Trouble arises when attempting to append a class through ng-class upon clicking

In a specific scenario, I am trying to change the border color from black to red in a div by appending a class using ng-class when clicked. However, when clicking a button, the modal opens but the class is not being appended as expected. <div ng-class ...

Upon page load, a dazzling SVG file will flicker before being adorned with CSS styles

I'm experiencing an issue with an SVG arrow icon on my webpage that flashes quickly across the entire screen upon page load before settling into its proper size and placement. I've tried using CSS to initially hide the icon and then reveal it aft ...

Improving Consistency: Achieving a Uniform a:hover Effect for Links Listed in Lists

One issue I'm having is with creating a list of links and styling them with a:hover. The problem arises when the list has a defined width wider than the links themselves, causing the LIs to change color before the As on hover. It creates a messy appea ...

"What is the best approach to adjusting the width of one div based on the width of another div using CSS Grid

As a beginner in programming, I'm trying to work with CSS Grid but facing some challenges. My goal is to create a component with two columns: the left column should have a width of minmax(570px, 720px), and the right column should be minmax(380px, 10 ...

Disabling the @import cache feature in LessCSS Assetic

I'm facing a minor issue that is robbing me of precious time. Currently, I am using the assetic plugin with the lesscss filter in my symfony2.1 project. The problem lies in Assetic not detecting changes in imported files when using the @import functi ...

Guide on incorporating the WHERE clause into an insert statement in PHP version 5.1.6

What is the correct way to incorporate a where clause into an insert statement in PHP 5.1.6? In my code, I have declared a global variable $module and I am trying to use a where clause to refine my search results. Specifically, I want to include where mod ...

Arrange an item independently of surrounding elements

Is it possible to position an element across two columns, starting in the middle of the second column? The columns are defined by divs. Could this be achieved through z-index positioning? ...

How can you modify the color of a <canvas> element using CSS?

Can the HTML5 element's color be modified using CSS as opposed to JS? I am looking to personalize qTips tooltip pointers with specific LESS CSS instructions that cannot be referenced through jQuery. ...

Tips on creating a button that, upon clicking, triggers the download of an Excel file using PHPSpreadsheet

I am trying to figure out how to create a button that, when clicked, will download an Excel file named b1b5.xls with some specified values added. Here is the code I have so far: <html> <head> </head> <body> <center> < ...

Adjusting the tab size and space size to their default settings within VSCode

I'm currently facing an issue with my VSCode setup. I am trying to configure the space size to be equal to 1 and tab size to be equal to 2 as the default for every project. However, despite my efforts, it keeps reverting back to spaces: 4 for each new ...

Ensure that the URL is updated correctly as the client navigates between pages within a Single Page Application

Seeking a solution for maintaining the URL in a Single Page application as the client navigates between pages, with the URL changing in the background. I attempted using @routeProvider but it doesn't seem to be suitable for my situation. Any suggestio ...

No matter what I try, connecting the CSS file to my HTML file just won't seem to work

I've been attempting to connect a CSS file to my HTML index file, but I can't seem to get it to work no matter what I try. I'm using VSCode. When typing the link from scratch, it auto-completes or shows up, indicating that it recognizes it. ...

Glitch Uncovered in Excel Spreadsheet I Exported

I have a situation where I am working with an HTML table that includes both text and radio buttons. The issue arises when I attempt to export the table data along with the selected radio button values to Excel using the 'Export to Excel' button. ...

Tips for making a screen adapt to different monitor resolutions

Hello there! I've been working on a login screen using bootstrap 4, but I'm facing an issue with the layout. My concern is about adjusting the page layout so that the background image does not get cut off or distorted. Take a look at the image ...

Additional <li> elements are created in Internet Explorer versions 8 and 9

Currently in the process of setting up a new website/landing page. Upon heading to the right column at the bottom (where the pictures are located), you will notice <li> elements containing pictures within containers. The only issue that arises is whe ...

Pop-up - maintain the initial value

I'm working on a modal using Bootstrap and React. Inside the modal, there's a dropdown with an initial empty option: <select class="form-control" onChange={this.handleSelectCat}> <option disabled selected></option> < ...

Showcasing a dynamically created JSON document on a basic web page

Looking for a solution to display the contents of a result.json file generated by my Java tool on a simple website. I am aware that accessing local files directly with JavaScript is not possible, so seeking alternative methods that do not involve using a w ...

The sequence of HTML attributes

Could there be a subjective angle to this question (or maybe not)... I work on crafting web designs and applications using Visual Studio and typically Bootstrap. When I drag and drop a CSS file into an HTML document, the code generated by Visual Studio loo ...

What is the best way to modify and execute js and css (less) files dynamically using ajax and jQuery?

Whenever I click a button, an ajax call is triggered to load various html code into a div with the id 'main'. While displaying the html content is not an issue, integrating and applying css and js code to my current page has proven to be challeng ...