Jump to content

W3 CSS Mobile

Recommended Posts




Following this snippet:


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 -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">

<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>
    <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>


Share this post

Link to post
Share on other sites

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.

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...