简体   繁体   中英

responsive web design fluid image

I am using MVC razor code to generate website logo and struggling with image scaling with resizing website. I tried with image = max-width:100% and height:auto but it is not working!

Here is my code:

<div class="float-left">
   <p class="site-title">@Html.ActionLink(" ", "Home", "Home", null, new {@class = "crown_logo"})</p>
</div>

a.crown_logo {
 display:block;
 width:284px;
 height:87px;
 background-image :url("../GUI/Images/rsz_crown_2.png");
 text-indent: -9999px; /* hides the link text */
}

Check the fiddle here it should help you with your problem: responsive image The whole concept explained here css:

img.responsive_logo
{
    position: absolute;
    max-width: 80%;
    top: 10%;
    left: 10%;
    border-radius: 3px;
    box-shadow: 0 3px 6px rgba(0,0,0,0.9);
}

img.responsive_logo:empty
{
    top: 50%;
    left: 50%;
    -webkit-transform: translate(-50%, -50%);
    -moz-transform: translate(-50%, -50%);
    -ms-transform: translate(-50%, -50%);
    -o-transform: translate(-50%, -50%);
    transform: translate(-50%, -50%);
}

@media screen and (orientation: portrait) {
  img.responsive_logo {
      max-width: 90%;
  }
}

@media screen and (orientation: landscape) {
  img.responsive_logo {
      max-height: 90%;
  }
}

EDIT: Use actual image and not a background-image style. Originally your image has to have a dimensions as it should be displayed in 100% width and 100% height.

<div class="float-left">
    <a href='@Url.Action("Home", "Home")'><img src="ImageSource" class="responsive_logo" /></a>
</div>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM