skip to Main Content

Here’s a picture of the website

I am using button code from UIverse and I have them aligned to the center.

My only issue here is that when I use another screen size the buttons come out of the div. The code I am using will be listed below in a codeblock. If anyone can help I would love this. I’m making a concept website for my school. The image above shows how ‘Organizations’ is out of the orange div. I need it aligned in center inside the div so it’s flexible on screen sizes.

I would love some help, Thanks!

button {
    --hover-shadows: 16px 16px 33px #ffffff,
                      -16px -16px 33px #ffffff00;
    --accent: rgb(255, 255, 255);
    font-weight: bold;
    letter-spacing: 0.1em;
    border-radius: 1.1em;
    background-color: #ff7300;
    color: white;
    padding: 1em 2em;
    transition: box-shadow ease-in-out 0.3s,
                background-color ease-in-out 0.1s,
                letter-spacing ease-in-out 0.1s,
                transform ease-in-out 0.1s;
                border: solid;
                border-width: 3px;
                border-color: #ffffff;
                display: block;
                 margin: 0 auto;
    
   }
   
   button:hover {
    box-shadow: var(--hover-shadows);
   }
   
   button:active {
    box-shadow: var(--hover-shadows),
                 var(--accent) 0px 0px 30px 5px;
    background-color: var(--accent);
    transform: scale(0.95);
   }

   #navbuttons {
    height: 60px;
    text-align: center;
    background-color: #ff7300;
    vertical-align: middle;
   }
#Theactualbuttons {
    position: relative;
    top: 15%;
    vertical-align: middle;

I have tried changing the flex values and margin values, it didn’t seem to work really well.

3

Answers


  1. Chosen as BEST ANSWER

    Thanks for all the answers. I used the code listed below to fix it. Thanks for the help.

    Edit: I pasted the wrong thing. This is the actual code I used. I also upped the div sizes a bit. Thanks for all the help!

    display: inline-block;
    display: -moz-inline-box;
    *display: inline; /* For IE7 */
    zoom: 1; /* Trigger hasLayout */
    text-align: center;
    margin-left: 80;
    

  2. I would use a flex-box with justify set to centre or space-evenly

    the following link describes their use nicely
    https://css-tricks.com/snippets/css/a-guide-to-flexbox/

    rough example:

    CSS

    #nav {
      width: 100%;
      padding-top: 5px;
      padding-bottom: 5px;
      background-color: #ff7300;
      display: flex;
      flex-wrap: wrap; /*might want to try nowrap*/
      justify-content: space-evenly;
      vertical-align: middle;
    }
    
    #nav a {
      color: white;
      margin: 5px;
      padding-top: 10px;
      padding-bottom: 10px;
      border: solid 2px white;
      border-radius: 10px;
      flex-grow: 1;
      text-align: center;
      vertical-align: middle;
    }
    

    HTML

    <div id="nav">
      <a class="button">Home</a>
      <a class="button">Information</a>
      <a class="button">Curriculum</a>
      <a class="button">Staff Directory</a>
      <a class="button">Student Activities</a>
      <a class="button">Organizations</a>
    </div>
    
    Login or Signup to reply.
  3. Set width and height for the div container (can bee %) and button position to relative.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search