2 divs align next to each other with 75% and 25%












2














I need to have two divs next to each other. The left div has a width of 75% and the right 25%. The content of the left div must align left and the right div aligns right.



So this is what I did:



<div class="header_menu">
<div class="links">
Home Contact
</div>
<div class="social_media">
Contact twitter linkedin
</div>
</div>


The css:



.header_menu{
border-bottom:1px solid #CCC;
}

.links{
width:75%;
display:inline;
}
.social_media{
width:25%;
display:inline;
}


I tried to add a float:left; and float:right; but then the border isn't placed at the bottom anymore.....???



M.










share|improve this question


















  • 4




    display: inline ignores width or height values. it just takes dimensions based on the inside text content.
    – Mr_Green
    Nov 12 '15 at 13:52










  • try bootstrap, it will relieve you of CSS issues to an extend.
    – Lucky Chingi
    Nov 12 '15 at 13:54






  • 1




    Look into display: table; for parents and display: table-cell; for children.
    – Kyle
    Nov 12 '15 at 13:55












  • try float: left and float: right as you were trying and clear the float from the parent container. Search for "clearfix float" in google.
    – Mr_Green
    Nov 12 '15 at 13:56










  • @Kyle, Your answer did the trick. Thnx
    – Interactive
    Nov 12 '15 at 13:57
















2














I need to have two divs next to each other. The left div has a width of 75% and the right 25%. The content of the left div must align left and the right div aligns right.



So this is what I did:



<div class="header_menu">
<div class="links">
Home Contact
</div>
<div class="social_media">
Contact twitter linkedin
</div>
</div>


The css:



.header_menu{
border-bottom:1px solid #CCC;
}

.links{
width:75%;
display:inline;
}
.social_media{
width:25%;
display:inline;
}


I tried to add a float:left; and float:right; but then the border isn't placed at the bottom anymore.....???



M.










share|improve this question


















  • 4




    display: inline ignores width or height values. it just takes dimensions based on the inside text content.
    – Mr_Green
    Nov 12 '15 at 13:52










  • try bootstrap, it will relieve you of CSS issues to an extend.
    – Lucky Chingi
    Nov 12 '15 at 13:54






  • 1




    Look into display: table; for parents and display: table-cell; for children.
    – Kyle
    Nov 12 '15 at 13:55












  • try float: left and float: right as you were trying and clear the float from the parent container. Search for "clearfix float" in google.
    – Mr_Green
    Nov 12 '15 at 13:56










  • @Kyle, Your answer did the trick. Thnx
    – Interactive
    Nov 12 '15 at 13:57














2












2








2







I need to have two divs next to each other. The left div has a width of 75% and the right 25%. The content of the left div must align left and the right div aligns right.



So this is what I did:



<div class="header_menu">
<div class="links">
Home Contact
</div>
<div class="social_media">
Contact twitter linkedin
</div>
</div>


The css:



.header_menu{
border-bottom:1px solid #CCC;
}

.links{
width:75%;
display:inline;
}
.social_media{
width:25%;
display:inline;
}


I tried to add a float:left; and float:right; but then the border isn't placed at the bottom anymore.....???



M.










share|improve this question













I need to have two divs next to each other. The left div has a width of 75% and the right 25%. The content of the left div must align left and the right div aligns right.



So this is what I did:



<div class="header_menu">
<div class="links">
Home Contact
</div>
<div class="social_media">
Contact twitter linkedin
</div>
</div>


The css:



.header_menu{
border-bottom:1px solid #CCC;
}

.links{
width:75%;
display:inline;
}
.social_media{
width:25%;
display:inline;
}


I tried to add a float:left; and float:right; but then the border isn't placed at the bottom anymore.....???



M.







html css






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 12 '15 at 13:51









Interactive

5981031




