viewport height, whilst centralising the image within slider css - image

I have a slider on a homepage I am currently working on. I am trying to achieve a full viewport height that takes up the whole width for the screen.
The only way I can currently achieve this is by either stretching the image, or the image isn't centred.
The image needs to be aligned roughly centred horizontally and vertically, so customers can see the centre of the image on any width of browser, and without stretching the image out of proportion.
I have tried the background-size: cover; on the element with no success as its not a background img. the containers have 100vh currently, but the width is the issue.
The issue is located here http://joeybox.info/ . I realise with the menu and the logo above the image the 100 viewport height will rest under the "fold", however I am placing the logo and menu over the image eventually, once I have figured out the css.
I have tried many solutions found within the stack overflow forum and none work in my scenario.
My current css, after deleting the in-correct code, is:-
.bx-wrapper img {display: inherit;
height: 100vh;
max-width: inherit;}
.ewic-wid-imgs {height: 100vh;
max-width: unset;
width: unset;}
.bx-wrapper img {display: inherit;
height: 100vh;
max-width: inherit;}
html=
<div class="slider-box">
<div id="ewic-con-385">
<div style="display: none;" id="preloader-385" class="sliderpreloader">
</div>
<div style="max-width: 100%; margin: 0px auto;" class="bx-wrapper">
<div style="width: 100%; overflow: hidden; position: relative; height: 633px;" class="bx-viewport">
<ul style="width: 315%; position: relative; left: 0px;" class="bxslider-385">
<li style="float: left; list-style: outside none none; position: relative; width: 1349px; margin-right: 10px;" class="ewic-slider bx-clone">
<img title="Qw Direct Leather Keyrings" class="ewic-wid-imgs" src="http://joeybox.info/wp-content/uploads/2015/07/qw-direct-leather-keyrings.jpg">
<div class="ewic-caption"><span>Qw Direct Leather Keyrings</span></div>
</li><li style="float: left; list-style: outside none none; position: relative; width: 1349px; margin-right: 10px;" class="ewic-slider">
<img title="Qw Direct Leather Keyrings" class="ewic-wid-imgs" src="http://joeybox.info/wp-content/uploads/2015/07/qw-direct-leather-keyrings.jpg">
<div class="ewic-caption"><span>Qw Direct Leather Keyrings</span>
</div></li><li style="float: left; list-style: outside none none; position: relative; width: 1349px; margin-right: 10px;" class="ewic-slider bx-clone">
<img title="Qw Direct Leather Keyrings" class="ewic-wid-imgs" src="http://joeybox.info/wp-content/uploads/2015/07/qw-direct-leather-keyrings.jpg"><div class="ewic-caption">
<span>Qw Direct Leather Keyrings</span>
</div></li></ul></div>
<div class="bx-controls bx-has-controls-direction bx-has-controls-auto">
<div class="bx-controls-direction"><a class="bx-prev disabled" href="">Prev</a>
<a class="bx-next disabled" href="">Next</a></div><div class="bx-controls-auto"><div class="bx-controls-auto-item"><a class="bx-start active" href="">Start</a></div>
<div class="bx-controls-auto-item"><a class="bx-stop" href="">Stop</a></div></div></div></div><br>
</div>
</div>

To achieve this you could add to your image inside .bx-wraper:
.bx-wrapper img {
display: inherit;
position:absolute;
left:0;
right:0;
top:0;
bottom:0;
margin:auto;
max-width: inherit;
}
now you need to set the parent li to relative:
.bx-wrapper ul li {
position:relative;
width:100%;
height:100%;
list-style: none !important;
margin: 0 !important;
}
and change your parent ul:
.bx-wrapper ul{
width:100%;
}

I have solved the above by changing my image slider. My new slider plugin (Envoke Supersized) uses a background image and was easier to use background-size:cover; css. Although after this full viewport height on mobile widths didn't look good with my images so I used 40vh on mobile widths.
I would recommend anyone trying to do the same to ensure your image is a background image, or replace the slider with a static background image for small browser widths.

Related

Make responsive image

