Fixed width div on left, fill remaining width div on right

前端 未结 2 1404
庸人自扰
庸人自扰 2021-02-01 01:26

I want a div with a fixed width image on the left and a variable width div with a background color, which should extend its width 100% on my device. I can\'t stop the second div

2条回答
  •  情书的邮戳
    2021-02-01 01:45

    with the use of css grid you can achieve this more easily

    • you need to wrap those divs in a wrapper, lets say parent
    • give .parent display: grid
    • give grid-template-areas in .parent and grid-area in both children
    • no need to use float: left in both children adjust the width of left div using grid-template-columns in .parent

    .parent {
      display: grid;
      grid-template-columns: 240px 1fr;
      grid-template-rows: auto 1fr;
      grid-template-areas: "header-left header-right";
    }
    .header {
        background-image: url(img/header.png);
        background-color: #ebebeb;
        background-repeat: no-repeat;
        height: 100px;
        grid-area: header-left;
    }
    
    .header-right {
        overflow: hidden;
        background-color: #000;
        width: 100%;
        height: 100px;
        grid-area: header-right;
    }

    css has become much more advanced and answering with the help of that advanced css just if it can be useful to someone :)

提交回复
热议问题