Reputation: 637
I have a Bootstrap dropdown button that I would like positioned on the right hand side of the page.
The dropdown is to be of 100% of the page's width, and should cover any content on the page when it is activated. However, I have a large logo positioned to the left of my dropdown button which I want users to be able to click on to take them back to the home page. Unfortunately, part of this logo is covered by the Bootstrap button.
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<a href="#">
<div class="logo" style="width: 300px; height: 300px; background-color: black;"></div>
</a>
<div class="dropdown custom-drop hide">
<a class="btn float-right btn-secondary btn-lg dropdown-toggle" href="#" role="button" id="dropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Menu
</a>
<div class="dropdown-menu" aria-labelledby="dropdownMenuLink">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</div>
<style>
.dropdown {
position: absolute;
z-index: 99;
width: 100%;
top: 100px;
}
.dropdown-toggle {
margin-right: 50px;
}
.dropdown-menu {
text-align: center;
z-index: 999;
width: 100%;
}
.dropdown-item {
padding: 0.75rem 1.5rem;
width: 100%;
}
</style>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js" integrity="sha384-b/U6ypiBEHpOf/4+1nzFpr53nxSS+GLCkfwBdFNTxtclqqenISfwAzpKaMNFNmj4" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script>
</body>
</html>
How can I fix this?
Upvotes: 1
Views: 545
Reputation: 1937
You can limit the area of the dropdown changing its width.
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<div class="logo-container">
<a href="#">
<div class="logo"></div>
</a>
</div>
<div class="dropdown custom-drop hide">
<a class="btn float-right btn-secondary btn-lg dropdown-toggle" href="#" role="button" id="dropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Menu
</a>
<div class="dropdown-menu" aria-labelledby="dropdownMenuLink">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</div>
<style>
.logo-container {
width: 300px;
height: 300px;
overflow: hidden;
}
.logo {
background-color: black;
width: 100%;
height: 100%;
}
.dropdown {
position: absolute;
z-index: 99;
width: calc(100% - 320px);
top: 100px;
right: 0px;
}
.dropdown-toggle {
margin-right: 50px;
}
.dropdown-menu {
position: absolute;
text-align: center;
z-index: 999;
width: calc(100% + 320px);
}
.dropdown-item {
padding: 0.75rem 1.5rem;
width: 100%;
}
</style>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js" integrity="sha384-b/U6ypiBEHpOf/4+1nzFpr53nxSS+GLCkfwBdFNTxtclqqenISfwAzpKaMNFNmj4" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script>
</body>
</html>
Upvotes: 2