/How to set width and height of image to be 150px and to be responsive/
/HTML/
<div class="tabs__tab-image-container">
<img src="https://pbs.twimg.com/profile_images/1208234904405757953/mT0cFOVQ_400x400.jpg" class="tabs__tab-content-img">
</div>
/CSS/
.tabs__tab-image-container {
max-width: 150px;
min-height: 150px;
height: 100%;
width: 100%;
}
tabs__tab-content-img {
border-radius: 50%;
max-width: 150px;
height: auto;
display: block;
object-fit: cover;
}
You need to be clearer in your question. You want an image to ALWAYS be 150px square but the DIV to be responsive? Or do you want the IMAGE to be responsive within the DIV? As you're only showing a DIV with a single image in it, it's hard to tell what the goal is.
A responsive page is one that changes based on the viewport size; locking the image down to a fixed size kinda defeats the purpose in that case. Your CSS also isn't using the image class as it's incorrectly formatted.
The following fixes the image class as you've specified it, but all this does is round the image corners; the content won't be responsive:
CSS:
.tabs__tab-image-container {
max-width: 150px;
min-height: 150px;
height: 100%;
width: 100%;
}
.tabs__tab-content img {
border-radius: 50%;
max-width: 150px;
height: auto;
display: block;
object-fit: cover;
}
HTML:
<div class="tabs__tab-image-container">
<div class="tabs__tab-content"><img src="https://pbs.twimg.com/profile_images/1208234904405757953/mT0cFOVQ_400x400.jpg">
</div>
</div>
To make the page responsive, you can add viewports in CSS for different page sizes, or if it's just the image displaying (with a line of text in the div for example) use the following:
CSS:
.tabs__tab-image-container {
text-align:center;
font-family: "Comic Sans MS", cursive;
font-size: 10.0vw;
font-weight:700;
}
.tabs__tab-content img {
border-radius: 50%;
width: 100%;
}
HTML:
<div class="tabs__tab-image-container">
<div class="tabs__tab-content"><img src="https://pbs.twimg.com/profile_images/1208234904405757953/mT0cFOVQ_400x400.jpg">
Text Here
</div>
</div>
If you only need the image, you don't even need the tabs__tab-image-container class, just use the tab content class targeting the image.

Another stacking centered images question

I have an image of TV set and I want to place images of "shows" in it, centered horizontally on the screen (in front of the tv screen image). I'm using a to set the dimensions of the area in which to place the images, but I don't have to if it's not necessary. I've fiddled with position:absolute/relative of the and the images, but I can't get both images to be centered and stacked - either they partly overlap when centered or they align perfectly at the edge of the "". Here's the current iteration of the code. Any advice would be appreciated.
<div id="sourceDiv" align="center">
<img class="test" src="uvaCover.jpg" style="z-index:2; width:800px">
<img class="test" src = "tvScreen.jpg" style="z-index:1; width:900px">
</div>
.test {
position: absolute;
display: block;
margin:auto;
height:auto;
overflow: hidden;
}
#sourceDiv {
position:relative;
background-color: red;
top:170px;
left: 20px;
width:1000px;
height: 800px;
margin:auto;
}
I found the answer. For the ":
display: flex;
align-items: center;
justify-content: center;

Align image center in floated div

