What methods can I use to prevent my HTML content from being obscured by the menu?

The top content on my page is being hidden by the menu. I attempted to fix this issue by inserting <br> at the beginning, but it isn't a permanent solution as users can still scroll upwards and hide the content once again. Is there a way to create a fixed zone that cannot be scrolled past?

/*Menu*/

div.mycontainer {
  width: 100%;
  font-size: 18px;
  margin: -2px;
  overflow: auto;
  position: fixed;
  background-color: black;
}

div.mycontainer div {
  width: fit-content;
  background-color: white;
  float: left;
  padding: 7px;
  padding-left: 2px;
  border-style: solid;
  border-color: #A0A0A0;
  border-width: 3px;
}

div.mycontainer a {
  color: black;
  text-decoration: none;
}

div.mycontainer div:hover {
  background-color: #34ed23;
}


/*Menu End*/


Welcome

Answer №1

Opt for the position: sticky; property instead of fixed positioning, and add in top:0; to maintain element integrity within the normal document flow.

* {
  margin: 0px;
}


/*Menu*/

div.mycontainer {
  width: 100%;
  font-size: 18px;
  overflow: auto;
  position: sticky;
  background-color: black;
  top: 0;
}

div.mycontainer div {
  width: fit-content;
  background-color: white;
  float: left;
  padding: 7px;
  padding-left: 2px;
  border-style: solid;
  border-color: #A0A0A0;
  border-width: 3px;
}

div.mycontainer a {
  color: black;
  text-decoration: none;
}

div.mycontainer div:hover {
  background-color: #34ed23;
}


/*End Menu*/
<body>
  <div class="mycontainer">
    <div>
      <a href="https://www.youtube.com">Link 1</a>
    </div>
    <div>
      <a href="https://www.google.com">Link 2</a>
    </div>
  </div>
  <br>
  <div>
    <h1>Welcome</h1>
    The standard Lorem Ipsum passage, used since the 1500s "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi
    ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
    Section 1.10.32 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC "Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi
    architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia
    dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid
    ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?"Section 1.10.32 of "de Finibus Bonorum et Malorum", written
    by Cicero in 45 BC "Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam
    voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam
    eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit
    qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?" Section 1.10.32 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC "Sed ut perspiciatis unde omnis iste natus
    error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit,
    sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam
    aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae
    consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?" 1914 translation by H. Rackham "But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account
    of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue
    pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can
    procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no
    annoying consequences, or one who avoids a pain that produces no resultant pleasure?" Section 1.10.33 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC "At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium
    voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et
    expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis
    aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores
    repellat." 1914 translation by H. Rackham "On the other hand, we denounce with righteous indignation and dislike men who are so beguiled and demoralized by the charms of pleasure of the moment, so blinded by desire, that they cannot foresee the pain
    and trouble that are bound to ensue; and equal blame belongs to those who fail in their duty through weakness of will, which is the same as saying through shrinking from toil and pain. These cases are perfectly simple and easy to distinguish. In a
    free hour, when our power of choice is untrammelled and when nothing prevents our being able to do what we like best, every pleasure is to be welcomed and every pain avoided. But in certain circumstances and owing to the claims of duty or the obligations
    of business it will frequently occur that pleasures have to be repudiated and annoyances accepted. The wise man therefore always holds in these matters to this principle of selection: he rejects pleasures to secure other greater pleasures, or else
    he endures pains to avoid worse pains."
  </div>
</body>

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

Issues arise when HTML components are not functioning correctly upon calling JSON

I'm encountering a challenging issue that's difficult to articulate. Here is a link to a JSFiddle that demonstrates the problem: https://jsfiddle.net/z8L392ug/ enter code here The problem stems from my utilization of a news API for F1 stories. W ...

Excessive greed in 2 column layout is causing left alignment issues

Check out the sample code here: http://jsfiddle.net/YUhgb/ HTML Markup <html> <body> <div class="left"></div> <div class="right"> <div class="container"> <div class="i ...

The challenge of styling React components

Starting a new project with React and Redux has presented me with the challenge of deciding on a styling method. As a newcomer to React, I want to choose a method that won't compromise performance, will offer all CSS3 features, and is easy to maintain ...

Github website logo not displaying properly

