Tips for resizing a flexible circle and a definite rectangle within a stationary holder

My parent container .secondary-nav-wrap has the following CSS:

.secondary-nav-wrap {
    margin: 30px 0;
    position: relative;
}

Within it, there is an ordered list (ol) with varying list items (li), and an absolutely positioned div .import-26-as with the following CSS code:

position: absolute;
top: 0;
right: 0;

Everything works fine when there are three list items:

https://i.sstatic.net/fk8fV.png

However, when the number of list items increases to 5 or 6 (max), the Import div overlaps with the list items as shown below:

https://i.sstatic.net/i29TH.png

I am aiming for a design where the yellow div automatically adjusts itself accordingly.

https://i.sstatic.net/3VDh9.png

I am okay if the yellow div overflows out of its parent div.

Edit:

The CSS code for the list item (li) is:

.primary-nav li, .secondary-nav li {
float: left;
text-align: center;
list-style: none;
max-width: 190px;
}

The CSS code for the ordered list (ol) is:

.primary-nav, .secondary-nav {
display: inline-block;
margin-right: auto!important;
margin-left: auto!important;
position: relative;
margin-top: 0;
margin-bottom: 0;
}

The CSS code for the yellow div is:

.import-26-as {
position: absolute;
top: 0;
right: 0%;
font-family: "Source Sans Pro",Helvetica,Arial;
font-size: 12px;
color: #4c4725;
height: 34px;
overflow: hidden;
-moz-transition: height 150ms ease-out;
-o-transition: height 150ms ease-out;
-webkit-transition: height 150ms ease-out;
transition: height 150ms ease-out;
}

The parent div is enclosed within a container div with the following CSS:

.container {
width: 950px;
margin: 0 auto;
}

Answer №1

Consider using quantity queries as another option. I have included CSS code for a minimum of 3 and a maximum of 6 items. To test it, try adding or removing secondary list items. Feel free to tweak the code as needed; it was created primarily for testing purposes.

CSS

.container {
    width: 950px;
    margin: 0 auto;
    font-family: arial;
    font-size: 12px;
}
.primary-nav-wrap ol{
    list-style: none;
    margin: 0 0 20px 0;
}
.primary-nav-wrap ol li {
    display: inline-block;
    padding: 19px;
    width: 111px;
    background-color: aliceblue;
    text-align: center;
}
.secondary-nav {
    margin: 0;
    width: 700px;
}
.secondary-nav li {
    float: left;
    text-align: center;
    list-style: none;
    width: 190px;
    background-color:#999999;
    padding: 20px;
    border-bottom: 10px solid #7A7EF1;
}
ol.secondary-nav li:nth-last-child(n+4), ol.secondary-nav li:nth-last-child(n+4) ~ li {
    max-width: 145px;
    padding-left: 15px;
    padding-right: 15px;
}
ol.secondary-nav li:nth-last-child(n+5), ol.secondary-nav li:nth-last-child(n+5) ~ li { 
    max-width: 120px;
    padding-left: 10px;
    padding-right: 10px;
}

ol.secondary-nav li:nth-last-child(n+6), ol.secondary-nav li:nth-last-child(n+6) ~ li { 
    max-width: 105px;
    padding-left: 5px;
    padding-right: 5px;
}
.import-26-as {
    width: 200px;
    background: yellow;
    float: right;
}
 .import-26-as a {
    font-family: "Source Sans Pro",Helvetica,Arial;
    font-size: 12px;
    color: #4c4725;
    height: 34px;
    display: block;
    text-align: center;
    padding-top: 10px;
}

HTML

<div class="container">
      <div class="primary-nav-wrap">
           <ol class="primary-nav">
               <li><span class="test">link 1</span></li>
               <li><span class="test">link 2</span></li>
               <li><span class="test">link 3</span></li>
               <li><span class="test">link 4</span></li>
               <li><span class="test">link 5</span></li>
               <li><span class="test">link 6</span></li>
           </ol>
       </div>
       <div class="secondary-nav-wrap">
           <ol class="secondary-nav">
               <li><span class="test">A. test test 1</span></li>
               <li><span class="test">B. test test 2</span></li>
               <li><span class="test">C. test test 3</span></li>
               <li><span class="test">D. test test 4</span></li>
               <li><span class="test">E. test test 5</span></li>
           </ol>
           <div class="import-26-as"><a href="">other link</a></div>
       </div>

    </div>

Answer №2

There are different options to consider.
1. You can utilize a table structure (or mimic it using the display property with values like table, table-cell, and inline-block).
2. Alternatively, you have the choice of setting the inner div to have display: inline-block and float: right.
In both cases, absolute positioning is not necessary.

UPDATE: Regarding the use of a table, check out this helpful resource on maximizing the width of an ol element: Here. The solution involves utilizing display: table-cell.

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

How can a full-screen background image be created in Next.js?

To achieve a full height display in both the html and body tags, how can we do this within a next.js component? Check out [1]: https://i.stack.imgur.com/K1r9l.png [2] Visit: https://www.w3schools.com/howto/howto_css_full_page.asp "mainImage.jsx" import ...

