Home > Software engineering >  Div text & image responsive using css
Div text & image responsive using css

Time:06-06

I have the left & right columns, I want the image to be responsive when I minimize the screen & by default both left & right should cover the whole screen. when I minimize the screen the right image becomes small & when I check on the mobile device the left column is covering 80% of the screen. Please help me to fix the responsive image & what I'm missing. Below is my code.

    div.container {
      mc-grid-row: true;
      margin-left: auto;
      margin-right: auto;
      display: flex;
      flex-wrap: wrap;
      justify-content: center;
      width: 100%
    }

    div.box {
      position: relative;
      box-sizing: border-box;
      margin-bottom: 0;
      width: 50%;
      min-width: 300px;
  
    }


* {
    box-sizing: border-box;
      outline: 0;
      padding: 0;
      margin: 0;
  }
body {
  margin: 0;
}
    .col-left{
        background: #efefef;
        box-shadow: 16px 0px 26px rgba(0, 0, 0, 0.3);
        width:50%;
        height:auto;
    
    }
    .col-right{
        width:50%;
        height:auto;    
    }
    .col-right img {
        width:100%;
        height:auto;
        background-repeat:no-repeat;
        background-size:cover;
        background-position:center center;
    }
    

.container{
    position:relative;
    left:126px; 
}
label {
    display: inline-block;
    max-width: 100%;
}

.container .main:after {
    clear: both;
    display: block;
    content: '';
}
.main{
    margin-left: 43px;
    width: 547px;
    height: 120px;
}

.content{
    position:relative;
    left: 126px;
    margin-top:175px;

}
.text{
    width: 547px;
    height: 213px;  
}

.title{
    font-family: 'Inter';
    font-style: italic;
    font-weight: 300;
    font-size: 36px;
    line-height: 44px;
    letter-spacing: 0.005em;
    color: #FFFFFF;
}

.container{
    margin-top:162px;
}
.author{
    font-family: 'Inter-Regular';
    font-style: normal;
    font-weight: 600;
    font-size: 28px;
    line-height: 33px;
    color: #FFFFFF;
    margin-top:48px;
    
}   


@media only screen and (min-width: 638px) and (max-width: 1334px) {
    
    .title{
        font-size:33px;
    }   
}

@media only screen and (min-width: 638px) and (max-width: 1251px) {
    
    .title{
        font-size:32px;
    }   
}
@media only screen and (min-width: 638px) and (max-width: 1171px) {
    
    .title{
        font-size:30px;
    }   
}
@media only screen and (min-width: 638px) and (max-width: 1130px) {
    
    .title{
        font-size:30px;
    }   
}
@media only screen and (min-width: 638px) and (max-width: 1056px) {
    
    .title{
        font-size:30px;
    }   
}

@media only screen and (min-width: 638px) and (max-width: 994px) {
    
    .title{
        font-size:30px;
    }   
}
@media only screen and (min-width: 638px) and (max-width: 987px) {
    
    .title{
        font-size:30px;
    }   
}
@media only screen and (min-width: 638px) and (max-width: 942px) {
    
    .title{
        font-size:30px;
    }   
}
@media only screen and (min-width: 638px) and (max-width: 838px) {
    
    .title{
        font-size:30px;
    }   
}
@media only screen and (min-width: 638px) and (max-width: 811px) {
    .ls-title{
        font-size: 18px;
        width: 320px;
    }
    .title{
        font-size:30px;
    }   
}
@media only screen and (min-width: 638px) and (max-width: 760px) {
    
    .title{
        font-size:30px;
    }   
}
@media only screen and (min-width: 638px) and (max-width: 709px) {
    
    .title{
        font-size:30px;
    }   
}

@media only screen and (min-width: 375px) and (max-width: 680px) {
    
    .container .main:before {
        width: 12px;
        height: 64px;
    }
    .container{
        left:40px;
    }   
    .ls-logo-wrap{
        left:40px;  
    }
    .main{
        margin-left:24px;
    }
    .content {
        left: 40px;
        margin-top: 43px;
    }
    .title{
        font-size:18px;
        width:280px;
        line-height:28px;
    }
    .author{
        margin-top:16px;
        font-size:18px;     
    }
    
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div >
        <div >
            <div >
                <div >
                    <label >textheretextherertexthere</label>
                </div>
            </div>
            <div >
                <div >
                    <label >textheretextheretextheretextheretextheretexthere</label>
                </div>
            </div>
            

        </div>
        <div >
            <img src="http://img.huffingtonpost.com/asset/scalefit_600_noupscale/56328113190000a600b9540d.jpeg" />
        </div>
    </div>

CodePudding user response:

This code snippet will help you to solve your problem! check it out If you need any help let me know :)

I have noticed you were using the same classes "title" inside two different fields maybe it can impact your styling sometimes :)

Also, you were using a lot of media queries which were not needed as I believe. You can learn more about RWD here :)

https://css-tricks.com/a-complete-guide-to-css-media-queries/

.container {
      display: flex;
  /*       flex-direction: row;
      height: min-content; */
  }

  .box {
      position: relative;
      box-sizing: border-box;
      margin-bottom: 0;
    }

* {
    box-sizing: border-box;
      outline: 0;
      padding: 0;
      margin: 0;
  }
body {
  margin: 0;
}

    .col-left{
        background: black;
        box-shadow: 16px 0px 26px rgba(0, 0, 0, 0.3);
        width:50%;
    
    }
    .col-right{
        width:50%;
        height:auto;    
    }
    .col-right img {
        width:100%;
        height:auto;
        background-repeat:no-repeat;
        background-size:cover;
        background-position:center center;
    }
    
label {
    display: inline-block;
    max-width: 100%;
}

.container .main:after {
    clear: both;
    display: block;
    content: '';
}

.main{
    text-align: center;
    height: 120px;
}

.text{
    text-align: center;
    height: 213px;  
}

.title{
    font-family: 'Inter';
    font-style: italic;
    font-weight: 300;
    font-size: 36px;
    line-height: 44px;
    letter-spacing: 0.005em;
    color: #FFFFFF;
    overflow-wrap: break-word;
    padding: 5px;

}

.author{
    font-family: 'Inter-Regular';
    font-style: normal;
    font-weight: 600;
    font-size: 28px;
    line-height: 33px;
    color: #FFFFFF;
    margin-top:48px;
}   


@media (max-width: 800px)
{
    .container{
        flex-direction: column;
    text-align: center;
    align-items: center;
    }   
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div >
        <div >
<!--            here you have used the same class which is not a correct way to use  -->
            <div >
                <div >
                    <label >textheretextherertexthere</label>
                </div>
            </div>
            <div >
                <div >
                    <label >textheretextheretextheretextheretextheretexthere</label>
                </div>
            </div>
            

        </div>
        <div >
            <img src="http://img.huffingtonpost.com/asset/scalefit_600_noupscale/56328113190000a600b9540d.jpeg" />
        </div>
    </div>

  • Related