Set minimal width of a image which may not overflow - html

I am working on a webpage which contains an header logo. This logo has two logo's in it: one with a transparent background and one with a orange background on the right. The image is like 3.000 pixels wide. I want to resize the image to let both logo's fit in the div horizontally. So that on every device I will see the logo's and a part of the orange background (what makes the image that long.
HTML
<div class="logo-header"><img src="logo.png"></div>
CSS
.logo-header {
overflow: hidden;
}
It indeed overflows nicely as I would want it, but when I use an iPhone 4 or some other small screen I am failing to get it have a minimal width.
Is this possible in CSS or is this something I should do with Javascript?

.logo-header {
background-image: url("http://bighugelabs.com/img/nbcam/ribbon_3000_bg_sh.png");
background-size: contain;
background-repeat: no-repeat;
height: 20vh;
width: auto;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<div class="logo-header"> </div>
</body>
</html>
if you check this image it's 3000px wide.
First of all, i recommend you optimise your image (try tinypng.com) and resize it using paint or some such (rezize before you optimize).
then use background cover and set it as a background image

Maybe you can try to split your image in two images.
With CSS, you then insert the second image (with orange background) as background-image of .logo-header, aligned to the right.

Related

Problem with CSS program which is not passing test case can anyone help me with it

I am getting an error at the background-repeat attribute in actual the image has to change whenever the mouse pointer hovers over the image but it is showing the test case is failed.
Tried to change it with background: "imgfile.jpg" no-repeat; but still same error is recurring. Help me with this. Thank you.
Here is the description about the code
Create a page that will display an image changing effect on mouse over in a file named imgeffect.html.
Initially the page would get displayed as below with only an image of apple (apple.jpg : with no-repeat attribute set to it in the same line )
apple
When we mouse over this image a transition effect on the image needs to happen, changing the image from apple to mango (mango.jpg : with no-repeat attribute set to it in the same line )
The page then should display :
mango
Create a webpage using the fields below:
A tag, with "step1" as class.
The width and height are 250px and 300px respectively.
Initially it must be appear with the image "apple" with 100px margin.
For the transisition, change the CSS3 properites of the div tag named as "step1" to
Width as 350px, height as 300px and change the image from apple to mango with the same margin value.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Change Image on Hover in CSS</title>
<style type="text/css">
.step1
{
width: 250px;
height: 300px;
background-image: "apple.jpg";
background-repeat: no-repeat;
margin:100px;
}
.step1:Hover
{
width:350px;
height:300px;
background-image: "mango.jpg";
background-repeat: no-repeat;
}
</style>
</head>
<body>
<div class="step1"></div>
</body>
</html>
testcase-failed-image
A simple change can help
simply change your code from
background-image: "apple.jpg";
to
background-image: url("apple.jpg");
correct it to mango.jpg too.
As an easier format you can also put it in this way:
background: url("mango.jpg") no-repeat;
in this way you can put all the background properties in single line.

how to insert a full screen large background image in html,css?

The full image is not displayed properly, the bottom of the image is missing, how can I display the full image on screen? (dimensions: 5904 * 4000 px)
I tried with object fit but its not working:
* {
margin: 0;
padding: 0;
}
header {
width: 100%;
height: 100vh;
background: url("adult-blur.jpg") center center no-repeat;
background-size: cover;
overflow: hidden;
object-fit: cover;
object-position: bottom top;
}
I also shared a video of this problem in facebook: here
You cannot have both:
The image show fully
Have the image cover the entire background
Remember that the image is of a fixed ratio and most screens will have a different ratio than your image not to mention differences in the actual viewable area (viewport) because of the browser toolbars and OS toolbars.
Your options are:
Have the image always be full-width using width:100%. This risks having a part of the image cut off at that bottom if it is taller than the viewport or having some white-space at the bottom if the image is shorter than the viewport.
Have the image always be full-height using height: 100%. This risks having a part of the image cut off at the right side if it wider than the viewport or some whitespace if it is not as wide as the viewport.
Use backgorund-repeat to have the image repeated vertically or horizontally to cover any whitespace.
Most other options you can find in CSS do a combination of the above options, with some additions like centering the image where there is white-space.
Most designers select the images with this in mind, choosing images that don't have any important details near the edges, and thus still look good if a small section is cut off at any end.
Check out this code:
<html>
<head>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"></script>
<style>
#body-container {
width: 100%;
height: 100vh;
background: url("j.jpg") center center no-repeat;
background-size: cover;
overflow-y: scroll;
}
</style>
</head>
<body>
<div id="body-container">
<!-- Place your document contents here -->
</div>
<body>
</html>
Here we used bootstrap-4. Put all contents of document body inside div container. In styles, background-size is used to make our image 100% in width n height. If it image stretches absurdly, you can also try background-size: cover.
Finally, overflow-y property is used to make our div scrolls vertically

