What is the best way to determine the size and placement of an item in relation to its container

Hello there! I am brand new to HTML and trying to figure out how to position and size an item relative to its container. I found this code snippet (https://codepen.io/Tectonics0x3F/pen/EfAgr) where changing the top and left percentages affects the box's position within the container, and adjusting height and width changes the size proportionally. However, when I try to replicate this in my own code, it doesn't seem to work properly. It looks like the boxes are not truly inside the container, but I'm not sure how to fix this issue. Just a note, I am trying to create a menu with these boxes within the container. Thank you for any help provided and apologies for any language barriers.

Here are snippets of my codes:

   body{
  background-image:url('../images/bg24.jpg');
  color: #fff;
  font-family: Arial, Helvetica, sans-serif;
  font-size:16px;
  line-height: 1.6em;
  margin:0;
  background-repeat:repeat; 
  margin: auto;
}


#container {
  height:70%;
  width:90%;
  margin:auto;
  top:25%;
  left:5%;
  border: 5px solid white;
  position:relative;
}



.button {
      background-color: #474B4F;  
      border: 2px solid Black;
      color: white;
      padding: 5% 5%;
      text-align: center;
      text-decoration: none;
      display: inline;
      font-size: 20px;
      cursor: pointer;
      border-radius: 5px; 
      box-sizing: border-box;
}

#button1{
  top: 0;
  left: 0;
  position:absolute;
}

#button2{
 margin-top:0;
 margin-left: 25%;
 position: absolute;
}
<body>
<div id="container">
<div id="button1">
<a href="Somepage.html" class="button">clickme1</a>
<div id="button2">
<a href="Somepage2.html" class="button">clickme2</a>
</div>
</div>
</body>

Answer №1

If you're looking for a straightforward method to create a menu, this is the solution for you. If you need more detailed guidance, feel free to ask.

.menu-item {
     background-color: #474B4F;  
     border: 2px solid Black;
     color: white;
     padding: 5% 5%;
     text-align: center;
     text-decoration: none;
     font-size: 20px;
     cursor: pointer;
     border-radius: 5px; 
     box-sizing: border-box;
}
#item1,#item2 {
margin:12px;/* Add spacing if desired */
display:inline-block;
}
<body>
    <div id="menu-container">
        <div id="item1">
        <a href="Page1.html" class="menu-item">Item 1</a>
        </div>
        <div id="item2">
        <a href="Page2.html" class="menu-item">Item 2</a>
        </div>
    </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

Issue with div:after transition not functioning in Safari