5981031








  • 4




    display: inline ignores width or height values. it just takes dimensions based on the inside text content.
    – Mr_Green
    Nov 12 '15 at 13:52










  • try bootstrap, it will relieve you of CSS issues to an extend.
    – Lucky Chingi
    Nov 12 '15 at 13:54






  • 1




    Look into display: table; for parents and display: table-cell; for children.
    – Kyle
    Nov 12 '15 at 13:55












  • try float: left and float: right as you were trying and clear the float from the parent container. Search for "clearfix float" in google.
    – Mr_Green
    Nov 12 '15 at 13:56










  • @Kyle, Your answer did the trick. Thnx
    – Interactive
    Nov 12 '15 at 13:57














  • 4




    display: inline ignores width or height values. it just takes dimensions based on the inside text content.
    – Mr_Green
    Nov 12 '15 at 13:52










  • try bootstrap, it will relieve you of CSS issues to an extend.
    – Lucky Chingi
    Nov 12 '15 at 13:54






  • 1




    Look into display: table; for parents and display: table-cell; for children.
    – Kyle
    Nov 12 '15 at 13:55












  • try float: left and float: right as you were trying and clear the float from the parent container. Search for "clearfix float" in google.
    – Mr_Green
    Nov 12 '15 at 13:56










  • @Kyle, Your answer did the trick. Thnx
    – Interactive
    Nov 12 '15 at 13:57








4




4




display: inline ignores width or height values. it just takes dimensions based on the inside text content.
– Mr_Green
Nov 12 '15 at 13:52




display: inline ignores width or height values. it just takes dimensions based on the inside text content.
– Mr_Green
Nov 12 '15 at 13:52












try bootstrap, it will relieve you of CSS issues to an extend.
– Lucky Chingi
Nov 12 '15 at 13:54




try bootstrap, it will relieve you of CSS issues to an extend.
– Lucky Chingi
Nov 12 '15 at 13:54




1




1




Look into display: table; for parents and display: table-cell; for children.
– Kyle
Nov 12 '15 at 13:55






Look into display: table; for parents and display: table-cell; for children.
– Kyle
Nov 12 '15 at 13:55














try float: left and float: right as you were trying and clear the float from the parent container. Search for "clearfix float" in google.
– Mr_Green
Nov 12 '15 at 13:56




try float: left and float: right as you were trying and clear the float from the parent container. Search for "clearfix float" in google.
– Mr_Green
Nov 12 '15 at 13:56












@Kyle, Your answer did the trick. Thnx
– Interactive
Nov 12 '15 at 13:57




@Kyle, Your answer did the trick. Thnx
– Interactive
Nov 12 '15 at 13:57












5 Answers
5






active

oldest

votes


















3














Take a look into this jsfiddle that should work for you:



https://jsfiddle.net/cmkgn4fg/4/



HTML-Code:



<div class="header_menu">
<div class="links">
Home Contact
</div>
<div class="social_media">
Contact twitter linkedin
</div>
<div class="clearfix"></div>
</div>


CSS-Code:



.header_menu{
border-bottom:1px solid #CCC;
width:100%;
}

.links{
width:75%;
float:left;
text-align:left;
}
.social_media{
width:25%;
float:left;
text-align:right;
}
.clearfix{
clear:both;
}





share|improve this answer























  • Can I suggest adding a comment why you have used box-sizing:border-box could be confusing to a newbie if they try your solution of floats and it doesn't work as they have added a border with no box-sizing adjustments.
    – DavidT
    Nov 12 '15 at 13:59










  • Why you have to use box-sizing:border-box can you read here: css-tricks.com/box-sizing
    – cgee
    Nov 12 '15 at 14:00










  • in fact, now you have removed the border I believe you can remove the box sizing all together.
    – DavidT
    Nov 12 '15 at 14:03










  • Oh yes.. it was only for testing for me.. But instead of this.. box-sizing:border-box is everytime a good idea to develop a website :)
    – cgee
    Nov 12 '15 at 14:04










  • Adding an extra <div class="clearfix"></div> for the sake of clear floats is bad practice. Add the clearing to the header_menu, its there already and perfect in this case.
    – LGSon
    Nov 12 '15 at 14:22



















2














You were almost there. inline-block is the one to use.



As inline elements has a white space, which will make them slightly bigger than 75% / 25% and therefore break them into 2 lines as they would exceed 100%, margin-right: -4px; is one way to fix that and make them both stay on 1 line.



Note, the -4px is based on the set font and might need to be adjusted, so here are a more options:




  • How do I remove the space between inline-block elements?


Stack snippet






.header_menu{
border-bottom:1px solid #CCC;
}