CSS background image that can scroll

I am trying to create a background image that will have a scroll bar to scroll the image down vertically. I like the idea of using width and height percentages because it seems like this method always fits the image to any screen resolution. Unfortunately, the length of the image is rather large and therefore the bottom of the image gets cut off. I have tried various ways to get this working including changing the background-size properties, using overflow-y:scroll and other edits that are not worth mentioning. Here is the code I am working on thus far:
HTML
<!doctype html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/style.css">
<meta charset="UTF-8">
</head>
<body>
<div class='image'></div>
</body>
</html>
CSS
#charset "UTF-8";
/* CSS Document */
body {
margin:0;
}
.image {
position:absolute;
width:100%;
height:100%;
background:black;
background-image:url(../pictures/testjpg);
background-size:cover;
overflow-y: scroll;
}
UPDATE: without height you can't scroll the image top to bottom. but you cant fit this any screen.
body,html {
margin: 0;
}
.image {
background-image: url("http://www.w3schools.com/howto/img_parallax.jpg");
background-position:center;
background-size: 100% 100%;
height:300vh;
}
<body>
<div class="image">
</div>
</body>
A scroll bar moves the viewport so that you can see what's not on the screen. At the above code, if you make your image to expand&contract by giving it relative height (%100 height&width of the screen), there will never be a 'scroll-able' vertical scroll bar because there's nothing to scroll to. It never 'overflows'.
To actually have scroll-able images, you need to give it a width - or in this case- height larger than your viewport.

Full page div, fit image to smaller dimension (preserve aspect ratio)?

I've been reading quite a bit of answers on this, but simply cannot get it to work. I thought I'd provide a full example, and hopefully I'll get an answer that works for me.
I have this image, bckg.png, size 1200x1920, created with Imagemagick convert -size 1200x1920 gradient:tomato-steelblue -distort SRT 60 bckg.png (click for full size):
I want this displayed in the center of the browser window, such that it is scaled according to the smaller dimension of the browser window, so the aspect ratio is preserved.
For instance, if the available browser window page area is 887x487, the smaller dimension is the height -- so I'd like the image height scaled to 487px, and preserving aspect ratio, its width would then be 487*(1200/1920) ≈ 305 px
So, I'm trying the following code, temp.htm:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
html,body { height:100%; }
/* convert -size 1200x1920 gradient:tomato-steelblue -distort SRT 60 bckg.png */
#background {
background: url(bckg.png) no-repeat center center fixed;
background-size: cover;
height:100%;
}
</style>
</head>
<body>
<div id="background">
</div>
</body>
</html>
In Firefox 42, this renders as:
However, what I would have wanted instead, should approximately look like this (I montaged this in an image editor):
... and basically, regardless of how I resize the browser window, the entire image should be shown inside it, centered.
How can I do this with HTML/CSS? (pre-css3 answers are appreciated as well)
Just switch the background-size to contain instead of cover JS Fiddle
#background {
background-size: contain;
** Note that if you want to get rid of the few white pixel margin around on your page top, right, bottom and left sides add this to your body css:
padding:0;
margin:0;
I'd rater prefer this one:
html, body {
height:100%;
padding:0;
margin:0;
}
#background {
background: url('http://i.stack.imgur.com/8H1yb.png') no-repeat center center;
background-size: auto 100%;
height:100%;
}
in order to obtain a larger compatibility width IE (i didn't test on older version but it should be 7+, maybe 6+)
http://jsfiddle.net/sqdkyaot/4/

background image with scrollbars

i got a little newbie question:
I need to put an image to be a background image of a site. and it needs to show the whole image. The user need to have the option to scroll down.
This is what i wrote and it does show the scroll bars but it doesn't scroll.
The image is very big.
<html>
<head>
<title>Title</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<style>
body {
background-image: url("OPL2013.gif"); /* Change Image URL */
background-repeat: no-repeat; /* Keep it */
background-position: 50% 0; /* position to center */
background-attachment: fixed; /* For Scrolling bars */
height: 100%;
min-height:100%;
}
</style>
</head>
<body dir="rtl" align="center">
</body>
</html>
**The image is 970X1200 Pixels
By setting background image, you are simply applying an image to the visible area as determined by the element it is applied to.
As such, you will likely want to add the image as an img element into your body, or explicitly set the dimensions of the body itself to those of the image.
The reason scrollbars arent being shown is that they are dictated by the overflow of an element, which is determined by its content. The background property does not represent content propagated to the element, as such- it cannot influence overflow and thereby cause scrollbars to appear. This is why you will need to either change the dimensions of the element to create overflow on its parent, or apply the image as the src of an img to do the same.