The transition effect on div:after does not function properly in Safari. Below is the code for reference: HTML: .bbtn { width: 151px; height: 48px; background: #ef2e41; margin: auto; margin-top: 32px; -webkit-transition: all 0.3s ease-in-ou ...

Align the inline text at the center as if it were an inline-block element

Currently working on a design that appears deceptively simple, yet I'm encountering challenges in centering it while keeping the text aligned to the left. https://i.sstatic.net/qhf6p.png In an attempt to have the background span only the actual text ...

What is the best way to prevent "escaping" in the createTextElement method when using Javascript?

Check out the Jsfiddle demo document.getElementById("container").appendChild(document.createTextNode('&#xe145; ')) <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet> <div id="container" class="ma ...

How can I display a drilldown label in HighCharts on a mobile device?

When viewing the chart on mobile devices, I notice that the drilldown data label for my pie chart is being truncated with ellipses. My goal is to adjust the styles so that the entire word "streaming" is displayed without any dots cutting off the bottom par ...

Exploring HTML5 using QXmlQuery

Looking to execute XQueries on a batch of HTML5 documents using QT (currently at 5.8...) HTML/HTML5 documents, unlike XHTML/XHTML5, are not well-formed XML files. HTML introduces elements that XML parsers cannot handle off the bat (such as special characte ...

The DIV Card has been displaced into a different row

https://i.sstatic.net/sdUB6.png I'm struggling to align my div card next to another card without it getting distorted. The first one looks fine, but I can't figure out how to position the next one beside it... $sql = "SELECT * FROM posts WHERE ...

Twist two images in opposite directions around the avatar picture using CSS

Upon hovering over the central image, I want two circles to animate in opposite directions simultaneously. So far, I have only been able to animate them separately by individually hovering over the objects. This is what I'm aiming for: Check out my ...

Is there a way to customize the alignment in a bootstrap table so that all content is left-aligned and the table utilizes only the required space

My goal is to create a table layout as shown below: [ header ] [ header 2 ] [ header 3 ] ----------------------------------------------------------------------100% cell here and longer and even longer ------------------------------------------- ...

The functionality of Bootstrap toggle ceases to operate properly following an AJAX content update

I am currently using AJAX load to fetch some content on my webpage. I am working with Bootstrap 3 and Bootstrap toggle. When the content is loaded, the Bootstrap 3 content functions properly (the panel-primary panel is clearly visible). However, the Bootst ...

"Embedding a Highcharts web chart within a pop-up modal window

I am looking to incorporate a Highcharts web chart onto a specific part of a Bootstrap modal, while ensuring the size remains dynamic along with the modal itself. Here's what I have attempted so far: Sample HTML code: <td><a href="#">${ ...

Responsive design is causing issues with the stacking of rows in Bootstrap

Currently in the process of creating a website using HTML5, CSS3, and Bootstrap technologies. Encountering difficulties while attempting to establish a stacked row-column layout. On desktop view, the design appears as desired, resembling this example: ht ...

Encountering the issue "Error: Uncaught PDOException - SQLSTATE[42000] - Syntax error or access violation: 1064"

I encountered an error that says: Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064. It seems to be a syntax error in my SQL statement. Can you help me figure out what's wrong with it? require_once "dbconnect.inc.php"; $e ...

CSS Sprites - Concealing the surplus section of the image

Greetings, I have implemented an Image Sprite to showcase a variety of Icons. XHTML <div class="ListIcons"> <ul> <li class="Icon i-scissors">A list item utilizing the <strong>i-scissors</strong> class.</li> ...

The image is not correctly aligned in the center within the anchor element

In the process of working on my Angular project, I have encountered an issue with displaying components as items. Here is a snippet of the component code: <a href="" class="list-group-item clearfix" > <div class="container-fluid"> <div class ...

Adjustable background image dimensions without covering it

I have a container set with height: 100vh; that includes a background image. I'm looking to make the background responsive so it fills the entire div. Using background-size: cover isn't producing the desired effect. Any suggestions on how I can a ...

Creating a stylish button using a combination of CSS and Javascript classes within a webpage layout

Is it feasible to include a button in the layout that has HTML, CSS styles, and JavaScript functionality? For instance: This button is designed with both CSS styling and JavaScript classes. How can one incorporate CSS and JavaScript along with HTML conte ...

Incorporating hyperlinks within the navigation buttons

I'm working on a design where I have six buttons that need to be displayed on top of a background image. How can I ensure that the text inside the buttons stays contained within them? Here is the current code structure I am using, which involves utili ...

Following the recent update to IntelliJ IDEA 2022.1.3, the use of ::ng-deep has been marked

After updating the version of IntelliJ, I noticed that the ::ng-deep angular material selector is now marked as deprecated. Here's an example: <mat-form-field class="register-custom-select"> <mat-select formControlName="gende ...

Generating unique identifiers and names for duplicated input fields in a form, which change dynamically

Innovative approach: When dealing with multiple replicated inputs, changing the id and name attributes can be a hassle. How can we ensure that each input remains unique, especially in a real project with several inputs like component_date and component_own ...

Issues with Jquery show and hide functionality within a list element

My menu items are displayed using show and hide functions, sliding up and down on hover. The issue I am facing is that when a list item expands, the overall background of the menu also expands. However, when it contracts, the background also contracts. If ...