Aligning three elements (left/center/right) inside a container

后端 未结 4 1257
挽巷
挽巷 2021-01-21 01:34

I am attempting to create a full-width banner with three internal inline elements. A back link, a logo and a forward link.

I would also like to use the same cod

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-21 02:08

    Consider positioning the left and right elements differently.

    https://jsfiddle.net/5gxLvp8a/4/

      #header-wrap {
        text-align: center;
        border: 1px solid green;
        margin: 0 auto;
        padding: 1rem 2.5rem;
        position: relative;
        div {
          display: inline-block;
          vertical-align: middle;
        }
      }
      .header-left {
        float: left;
        border: 1px solid red;
        width: 100px;
        position: absolute;
        left: 25px;
      }
      .header-right {
        float: right;
        border: 1px solid red;
        width: 100px;
        position: absolute;
        right: 25px;
      }
    

    See code snippet below:

    html, html a {
      font-size: 10px; }
    
      #header-blue {
        width: 100%;
        margin-bottom: 50px;
        height: auto;
        background-color: #3498DB;
        color: #fff; }
        #header-blue #header-wrap {
          text-align: center;
          border: 1px solid green;
          margin: 0 auto;
          padding: 1rem 2.5rem;
          position: relative; }
          #header-blue #header-wrap div {
            display: inline-block;
            vertical-align: middle; }
        #header-blue .header-left {
          float: left;
          border: 1px solid red;
          width: 100px;
          position: absolute;
          left: 25px; }
          #header-blue .header-right {
            float: right;
            border: 1px solid red;
            width: 100px;
            position: absolute;
            right: 25px; }
            #header-blue .header-center {
              border: 1px solid red;
              margin: 0 auto !important;
              display: inline-block;
              width: 100px; }
    
    .clearfix:after {
      content: " ";
      visibility: hidden;
      display: block;
      height: 0;
      clear: both; }

    1

    2

    2

    2

    2

    3

    3

    1

    2

    2

    2

    2

提交回复
热议问题