Struggling to display my favicon on my website created with Github. I've tried using the code <link rel="shortcut icon" type="image/x-icon" href="favicon.ico">, but it's not working. Can anyone provide me with the correct code? I am using B ...

Unable to transform dynamically loaded text area into CKEditor

Executing the get_content function upon a link click. function get_content(n) { var hr=new XMLHttpRequest(); var url="./updatecontent.php"; var vars="id="+n; hr.open("POST",url,true); hr.setRequestHeader("Content-type","application/x-w ...

Creating unique CSS styles through randomly generated values for both the left and top positions each time the page is refreshed or loaded

I have multiple draggable frames within my HTML, each with unique "left" and "top" values in the CSS. I am looking to randomize these values every time the page is refreshed or loaded, with a range of 10 to 1000 pixels. Here is an example of the CSS for o ...

At what point in the process does Angular/PrimeNG switch the CSS classes from 'p-' to 'ui-'?

So I've encountered quite a peculiar problem. I've managed to create a customized PrimeNG component that seems to be functioning properly, but there are a couple of issues at hand: Despite using ViewEncapsulation.None, just like with other Pri ...

Optimal techniques for leveraging CSS within Mui and Reactjs

Just starting out with mui, I'm currently working on styling CSS for mui components like so <Typography variant="h5" sx={{ fontWeight: "bold", color: "#1a759f", display: "flex", ...

Elevate the size of the hero section

Is there a way to increase the height of my jumbotron without adding it in the class attribute, as it would affect responsiveness? I want it to look like this, but currently, it appears as this. Below is my code: Html: <div class="container"> ...

What is the most efficient method for integrating PHP script into HTML code?

When it comes to inserting the full path to every image/css file on my website due to url rewriting, I am searching for the most efficient method. I could simply use: <img src='<?php echo $full_path; ?>/images/theImg.jpg' alt='alt ...

Color-matching cells must be positioned in the same column within the gridbox consecutively

In my current project, I am dealing with a large number of sections. Each section contains one or two rows with columns ranging from 2 to 15, all of equal width. The cells of the same color are placed in the same column, and the layout looks like this: ht ...

What is the best way to incorporate right side padding into a horizontal scroll?

I'm attempting to include padding on the right side of a horizontal scroll so that the last item in the scroll appears in the center of the screen. Here's what I have tried so far. While the left padding works perfectly, I'm puzzled as to w ...

initiate changes to the application's style from a component nested within the app

I'm looking to update the background color of the entire page, including the app-nav-bar, when I'm inside a child component. When I navigate away from that component, I want the default style to be restored. Any suggestions on how to achieve this ...

How can CSS be effectively handled across master pages, content pages, and user controls?

When working on a web project that includes content pages, master pages, and user controls, what are the best practices for writing CSS for each of these elements? Should it be included in the page itself, or in a separate file? Is it better to have a sepa ...

Steps for aligning an image and text within an icon next to each other

I'm looking to align a small PNG image next to some text within an icon. How can I achieve this? Currently, they are stacked vertically. Here is the current layout - I want the two elements side by side instead. The structure of the division is unique ...

Is it possible to create a hidden scrollbar that functions seamlessly on a wide range of web browsers?

I'm currently working on a bootstrap website that features two columns that stretch to the height of the viewport, with any overflow being managed by scrollbars. This allows for the columns to be scrollable without affecting the overall page height. ...

Showing information from page's table using find_element_by_xpath (Selenium with Python)

I am currently exploring the implementation of the find_element_by_xpath() method to locate table elements on a webpage and present them in either a display or print format. Below is an excerpt from the page content: <tbody id="listContainer_databody" ...

Converting Temperature between Celsius and Fahrenheit using a Dropdown Menu

I am trying to create a conversion tool using a Select menu. The idea is that the first input box will display the temperature unit selected in the menu, but for some reason it's not working as expected. If I choose Celsius from the menu, then the inp ...

Content enclosed in a div tag and displayed within the same

I need assistance in converting a PSD file into two cards. The content within the card should resemble this. Can anyone provide guidance on how to achieve this? Below is the code I am currently working with: .container { margin-top: 10px; } .ca ...

Is it possible to enhance the appearance of the select2 options in any way?

I am currently using a select2 plugin to handle select boxes, where the options are generated by concatenating two values together. However, I am looking for a way to style one of the values in the select2 box with a different color. Are there any options ...