I have a loop to loaded logo image in floated div block, I been tried few tips from stackoverflow but have no luck to make the logo align center and middle within the div, all logo height are not fixed and might have different height for each:
<div style="float:left; width:80px; height:80px; padding:8px; border:1px solid #ccc;">
<img width="78px" align="left" src="images/logo/logo1.jpg">
</div>
Please help, thanks.
Use positioning. The following worked for me...
With zoom to the center of the image (image fills the div):
div{
float:left;
display:block;
overflow:hidden;
width: 70px;
height: 70px;
position: relative;
}
div img{
min-width: 70px;
min-height: 70px;
max-width: 250%;
max-height: 250%;
top: -50%;
left: -50%;
bottom: -50%;
right: -50%;
position: absolute;
}
Without zoom to the center of the image (image does not fill the div):
div{
float:left;
display:block;
overflow:hidden;
width: 100px;
height: 100px;
position: relative;
}
div img{
width: 70px;
height: 70px;
top: 50%;
left: 50%;
bottom: 50%;
right: 50%;
position: absolute;
}
You really should move your CSS out of the style attribute and into a file like style.css if you have not done so. But if you really have to you can place the code below into inline styles like you have now.
Remove the align="left" attribute from your image tag and set the image's display to block. This will allow margin: 0 auto; to center your image for you inside the containing DIV.
Looks like you'll have to replicate a <table> with CSS to get the vertical centering you desire. Table cells allow vertical centering. To do this I've added and additional DIV with a class of .container. The .container DIV has it's display set to table and the .image-container DIV, which is acting like a table cell, has it's display set to table-cell.
CSS
.container {
float: left;
width: 80px;
height: 80px;
padding: 8px;
border: 1px solid #ccc;
display: table;
}
.image-container {
display: table-cell;
vertical-align: middle;
}
.image-container img {
display: block;
margin: 0 auto;
}
HTML
<div class="container">
<div class="image-container">
<img src="images/logo/logo1.jpg">
</div>
</div>
JSFiddle: http://jsfiddle.net/MJ5j4/
just create a class "centerImgWrapper", and wrap all your "center" Images anywhere in the Code with divs.
Thats pure CSS
.centerImgWrapper {
width: 100%;
height: 100%;
position: relative;
overflow: hidden;}
.centerImgWrapper img {
left: 0;
right:0;
top: 0;
bottom:0;
max-height: 100%;
max-width: 100%;
margin:auto;
position:absolute;
}
Just Check out the Fiddle.
MyFiddle
Dave
If you are trying to get it in the middle inside the div, have you tried:
<div style="width:800px; height:800px; padding:8px; border:1px solid #ccc;">
<img width="78px" src="mobiIconGreenGray.gif" style="margin-left:50%; margin-top:50%;">
</div>
I used "margin-left:50%; margin-top:50%;" INSIDE the IMG tag and got rid of the "align" and "float" attribute. I probably wouldn't want to use "align" in this case.
Either way, I hope it helps.
Images are more or less displayed as inline-blocks. So you can just set text-align: center; on the styles of the container div.
Getting something to be vertically aligned in the middle is complicated with css. If you're going to be dynamically placing the logo with JavaScript anyway, you can save yourself trouble and just center it vertically by specifying the margins with JavaScript.
Check out this demo: http://jsfiddle.net/jyvFN/1/
HTML
<div id="container">
<img id="logo" src="http://placekitten.com/100/100" />
</div>
CSS:
#container {
float: left;
background-color: blue;
width: 200px;
height: 150px;
text-align: center;
border: 1px solid red;
}
JavaScript
var logo = document.getElementById('logo');
var container = document.getElementById('container');
var margin = (container.clientHeight - logo.clientHeight) / 2;
logo.style.marginTop = margin + "px";
logo.style.marginBottom = margin + "px";
Why didn't you set align of the image center?
Then your code should be:
<div style="float:left; width:80px; height:80px; padding:8px; border:1px solid #ccc;">
<img width="78px" align="center" src="images/logo/logo1.jpg">
And I think it's also problem of the ratio of the image width vs the div block + it's padding and border.
Try to set it balance.

How do I ensure that an image is fluid and will resize?

I am trying to use CSS to ensure an image on my page will resize if the screen is below a certain resolution or the window below a certain size. I have read to use {max-width:100%}, which I have incorporated into my code, but the image isn't resizing at all. The image is 500px wide.
Thank you!
CSS and HTML:
.left{
float:left;
width:600px;
}
.right{
float:right;
width:400px;
}
#logoimage{
width: 100%;
margin: 50px auto;
max-width: 100%;
}
#navbar{
text-align: center;
font-family: 'Special Elite', cursive;
color:white;
font-size: 80px;
font-style: bold;
display: block;
margin: 60px auto;
}
<body>
<div class="left">
<div id="logo">
<img src="/pictures/logo.png">
</div>
</div>
Your CSS for ID logoimage is not being applied to anything. You have an img element, but it has no ID specified. Change <img src="/pictures/logo.png"> to <img id="logoimage" src="/pictures/logo.png" /> for it to take effect.
Also, there's no point setting width to 100% AND max-width to 100%. It's redundant. Either set width to 100% to ensure the element is 100% width, or set max-width to 100% ensuring the element will auto-width up to a maximum of 100%.

css background-image not displaying

I have the following code on home page:
<ul id="slides1">
<li>
<!-- About-->
<div class="logo"></div>
<div class="sub1"> </div>
<img src="images/nadpisi/about.png" class="nadpis1">
<img id="i1" src="images/MiddleBg/first.jpg"/>
</li>
</ul>
Here I have logo in class=logo and div class sub1 has background image in css file:
.sub1{
background-image: url(../images/sub1/about.png);
width: 600px;
height: 100px;
position: absolute;
z-index: 7;
top: 270px;
margin-left: 490px;
background-repeat: no-repeat;
}
.logo {
background-image: url(../images/LOGO.png);
width: 229px;
height: 129px;
background-repeat: no-repeat;
position: absolute;
z-index: 10;
top: 80px;
margin-left: 490px;
}
When I open the page with Chrome, both these logo and sub1 background images are not displayed but image after them does display, but when I go to browser`s address bar and press Enter they display. What is the problem, can anyone help?
Your images are probably not being found. Most likly a problem with your paths. Check if the image loads in a developer console.

Resources