.links{
display: inline-block;
margin-right: -4px;
width:75%;
text-align: left;
}
.social_media{
display: inline-block;
margin-right: -4px;
width:25%;
text-align: right;
}

<div class="header_menu">
<div class="links">
Home Contact
</div>
<div class="social_media">
Contact twitter linkedin
</div>
</div>








share|improve this answer































    1














    Inline elements don't respond to width and height styles, which is why you are running into this issue.



    Remember when floating divs, you will need a clearfix. You can read about clearfixes here



    <div class="header_menu clearfix">
    <div class="links">
    Home Contact
    </div>
    <div class="social_media">
    Contact twitter linkedin
    </div>
    </div>


    Then your CSS.



    .header_menu{
    border-bottom:1px solid #CCC;
    }
    .links{
    width:75%;
    float:left;
    }
    .social_media{
    width:25%;
    float:right;
    }





    share|improve this answer































      1














      The rule display: inline; ignores height and width, as the element is now an inline level element (as in it should be treated as part of text/content) but with the display properties table and table-cell you can achieve the layout you require:



      <div class="header_menu">
      <div class="links">
      Home Contact
      </div>
      <div class="social_media">
      Contact twitter linkedin
      </div>
      </div>


      And the CSS:



      .header_menu{
      border-bottom:1px solid #CCC;
      display: table;
      }

      .links{
      width:75%;
      displaY: table-cell;
      }
      .social_media{
      width:25%;
      display:table-cell;
      }


      This forces table-like behavior onto the elements but also keeps the styling options of the HTML elements you're using.



      Example on jsFiddle.






      share|improve this answer





























        0














        try this :



        <div class="header_menu"
        <div class="links">
        Home Contact
        </div>
        <div class="social_media clear">
        Contact twitter linkedin
        </div>
        </div>


        and in your css file :



        .header_menu{
        border-bottom:1px solid #CCC;
        }


        .links{
        width:75%;
        display:inline-block;
        float: left;
        clear: both;
        background-color: red;
        }
        .social_media{
        width:25%;
        float: right;
        display:inline-block;
        background-color: orange;
        }


        the colors bck is for you to see the layout clearly ! hope this would help






        share|improve this answer





















          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f33672991%2f2-divs-align-next-to-each-other-with-75-and-25%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          5 Answers
          5






          active

          oldest

          votes








          5 Answers
          5






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          3














          Take a look into this jsfiddle that should work for you:



          https://jsfiddle.net/cmkgn4fg/4/



          HTML-Code:



          <div class="header_menu">
          <div class="links">
          Home Contact
          </div>
          <div class="social_media">
          Contact twitter linkedin
          </div>
          <div class="clearfix"></div>
          </div>


          CSS-Code:



          .header_menu{
          border-bottom:1px solid #CCC;
          width:100%;
          }

          .links{
          width:75%;
          float:left;
          text-align:left;
          }
          .social_media{
          width:25%;
          float:left;
          text-align:right;
          }
          .clearfix{
          clear:both;
          }





          share|improve this answer























          • Can I suggest adding a comment why you have used box-sizing:border-box could be confusing to a newbie if they try your solution of floats and it doesn't work as they have added a border with no box-sizing adjustments.
            – DavidT
            Nov 12 '15 at 13:59










          • Why you have to use box-sizing:border-box can you read here: css-tricks.com/box-sizing
            – cgee
            Nov 12 '15 at 14:00










          • in fact, now you have removed the border I believe you can remove the box sizing all together.
            – DavidT
            Nov 12 '15 at 14:03










          • Oh yes.. it was only for testing for me.. But instead of this.. box-sizing:border-box is everytime a good idea to develop a website :)
            – cgee
            Nov 12 '15 at 14:04










          • Adding an extra <div class="clearfix"></div> for the sake of clear floats is bad practice. Add the clearing to the header_menu, its there already and perfect in this case.
            – LGSon
            Nov 12 '15 at 14:22
















          3














          Take a look into this jsfiddle that should work for you:



          https://jsfiddle.net/cmkgn4fg/4/



          HTML-Code:



          <div class="header_menu">
          <div class="links">
          Home Contact
          </div>
          <div class="social_media">
          Contact twitter linkedin
          </div>
          <div class="clearfix"></div>
          </div>


          CSS-Code:



          .header_menu{
          border-bottom:1px solid #CCC;
          width:100%;
          }

          .links{
          width:75%;
          float:left;
          text-align:left;
          }
          .social_media{
          width:25%;
          float:left;
          text-align:right;
          }
          .clearfix{
          clear:both;
          }





          share|improve this answer























          • Can I suggest adding a comment why you have used box-sizing:border-box could be confusing to a newbie if they try your solution of floats and it doesn't work as they have added a border with no box-sizing adjustments.
            – DavidT
            Nov 12 '15 at 13:59










          • Why you have to use box-sizing:border-box can you read here: css-tricks.com/box-sizing
            – cgee
            Nov 12 '15 at 14:00










          • in fact, now you have removed the border I believe you can remove the box sizing all together.
            – DavidT
            Nov 12 '15 at 14:03










          • Oh yes.. it was only for testing for me.. But instead of this.. box-sizing:border-box is everytime a good idea to develop a website :)
            – cgee
            Nov 12 '15 at 14:04










          • Adding an extra <div class="clearfix"></div> for the sake of clear floats is bad practice. Add the clearing to the header_menu, its there already and perfect in this case.
            – LGSon
            Nov 12 '15 at 14:22














          3












          3








          3






          Take a look into this jsfiddle that should work for you:



          https://jsfiddle.net/cmkgn4fg/4/



          HTML-Code:



          <div class="header_menu">
          <div class="links">
          Home Contact
          </div>
          <div class="social_media">
          Contact twitter linkedin
          </div>
          <div class="clearfix"></div>
          </div>


          CSS-Code:



          .header_menu{
          border-bottom:1px solid #CCC;
          width:100%;
          }

          .links{
          width:75%;
          float:left;
          text-align:left;
          }
          .social_media{
          width:25%;
          float:left;
          text-align:right;
          }
          .clearfix{
          clear:both;
          }





          share|improve this answer














          Take a look into this jsfiddle that should work for you:



          https://jsfiddle.net/cmkgn4fg/4/



          HTML-Code:



          <div class="header_menu">
          <div class="links">
          Home Contact
          </div>
          <div class="social_media">
          Contact twitter linkedin
          </div>
          <div class="clearfix"></div>
          </div>


          CSS-Code:



          .header_menu{
          border-bottom:1px solid #CCC;
          width:100%;
          }

          .links{
          width:75%;
          float:left;
          text-align:left;
          }
          .social_media{
          width:25%;
          float:left;
          text-align:right;
          }
          .clearfix{
          clear:both;
          }






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 12 '15 at 14:04

























          answered Nov 12 '15 at 13:56









          cgee

          1,2661629




          1,2661629












          • Can I suggest adding a comment why you have used box-sizing:border-box could be confusing to a newbie if they try your solution of floats and it doesn't work as they have added a border with no box-sizing adjustments.
            – DavidT
            Nov 12 '15 at 13:59










          • Why you have to use box-sizing:border-box can you read here: css-tricks.com/box-sizing
            – cgee
            Nov 12 '15 at 14:00










          • in fact, now you have removed the border I believe you can remove the box sizing all together.
            – DavidT
            Nov 12 '15 at 14:03










          • Oh yes.. it was only for testing for me.. But instead of this.. box-sizing:border-box is everytime a good idea to develop a website :)
            – cgee
            Nov 12 '15 at 14:04










          • Adding an extra <div class="clearfix"></div> for the sake of clear floats is bad practice. Add the clearing to the header_menu, its there already and perfect in this case.
            – LGSon
            Nov 12 '15 at 14:22


















          • Can I suggest adding a comment why you have used box-sizing:border-box could be confusing to a newbie if they try your solution of floats and it doesn't work as they have added a border with no box-sizing adjustments.
            – DavidT
            Nov 12 '15 at 13:59










          • Why you have to use box-sizing:border-box can you read here: css-tricks.com/box-sizing
            – cgee
            Nov 12 '15 at 14:00










          • in fact, now you have removed the border I believe you can remove the box sizing all together.
            – DavidT
            Nov 12 '15 at 14:03










          • Oh yes.. it was only for testing for me.. But instead of this.. box-sizing:border-box is everytime a good idea to develop a website :)
            – cgee
            Nov 12 '15 at 14:04










          • Adding an extra <div class="clearfix"></div> for the sake of clear floats is bad practice. Add the clearing to the header_menu, its there already and perfect in this case.
            – LGSon
            Nov 12 '15 at 14:22
















          Can I suggest adding a comment why you have used box-sizing:border-box could be confusing to a newbie if they try your solution of floats and it doesn't work as they have added a border with no box-sizing adjustments.
          – DavidT
          Nov 12 '15 at 13:59




          Can I suggest adding a comment why you have used box-sizing:border-box could be confusing to a newbie if they try your solution of floats and it doesn't work as they have added a border with no box-sizing adjustments.
          – DavidT
          Nov 12 '15 at 13:59












          Why you have to use box-sizing:border-box can you read here: css-tricks.com/box-sizing
          – cgee
          Nov 12 '15 at 14:00




          Why you have to use box-sizing:border-box can you read here: css-tricks.com/box-sizing
          – cgee
          Nov 12 '15 at 14:00












          in fact, now you have removed the border I believe you can remove the box sizing all together.
          – DavidT
          Nov 12 '15 at 14:03




          in fact, now you have removed the border I believe you can remove the box sizing all together.
          – DavidT
          Nov 12 '15 at 14:03












          Oh yes.. it was only for testing for me.. But instead of this.. box-sizing:border-box is everytime a good idea to develop a website :)
          – cgee
          Nov 12 '15 at 14:04




          Oh yes.. it was only for testing for me.. But instead of this.. box-sizing:border-box is everytime a good idea to develop a website :)
          – cgee
          Nov 12 '15 at 14:04












          Adding an extra <div class="clearfix"></div> for the sake of clear floats is bad practice. Add the clearing to the header_menu, its there already and perfect in this case.
          – LGSon
          Nov 12 '15 at 14:22




          Adding an extra <div class="clearfix"></div> for the sake of clear floats is bad practice. Add the clearing to the header_menu, its there already and perfect in this case.
          – LGSon
          Nov 12 '15 at 14:22













          2














          You were almost there. inline-block is the one to use.



          As inline elements has a white space, which will make them slightly bigger than 75% / 25% and therefore break them into 2 lines as they would exceed 100%, margin-right: -4px; is one way to fix that and make them both stay on 1 line.



          Note, the -4px is based on the set font and might need to be adjusted, so here are a more options:




          • How do I remove the space between inline-block elements?


          Stack snippet






          .header_menu{
          border-bottom:1px solid #CCC;
          }

          .links{
          display: inline-block;
          margin-right: -4px;
          width:75%;
          text-align: left;
          }
          .social_media{
          display: inline-block;
          margin-right: -4px;
          width:25%;
          text-align: right;
          }

          <div class="header_menu">
          <div class="links">
          Home Contact
          </div>
          <div class="social_media">
          Contact twitter linkedin
          </div>
          </div>








          share|improve this answer




























            2














            You were almost there. inline-block is the one to use.



            As inline elements has a white space, which will make them slightly bigger than 75% / 25% and therefore break them into 2 lines as they would exceed 100%, margin-right: -4px; is one way to fix that and make them both stay on 1 line.



            Note, the -4px is based on the set font and might need to be adjusted, so here are a more options:




            • How do I remove the space between inline-block elements?


            Stack snippet






            .header_menu{
            border-bottom:1px solid #CCC;
            }

            .links{
            display: inline-block;
            margin-right: -4px;
            width:75%;
            text-align: left;
            }
            .social_media{
            display: inline-block;
            margin-right: -4px;
            width:25%;
            text-align: right;
            }

            <div class="header_menu">
            <div class="links">
            Home Contact
            </div>
            <div class="social_media">
            Contact twitter linkedin
            </div>
            </div>








            share|improve this answer


























              2












              2








              2






              You were almost there. inline-block is the one to use.



              As inline elements has a white space, which will make them slightly bigger than 75% / 25% and therefore break them into 2 lines as they would exceed 100%, margin-right: -4px; is one way to fix that and make them both stay on 1 line.



              Note, the -4px is based on the set font and might need to be adjusted, so here are a more options:




              • How do I remove the space between inline-block elements?


              Stack snippet






              .header_menu{
              border-bottom:1px solid #CCC;
              }

              .links{
              display: inline-block;
              margin-right: -4px;
              width:75%;
              text-align: left;
              }
              .social_media{
              display: inline-block;
              margin-right: -4px;
              width:25%;
              text-align: right;
              }

              <div class="header_menu">
              <div class="links">
              Home Contact
              </div>
              <div class="social_media">
              Contact twitter linkedin
              </div>
              </div>








              share|improve this answer














              You were almost there. inline-block is the one to use.



              As inline elements has a white space, which will make them slightly bigger than 75% / 25% and therefore break them into 2 lines as they would exceed 100%, margin-right: -4px; is one way to fix that and make them both stay on 1 line.



              Note, the -4px is based on the set font and might need to be adjusted, so here are a more options:




              • How do I remove the space between inline-block elements?


              Stack snippet






              .header_menu{
              border-bottom:1px solid #CCC;
              }

              .links{
              display: inline-block;
              margin-right: -4px;
              width:75%;
              text-align: left;
              }
              .social_media{
              display: inline-block;
              margin-right: -4px;
              width:25%;
              text-align: right;
              }

              <div class="header_menu">
              <div class="links">
              Home Contact
              </div>
              <div class="social_media">
              Contact twitter linkedin
              </div>
              </div>








              .header_menu{
              border-bottom:1px solid #CCC;
              }

              .links{
              display: inline-block;
              margin-right: -4px;
              width:75%;
              text-align: left;
              }
              .social_media{
              display: inline-block;
              margin-right: -4px;
              width:25%;
              text-align: right;
              }

              <div class="header_menu">
              <div class="links">
              Home Contact
              </div>
              <div class="social_media">
              Contact twitter linkedin
              </div>
              </div>





              .header_menu{
              border-bottom:1px solid #CCC;
              }

              .links{
              display: inline-block;
              margin-right: -4px;
              width:75%;
              text-align: left;
              }
              .social_media{
              display: inline-block;
              margin-right: -4px;
              width:25%;
              text-align: right;
              }

              <div class="header_menu">
              <div class="links">
              Home Contact
              </div>
              <div class="social_media">
              Contact twitter linkedin
              </div>
              </div>






              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Nov 21 at 10:23

























              answered Nov 12 '15 at 14:08









              LGSon

              69.2k84484




              69.2k84484























                  1














                  Inline elements don't respond to width and height styles, which is why you are running into this issue.



                  Remember when floating divs, you will need a clearfix. You can read about clearfixes here



                  <div class="header_menu clearfix">
                  <div class="links">
                  Home Contact
                  </div>
                  <div class="social_media">
                  Contact twitter linkedin
                  </div>
                  </div>


                  Then your CSS.



                  .header_menu{
                  border-bottom:1px solid #CCC;
                  }
                  .links{
                  width:75%;
                  float:left;
                  }
                  .social_media{
                  width:25%;
                  float:right;
                  }





                  share|improve this answer




























                    1














                    Inline elements don't respond to width and height styles, which is why you are running into this issue.



                    Remember when floating divs, you will need a clearfix. You can read about clearfixes here



                    <div class="header_menu clearfix">
                    <div class="links">
                    Home Contact
                    </div>
                    <div class="social_media">
                    Contact twitter linkedin
                    </div>
                    </div>


                    Then your CSS.



                    .header_menu{
                    border-bottom:1px solid #CCC;
                    }
                    .links{
                    width:75%;
                    float:left;
                    }
                    .social_media{
                    width:25%;
                    float:right;
                    }





                    share|improve this answer


























                      1












                      1








                      1






                      Inline elements don't respond to width and height styles, which is why you are running into this issue.



                      Remember when floating divs, you will need a clearfix. You can read about clearfixes here



                      <div class="header_menu clearfix">
                      <div class="links">
                      Home Contact
                      </div>
                      <div class="social_media">
                      Contact twitter linkedin
                      </div>
                      </div>


                      Then your CSS.



                      .header_menu{
                      border-bottom:1px solid #CCC;
                      }
                      .links{
                      width:75%;
                      float:left;
                      }
                      .social_media{
                      width:25%;
                      float:right;
                      }





                      share|improve this answer














                      Inline elements don't respond to width and height styles, which is why you are running into this issue.



                      Remember when floating divs, you will need a clearfix. You can read about clearfixes here



                      <div class="header_menu clearfix">
                      <div class="links">
                      Home Contact
                      </div>
                      <div class="social_media">
                      Contact twitter linkedin
                      </div>
                      </div>


                      Then your CSS.



                      .header_menu{
                      border-bottom:1px solid #CCC;
                      }
                      .links{
                      width:75%;
                      float:left;
                      }
                      .social_media{
                      width:25%;
                      float:right;
                      }






                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited May 23 '17 at 10:27









                      Community

                      11




                      11










                      answered Nov 12 '15 at 13:57









                      dgarbacz

                      7381517




                      7381517























                          1














                          The rule display: inline; ignores height and width, as the element is now an inline level element (as in it should be treated as part of text/content) but with the display properties table and table-cell you can achieve the layout you require:



                          <div class="header_menu">
                          <div class="links">
                          Home Contact
                          </div>
                          <div class="social_media">
                          Contact twitter linkedin
                          </div>
                          </div>


                          And the CSS:



                          .header_menu{
                          border-bottom:1px solid #CCC;
                          display: table;
                          }

                          .links{
                          width:75%;
                          displaY: table-cell;
                          }
                          .social_media{
                          width:25%;
                          display:table-cell;
                          }


                          This forces table-like behavior onto the elements but also keeps the styling options of the HTML elements you're using.



                          Example on jsFiddle.






                          share|improve this answer


























                            1














                            The rule display: inline; ignores height and width, as the element is now an inline level element (as in it should be treated as part of text/content) but with the display properties table and table-cell you can achieve the layout you require:



                            <div class="header_menu">
                            <div class="links">
                            Home Contact
                            </div>
                            <div class="social_media">
                            Contact twitter linkedin
                            </div>
                            </div>


                            And the CSS:



                            .header_menu{
                            border-bottom:1px solid #CCC;
                            display: table;
                            }

                            .links{
                            width:75%;
                            displaY: table-cell;
                            }
                            .social_media{
                            width:25%;
                            display:table-cell;
                            }


                            This forces table-like behavior onto the elements but also keeps the styling options of the HTML elements you're using.



                            Example on jsFiddle.






                            share|improve this answer
























                              1












                              1








                              1






                              The rule display: inline; ignores height and width, as the element is now an inline level element (as in it should be treated as part of text/content) but with the display properties table and table-cell you can achieve the layout you require:



                              <div class="header_menu">
                              <div class="links">
                              Home Contact
                              </div>
                              <div class="social_media">
                              Contact twitter linkedin
                              </div>
                              </div>


                              And the CSS:



                              .header_menu{
                              border-bottom:1px solid #CCC;
                              display: table;
                              }

                              .links{
                              width:75%;
                              displaY: table-cell;
                              }
                              .social_media{
                              width:25%;
                              display:table-cell;
                              }


                              This forces table-like behavior onto the elements but also keeps the styling options of the HTML elements you're using.



                              Example on jsFiddle.






                              share|improve this answer












                              The rule display: inline; ignores height and width, as the element is now an inline level element (as in it should be treated as part of text/content) but with the display properties table and table-cell you can achieve the layout you require:



                              <div class="header_menu">
                              <div class="links">
                              Home Contact
                              </div>
                              <div class="social_media">
                              Contact twitter linkedin
                              </div>
                              </div>


                              And the CSS:



                              .header_menu{
                              border-bottom:1px solid #CCC;
                              display: table;
                              }

                              .links{
                              width:75%;
                              displaY: table-cell;
                              }
                              .social_media{
                              width:25%;
                              display:table-cell;
                              }


                              This forces table-like behavior onto the elements but also keeps the styling options of the HTML elements you're using.



                              Example on jsFiddle.







                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Nov 12 '15 at 14:01









                              Kyle

                              48.2k27132146




                              48.2k27132146























                                  0














                                  try this :



                                  <div class="header_menu"
                                  <div class="links">
                                  Home Contact
                                  </div>
                                  <div class="social_media clear">
                                  Contact twitter linkedin
                                  </div>
                                  </div>


                                  and in your css file :



                                  .header_menu{
                                  border-bottom:1px solid #CCC;
                                  }


                                  .links{
                                  width:75%;
                                  display:inline-block;
                                  float: left;
                                  clear: both;
                                  background-color: red;
                                  }
                                  .social_media{
                                  width:25%;
                                  float: right;
                                  display:inline-block;
                                  background-color: orange;
                                  }


                                  the colors bck is for you to see the layout clearly ! hope this would help






                                  share|improve this answer


























                                    0














                                    try this :



                                    <div class="header_menu"
                                    <div class="links">
                                    Home Contact
                                    </div>
                                    <div class="social_media clear">
                                    Contact twitter linkedin
                                    </div>
                                    </div>


                                    and in your css file :



                                    .header_menu{
                                    border-bottom:1px solid #CCC;
                                    }


                                    .links{
                                    width:75%;
                                    display:inline-block;
                                    float: left;
                                    clear: both;
                                    background-color: red;
                                    }
                                    .social_media{
                                    width:25%;
                                    float: right;
                                    display:inline-block;
                                    background-color: orange;
                                    }


                                    the colors bck is for you to see the layout clearly ! hope this would help






                                    share|improve this answer
























                                      0












                                      0








                                      0






                                      try this :



                                      <div class="header_menu"
                                      <div class="links">
                                      Home Contact
                                      </div>
                                      <div class="social_media clear">
                                      Contact twitter linkedin
                                      </div>
                                      </div>


                                      and in your css file :



                                      .header_menu{
                                      border-bottom:1px solid #CCC;
                                      }


                                      .links{
                                      width:75%;
                                      display:inline-block;
                                      float: left;
                                      clear: both;
                                      background-color: red;
                                      }
                                      .social_media{
                                      width:25%;
                                      float: right;
                                      display:inline-block;
                                      background-color: orange;
                                      }


                                      the colors bck is for you to see the layout clearly ! hope this would help






                                      share|improve this answer












                                      try this :



                                      <div class="header_menu"
                                      <div class="links">
                                      Home Contact
                                      </div>
                                      <div class="social_media clear">
                                      Contact twitter linkedin
                                      </div>
                                      </div>


                                      and in your css file :



                                      .header_menu{
                                      border-bottom:1px solid #CCC;
                                      }


                                      .links{
                                      width:75%;
                                      display:inline-block;
                                      float: left;
                                      clear: both;
                                      background-color: red;
                                      }
                                      .social_media{
                                      width:25%;
                                      float: right;
                                      display:inline-block;
                                      background-color: orange;
                                      }


                                      the colors bck is for you to see the layout clearly ! hope this would help







                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Nov 12 '15 at 14:14









                                      IKEN Lemjahed Ayoub

                                      10417




                                      10417






























                                          draft saved

                                          draft discarded




















































                                          Thanks for contributing an answer to Stack Overflow!


                                          • Please be sure to answer the question. Provide details and share your research!

                                          But avoid



                                          • Asking for help, clarification, or responding to other answers.

                                          • Making statements based on opinion; back them up with references or personal experience.


                                          To learn more, see our tips on writing great answers.





                                          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                          Please pay close attention to the following guidance:


                                          • Please be sure to answer the question. Provide details and share your research!

                                          But avoid



                                          • Asking for help, clarification, or responding to other answers.

                                          • Making statements based on opinion; back them up with references or personal experience.


                                          To learn more, see our tips on writing great answers.




                                          draft saved


                                          draft discarded














                                          StackExchange.ready(
                                          function () {
                                          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f33672991%2f2-divs-align-next-to-each-other-with-75-and-25%23new-answer', 'question_page');
                                          }
                                          );

                                          Post as a guest















                                          Required, but never shown





















































                                          Required, but never shown














                                          Required, but never shown












                                          Required, but never shown







                                          Required, but never shown

































                                          Required, but never shown














                                          Required, but never shown












                                          Required, but never shown







                                          Required, but never shown







                                          Popular posts from this blog

                                          404 Error Contact Form 7 ajax form submitting

                                          How to know if a Active Directory user can login interactively

                                          Refactoring coordinates for Minecraft Pi buildings written in Python