I am working on an MVC project. when trying to add a cover poster to the page, getting some margin in two sides. I tried several codes to get the image in full width, but it doesn’t work.
what I tried,
This is my full html and css.
.cover {
background-image: url("https://images.pexels.com/photos/133633/pexels-photo-133633.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1");
height: 100vh;
width: 100vw;
background-repeat: no-repeat;
background-size: cover;
background-position: center;
}
/*section {
margin-left: -115px;
margin-right: -115px;
}*/
body,html{
margin:0;
padding-top:0px;
padding-bottom:0px;
height:50%;
width:100%;
}
*{
margin:0;
padding:0;
}
@{
ViewBag.Title = "Home Page";
}
<section>
<div class="cover img-fluid"></div>
</section>
2
Answers
In the above question, the problem is not in the Html or Css. After a lengthy research I found that the problem was in the bootstrap.Css file. I am using the bootstrap version 5.1.3
Bootstrap classes container and container-fluid are using media rules(@media) and limiting the display area using max-width property. I simply commented the property and run the project then its working perfectly fine.
Adding the bootstrap css section below where I made changes.
I don't know what to do in the case of a cdn user and also I don't know is this a good practice. But its gives me exact output what I am expecting.
Appreciating the contributors who spend their time and effort to answer this question.
Thank you.
Since you are using bootstrap this snippet can’t run your code correctly (Next time tell in your question that you use bootstrap). But what i found out when u showed the code with the cards. You didn’t work in the section. if you want you image to be the background and work on that image. Then you have to work in the
div
or in this casesection
. Try the HTML code below that should work.