I meet a tricky problem.
I need to center horizontal and vertical images after scaling images.
Here is my HTML:
li {
float: left;
padding: .78125%;
width: 31.25%;
/*li tag height and width is not fixed for screen adaptation*/
}
<!-- The code run in mobile browser.So do not think too much fu*king compatibility-->
<ul>
<li>
<a href="link">
<img class="lazy" src="" data-original="">
</a>
</li>
<li>
<a href="link">
<img class="lazy" src="" data-original="">
</a>
</li>
<li>
<a href="link">
<img class="lazy" src="" data-original="">
</a>
</li>
</ul>
The problem is, images size is not fixed and them will scale with their original ratio.And after scaling, I need to center horizontal and vertical images.
I can center horizontal and vertical images without scaling. But I can't handle it if it need to scale.
(ps: Forgive my poor English. Can you understand my problem?)
You could take advantage of CSS to do this for you. Simply attach your background-image to a div like so:
<div class="resize-me" style=" background-image: url('http://dynamically/generated/url/here'); "></div>
Then in your css do this:
.resize-me {
background-size: cover;
width: 200px;
height: 200px;
}
That way, the url you attach can be any size, and CSS will scale up or down the image to be the width and height of the resize-me class. It should also center the image properly every time.
Essentially, when you use cover, CSS will determine the best fit for the image to completely cover the background of the div. So if you want to resize the div, you wont have to do any manual scaling of your images. This is essentially the same trick that developers used to use with standard images where you would use a clipping mask div over a block-level image. The difference is that it does the centering automatically, and you only need to create one DOM element.
Related
I have a banner which contains a background image that I want to be responsive and appear the same on any device, that's why I have made background-size = 100% , but the problem is that a blank space at the top and the bottom of the background image appears that I want to remove, but without success. I have tried a lot of propositions in some other questions in relation with that, but It is not working. I am a beginner in CSS, can someone help me to find the perfect solution for a problem like that?
Bellow, you will find the code of my banner and 2 pictures explaining what I have got.
This is the banner's html code:
<div class="bannercontainer">
<div class="banner" data-fullscreen="on" data-auto="true" data-hidetimerbar="off" data-fullscreenoffsetcontainer=".header">
<ul>
<li data-transition="fade" data-slotamount="7" data-saveperformance="on" class="background" style="background-image: url(images/slider/test.png); background-size: 100%">
<div class="tp-caption sft large_bold_white" data-x="left" data-y="center" data-hoffset="500" data-voffset="-85" data-speed="700" data-start="700" data-easing="easeOutBack">Welcome</div>
<p class="tp-caption fade" data-x="left" data-y="center" data-hoffset="500" data-speed="500" data-start="900" data-easing="easeOutBack"></p>
Read More
</li>
</ul>
</div>
</div>
The first picture show the background image that fits perfectly
https://imgur.com/a/Koqvh0t
But in mobile device, I only want to remove the blank space
https://imgur.com/a/THMHj0P and keep the background image like that.
Thank you so much for your help.
what if you just set the height to 100% instead of the entire image:
height: 100%;
or you could just set the background to red so it doesn't look like blank space:
background-color: red;
Try the following CSS:
.bannercontainer .background{
background-size: cover;
}
This makes image fill in any empty spaces and trim the image when necessary.
Edit: Actually it looks like you're already using it. By the images it looks like your sizing of child elements e.g. .banner, <ul> or <li> is not 100% height. Use F12 to inspect elements. Hover over the elements to see their sizes on the page. The one that wraps only around the image probably needs to be set to position: absolute; height: 100%; width: 100%; margin:0; padding: 0;
So what I'm trying to achieve is the following style
Essentially it's three different photos
Big picture on the left as well as two rectangle pictures on the right.
The problem I'm having is i need these to fill 100 view port when you visit so I put
.intro-deals{
height: calc(100vh - 182px);
overflow: hidden;
}
which does fill the pages view port but the images will get cut off. and look like the following:
You can see how the image will get cutoff at the bottom, What would be the best way to approach this?
Here is the main part of my code as well
<div className="intro-deals">
<div className="col-md-6 no-pad">
<img className="img-responsive" src={require('../images/home/header/Home_bannerMain.jpg')} alt=""/>
</div>
<div className="col-md-6 no-pad">
<img className="img-responsive" src={require('../images/home/header/Home_bannerSide1.jpg')} alt=""/>
<img className="img-responsive" src={require('../images/home/header/Home_bannerSide2.jpg')} alt=""/>
</div>
</div>
css
.intro-deals{
height: calc(100vh - 182px);
overflow: hidden;
}
Edit
Also a simplified Codepen (You will have to view in full-screen mode)
Looking at the picture (before seeing the code), the best shot I thought to achieve this was:
Setting up height/width of all boxes according to viewport
Using images as backgrounds for divs, with background-size: cover, and background-position: center center.
That's it
I've been trying to make a group of images-list page using bootstrap but I can't make it responsive on other resolutions, The images moves left and the entire style of the arrangement will break.
<div class="fluid-container">
<div>
<img class="img-responsive" src="source-path">
</div>
<div>
<img class="img-responsive" src="source-path">
</div>
<div>
<img class="img-responsive" src="source-path">
</div>
<div>
<img class="img-responsive" src="source-path">
</div>
<div>
in this one ^ The images appears in 1-row and not sided to each other, And when I use style="float: left;" it works but not responsive as I wished, Is there a better way to make a better album{images-list} using bootstrap?
Your images are responsive.
In the sense that they do scale down depending on parent size.
Here is how .img-responsive is defined in Bootstrap 3:
display: block;
max-width: 100%;
height: auto;
Please note, as Sreemat well pointed out, you do not need to wrap the images in <div>s since they already have display:block.
The problem is most people, when they say responsive they also expect it to grow in size according to the parent's width, which .img-responsive does not do, as doing that has the potential of making small images look really bad.
But if that's your desired behavior, add this to your CSS:
.img-responsive {
min-width: 100%:
}
I have an HTML Document and a CSS Document and I'm trying to remove a large margin in between the image I've placed and the text below it. When I adjust the pixel margin on the top of the image it adjusts, but I've tried a few things on the bottom of the image and just can't seem to get it to work right. There is a huge gap and I just want it to look "normal". That is, having a smaller margin between the img and the text below it.
<div id="header" class="container">
<!--Home Logo -->
<a href="#">
<img src="http://www.satckoverflow.com/wp-content/uploads/2015/02/Stack-Overflow-Logo.png" style="position: relative; top: -150px;" alt="Platinum Imprints">
</a>
<p>Welcome! Here at Platinum Imprints we specialize in Custom Screen Printing. Use anywhere from one to many colors on a simple shirt.</p>
This is what I have for HTML.
You have inline styles on the img element that are setting relative positioning. Removing this will fix your problem.
Remove the inline style position: relative; top: -150px; in the img tag to remove the spacing.
I received HTML & CSS layout that should be working fine. However, I'm experiencing some strange problems for which I'm not sure why do they occur.
At the bottom of the following this website there is slider that should display couple of photos with text and by clicking on arrows it should slide them. The problem is I can't position neither arrows, nor wrapper containing images.
As you can see arrows(CSS classes: .strelica-lijevo and .strelica-desno are currently behind the image wrapper (CSS class: .slike-wrapper) when they should be left (.strelica-lijevo) or right (.strelica-desno).
Code can be seen directly on the website. Any help would be appreciated.
There are some issues with the HTML and CSS - you should either try to contact whoever delivered this slider to get support for implementing it or you could try by yourself as follows (just checked the markup and CSS and maybe this helps):
Your current HTML:
<div class="w-clearfix main-content karta">
<div class="slike-wrapper">
<a class="w-inline-block featured-male-slike karta" href="/zagreb/category/to-see/2/zagreb-is-the-capital-and-the-largest-city-of-croatia/5">
<img class="featured-male-slike" src='/Content/610ddd4a-b9a7-45f8-ac56-66eec5968329.jpg' />
<div class="potpis-mala-slika-featured">
<div class="potpis-ispod-slike">Zagreb is the capital and the largest city of Croatia</div>
</div>
</a>
<a class="w-inline-block featured-male-slike karta" href="/zagreb/category/to-see/2/museum-of-broken-relationships/8">
<img class="featured-male-slike" src='/Content/3a6ee262-676f-4599-9f97-6b9c48136449.jpg' />
<div class="potpis-mala-slika-featured">
<div class="potpis-ispod-slike">Museum of Broken Relationships</div>
</div>
</a>
</div>
<div class="strelica-lijevo"> <img src='/Content/strelica-lijevo.svg' /> </div>
<div class="strelica-desno"> <img src='/Content/strelica-desno.svg' /> </div>
</div>
could be changed into:
<div class="w-clearfix main-content karta">
<div class="strelica-lijevo"> <img src='/Content/strelica-lijevo.svg' /> </div>
<div class="slike-wrapper">
<a class="w-inline-block featured-male-slike karta" href="/zagreb/category/to-see/2/zagreb-is-the-capital-and-the-largest-city-of-croatia/5">
<img class="featured-male-slike" src='/Content/610ddd4a-b9a7-45f8-ac56-66eec5968329.jpg' />
<div class="potpis-mala-slika-featured">
<div class="potpis-ispod-slike">Zagreb is the capital and the largest city of Croatia</div>
</div>
</a>
<a class="w-inline-block featured-male-slike karta" href="/zagreb/category/to-see/2/museum-of-broken-relationships/8">
<img class="featured-male-slike" src='/Content/3a6ee262-676f-4599-9f97-6b9c48136449.jpg' />
<div class="potpis-mala-slika-featured">
<div class="potpis-ispod-slike">Museum of Broken Relationships</div>
</div>
</a>
</div>
<div class="strelica-desno"> <img src='/Content/strelica-desno.svg' /> </div>
</div>
This would just change the order of the elements - 1st the left arrow, than the gallery, than the right arrow - so they're displayed next to each other. Guess this could be changed in another way, but this is the easiest approach withouth having to change too much in the CSS.
In the CSS
.featured-male-slike.karta
{
clear: right;
display: inline;
float: left;
margin-top: 30px;
overflow: hidden;
/* position: absolute; */ /* <--comment position abolute out */
}
comment "position: absolute;" out - you could also remove it, but it's better to keep it just so you can check with whomever created this slider for you, maybe there's some other way to fix the slider as you mentioned it should be working as it is. Because of this position:absolute the gallery would still be displayed above the left arrow, removing it has the purpose to keep the CSS-property float:left for all three elements - left arrow, gallery, right arrow, so they will be displayed next to each other.
Next is up to you - the images are displayed not positioned correctly because they have a different height, and the css for the img is height: auto, meaning that the height for each img depends on the actual calculated height (as both images are scaled down from bigger original images). You could either try to display images with the same size, or you can add css to set a fixed height for both images, e.g.
.slike-wrapper img
{
height:140px;
}
as the left image has a calculated height of 158px and the right image has 140px. As I only tested this directly in the browser's web developer tools, I can't guarantee that this approach would work for you, but you can give it a try.