ideasvacuum Posted August 31, 2018 Share Posted August 31, 2018 Following this snippet: https://www.w3schools.com/w3css/tryit.asp?filename=tryw3css_ref_dropdown_menu2 As-is, the example works perfectly, but if edited for mobile (w3-mobile), all the buttons are stacked vertically in a narrow view port (as designed) but the buttons with dropdowns are not centered like the others - instead, they are justified left, which is incredibly ugly Here is my edit of the code - can anyone tell me what I'm doing wrong? <!DOCTYPE html <!-- https://www.w3schools.com/w3css/tryit.asp?filename=tryw3css_ref_dropdown_menu2 --> <html> <title>W3.CSS</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css"> <body> <div class="w3-container"> <h2>Navigation Bar with Dropdown</h2> <p>Add a dropdown menu inside the navigation bar:</p> <div class="w3-bar w3-light-grey"> <a href="#" class="w3-bar-item w3-button w3-mobile">Home</a> <a href="#" class="w3-bar-item w3-button w3-mobile">Link 1</a> <div class="w3-dropdown-hover"> <button class="w3-button w3-mobile">Dropdown</button> <div class="w3-dropdown-content w3-bar-block w3-card-4"> <a href="#" class="w3-bar-item w3-button">Link A</a> <a href="#" class="w3-bar-item w3-button">Link B</a> <a href="#" class="w3-bar-item w3-button">Link C</a> </div> </div> <a href="#" class="w3-bar-item w3-button w3-mobile">Link 2</a> <a href="#" class="w3-bar-item w3-button w3-mobile">Link 3</a> </div> </div> </body> </html> Link to comment Share on other sites More sharing options...
dsonesuk Posted September 1, 2018 Share Posted September 1, 2018 Add 'w3-mobile' class to 'w3-dropdown-hover' div class 1 Link to comment Share on other sites More sharing options...
ideasvacuum Posted September 1, 2018 Author Share Posted September 1, 2018 That works perfectly thank you. For the drop-down buttons, I was able to set them to center with inline style: style="text-align:center" Link to comment Share on other sites More sharing options...
dsonesuk Posted September 1, 2018 Share Posted September 1, 2018 The real question is WHY? didn't you use the same class 'w3-mobile' for them? Link to comment Share on other sites More sharing options...
ideasvacuum Posted September 25, 2018 Author Share Posted September 25, 2018 The reason why: By default, the navbar normal mode drop-down items are justified center, which is why I wanted them to be justified center in mobile mode. If you set the items as w3-mobile, they become left-justified on the navbar normal mode. A sort of chicken and egg thing. Any how, changed my mind and followed the recommendations here. Thanks all. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now