When positioning your diamonds using position: absolute
, they will be positioned relative to the body
element by default. However, if you want them to be positioned relative to a specific div
, you can wrap the diamonds in a div
and style that container using position: relative
. This way, the positioning of the diamonds will be based on the container div
. Make sure to also add a margin-top
to the container div
if you are using transform: translate
to push the diamonds up.
Below is an example that demonstrates the CSS styling for the container div
and the diamonds:
/* CSS styling for positioning diamonds */
* {
margin: 0;
padding: 0;
background-color: #000;
font-family: poppins, sans-serif;
}
.ul-container {
position: relative;
margin-top: 300px;
}
/* Main navigation styling */
.main-nav {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
margin: 0;
padding: 0;
width: 600px;
height: 150px;
}
/* Individual diamond styling */
.main-nav li {
list-style: none;
position: absolute;
width: 200px;
height: 200px;
transform: rotate(45deg);
transition: 0.5s;
margin: -100px;
overflow: hidden;
opacity: 0.6;
border-color: rgb(236, 39, 236);
border: solid rgb(236, 39, 236)
}
/* Styling for hover effect on diamonds */
.main-nav li:hover {
opacity: 1;
cursor: pointer;
}
/* More styling for individual diamond items */
.main-nav li.item1 {
/* Specific styling for first diamond */
}
/* Repeat the above styling for other diamond items */
/* Additional CSS styling continues... */
<div class="ul-container">
<ul class="main-nav">
<li class="item1">
<div class="bg">
<div class="title">
First
</div>
</div>
</li>
<!-- Add more diamond items as needed -->
</ul>
</div>