Align the responsive image in the center of a container

I am facing a challenge in centering an image wrapped by an anchor tag inside a div. I have tried using display flexbox and justify-content:center for the image, which works to some extent. However, the height of the image remains constant while the width ...

Restangular will maintain the Http Content-Type as it is

I encountered an issue while trying to send a file as part of my form. Despite changing the content type to "multipart/form-data", the console still indicates that it is using application/json;charset=utf-8. As a result, Node.js (with Sails.js framework) t ...

What is the best way to align the subsequent sub-elements to the right edge of the initial child element in a left alignment

Here is the HTML snippet I am working with: .entry{ border: 1px solid gray; } .list_number{ color: red; border: 1px dashed gray; margin-right: 5px; } .entry_body{ border: 1px solid green; } <div class="entry"> <span class=" ...

Setting the current date in the CalendarExtender control is a simple task that can

I have a simple requirement that I need help with. Can anyone provide instructions on how to set the current date in a CalendarExtender control? <cal:CalendarExtender ID="calDate" runat="server" SelectedDate="2008-01-01" TargetControlID="txtDate" CssC ...

Interactive form featuring text fields and dropdown menus

Is it possible to create a form with the ability to add new rows consisting of SELECT and INPUT elements? Although my current code allows for this, I am facing an issue where no variable from the SELECT element is posted when the form is submitted. This i ...

Steps for adjusting menu link color after being clicked

I am attempting to modify the background color of visited links. Below is my header code: echo ('<ul>'); echo('<li><a href="'.$FromPage.'">Back</a></li>'); echo('<li><a href="Tal ...

Guide to utilizing variables with Pattern.compile in Java for selenium RC

I am facing a challenge where I need to check if the date in a field corresponds to the current day. In Selenium IDE, this is easily achieved: <tr> <td>storeExpression</td> <td>javascript{var date = new Date ...

troubleshooting responsive design issues with Bootstrap and PHP

this is the issue I'm facing and what I require: Please provide assistance with fixing the code for my website project. What exactly is the problem and how can it be resolved? Thank you. <?php include 'init.php'; $stmt = $con->prepar ...

Guide on placing images in a grid using CSS

Exploring a new way to arrange images in grid style with a box underneath. Seeking advice on achieving this specific layout shown in an image. Current progress in positioning can be seen in this screenshot. Desired adjustments include aligning the far ri ...

Retrieve information from a Django model in mysql based on user input

I am trying to retrieve data from a Django model (stored in MySQL) based on user input. Essentially, I have an HTML search bar where users can enter a value, which should then fetch related data from the Django model and display it on another HTML page. ...

Transforming HTML features into PHP scripts. (multiplying two selected values)

I am currently working on converting these JavaScript functions into PHP in order to display the correct results. I need guidance on how to use PHP to multiply the values of the NumA and NumB select options, and then show the discount in the discount input ...

Tips on extracting JSON information in JavaScript when the key name is unspecified

I have a challenge in parsing JSON data where the property name is unknown. Below is a snippet of my code, and I need your help in figuring out how to retrieve all data with an unknown property. datas.data.videoGroup.past, then utilize a loop $.each(data ...

Displaying HTML code through Alert() is a convenient way to showcase snippets of

Can alert() or another pop-up be used to show actual HTML code? For instance, the following code snippet: var range = selection.getRangeAt(0); var newNode = document.createElement('span'); newNode.setAttribute("class", "selectedText"); range.sur ...

Tips for regularly retrieving information from a psql table

I have a scenario where I am retrieving data from a psql table and converting it into a JSON array to be used for displaying a time series chart using JavaScript. The data that is passed needs to be in the form of an array. Since the data in the table get ...

How can we create a touch and mouse-friendly horizontal scrolling navigation pattern?

I am trying to implement horizontal scrolling for video testimonials in a single row on a responsive website, but I am encountering an issue. The width of the container class is larger than col-12, which leaves space and causes horizontal scroll on the pag ...

The CSS3 Animation-fill-mode: An Essential Property

I am working on a cool effect where text slides into the window and remains in place after the animation is complete. Surprisingly, I have managed to get the animation to work on one part of the text, but for some reason, the second part is not cooperating ...

A curated list of Laravel form request validation resources

After researching, I couldn't find any information on how to validate collections in the documentation. In .NET Core, I can easily achieve this by creating a Model with data attributes that automatically bind to the front end model, displaying all err ...

Jquery allows for the toggling of multiple checkboxes

I have a group of check-boxes that I would like to toggle their content when checked. Currently, I am using jQuery to achieve this functionality, but I am searching for a way to optimize my code so that I do not need to write a separate function for each ...

Exploring the Possibilities of Wordpress Search with Multiple Dropdown Options

Is it possible to search across multiple categories? For example, I have 4 dropdown menus: 1. City 2. Area 3. Month 4. Products/Services When a user visits my site, they will see a static page with 4 dropdown lists and a "search" button. After the user ...