How can I properly make my hero image/banner image responsive? - html

Currently trying to add an image to my section-'header'. Soon we have to make the site responsive, and I am currently struggling with getting the full picture to resize, when resizing the browser-window
when I use background-size: cover;, resizing will cut off a lot of the image. When using background-size: 100%;, it will leave a massive "chin", which just adds up empty-space under the page's buttons which is nothing more than just the background-color + it will get somewhat squeezed into the header (the header is fixed).
Do not mind the header-content itself. making that responsive will be done in the future
Is there a way I can combat this?
CSS
hero-image {
background-image: url(/img/header-background.jpeg);
background-size: cover;
background-repeat: no-repeat;
overflow:hidden;
width: 100%;
}
#page-header {
height: 100vh;
background-color: #1c1b39;
color: #ffffff;
}
#page-header h1 {
padding-top: 15%;
font-size: 3em;
letter-spacing: 0.1em;
text-transform: uppercase;
}
#page-header p {
padding-top: 1%;
font-size: 1.5em;
max-width: 780px;
margin: 0 auto;
opacity: 0.5;
}
button {
margin-top: 5%;
border-radius: 30px;
width: 300px;
height: 60px;
text-transform: uppercase;
font-size: 1.5em;
}
#button-reserve, #button-trailer:hover {
background-color: #ff4242;
}
#button-reserve:hover, #button-trailer{
background-color: inherit;
border: 5px solid #ff4242;
color: #ff4242;
}
#button-reserve:hover, #button-trailer:hover{
transition: 0.5s;
}
#button-reserve {
color: #ffffff;
border-style: none;
}
#button-trailer:hover {
color: #ffffff;
}
html
<section id="page-header" class="hero-image">
<h1>Buitenaards leuk: Coderen!</h1>
<p>Op een leuke en speelse manier de vaardigheden van de toekomst ontdekken. Ideaal voor het basisonderwijs</p>
<button id="button-reserve">Reserveer workshop</button>
<button id="button-trailer">Bekijk trailer</button>
</section>

Just quickly looking at this, have you considered using background-size: contain; rather than cover?
It will allow the background to be responsive but does have limitations.

Using background-size: cover; will resize the background image to make sure the element is fully covered. Stretching it to fit top-to-bottom. Depending on the image dimensions, this may display only a part of the image, and not all of it.
But using background-size: contain; resizes the background image to make sure it remains fully visible.
So the code below will make your image responsive, but it will not cover the full height of the viewport.
.hero-image {
background-image: url(/img/header-background.jpeg);
background-size: contain;
background-repeat: no-repeat;
overflow:hidden;
max-width: 100%;
}
But you can set the background-color the same as the image's background if you do not wish to use background-repeat: repeat-y;
EDIT: Don't for get to correct hero-image to .hero-image in your CSS.

Related

Can't replace image on hover

This never happened to me before, and i can't figure our why the hover happens, but the back image won't change :
<div class="settings" id="settings" style="background-image:url(assets/settings.svg);"></div>
.settings{
width: 2.0vw;
height: 2.0vw;
margin-top: calc((8vh - 2vw)/2);
margin-left: 1.5vw;
float: left;
background-position: center;
background-size: contain;
}
.settings:hover{
background-image: url("assets/settingsH.svg");
}
To prove that the image is there, if i set assets/settingsH.svg in the html - it will show the hover image.
If i change size on hover, it will also work (hover is happening) but back image won't change no matter what.
No other hidden settings class was found.
That's because you put the background image inline with html, so if you want to replace it via css, you must put an !important:
.settings:hover{
background-image: url("assets/settingsH.svg")!important;
}
or bettter, put the background in css:
.settings {
width: 2.0vw;
height: 2.0vw;
margin-top: calc((8vh - 2vw) / 2);
margin-left: 1.5vw;
float: left;
background-position: center;
background-size: contain;
background-image: url("https://via.placeholder.com/400/0000FF");
}
.settings:hover {
background-image: url("https://via.placeholder.com/400/FF0000");
}
<div class="settings" id="settings"></div>

background images specified in css not rendering

I have a PHPBB theme I am starting to construct. In the CSS file, I have three items--a body and two divs--with background images. The background images for the divs have ceased working in all browsers.
The site with the theme presented is here: https://www.tarazedi.com/index.php?style=7
The problem images are here: https://www.tarazedi.com/styles/wTcFresh/theme/images/site_banner.png
The CSS is located in wTcFresh/theme/.
The images are all in the same locations but there seems to be a pathing issue but is working very strangely. I have tried using both relative and absolute URLs. I have tried url(x);, url('x');, and url("x"); and also changing the other background elements. In no case have the banner and logo images started working, but the body image works fine despite being in the same place and using the same syntax. When I inspect the computed styles of the divs in Chrome the image will show as the full absolute URL correctly but the relative link links instead to tarazedi.com/images/site_banner.png which returns a 500 error because that URL is, obviously, useless. In Edge and Firefox the inspector shows the correct link to the image but still does not render.
I have cleared browser and site-side caches with each attempt I make to fix it.
I am baffled. What am I missing?
body {
color: #CCCCCC;
background-color: #000000;
background-image: url("images/bg.jpg");
background-attachment: fixed;
}
.headerbanner {
border: #009900 solid 4px;
border-radius: 40px;
background-image: url("images/site_banner.png");
background-attachment: fixed;
background-position: right;
background-repeat: no-repeat;
margin-left: auto;
margin-right: auto;
vertical-align: middle;
}
.headerlogo {
border: #003300 solid 4px;
border-radius: 36px;
overflow: hidden;
background-repeat: no-repeat;
background-image: url("images/site_logo.png");
background-attachment: fixed;
background-position: left center;
vertical-align: middle;
}
To achieve expected result,adjust background-position and it is not issue with the background-image
1.Remove background:position to see the difference
Editing it thusly fixed the problem and it now renders correctly. Thank you very much!
.headerbanner {
border: #009900 solid 4px;
border-radius: 40px;
background-image: url("images/site_banner.png");
background-position: right;
background-repeat: no-repeat;
margin-left: auto;
margin-right: auto;
align-items: center;
}
.headerlogo {
border: #003300 solid 4px;
border-radius: 36px;
background-image: url("images/site_logo.png");
overflow: hidden;
background-repeat: no-repeat;
background-position: left;
align-items: center;
}

Is there a way to make my image equal the size of the navigation bar?

Is there a way that I can make the width of my navigation bar the same width as the image. The problem is I'm working with an image that has an original size of 497 x 298px but to make the image stretch the full width of the page whilst still having margins of 10px on either side I had to set width: 98.4%.
Also, for some reason when I set the ul to width 100% the navigation is way too long and only fits within a normal desktop screen if I make it 50%. So at the moment they are both the same length, but when I resize the page they start to go out of sync with only the ul element following the rules I've set.
ul {
display: block;
max-width: 100%;
list-style-type: none;
margin: 10px 10px 0 10px;
padding-left: 32%;
padding-right: 25%;
text-align: center;
overflow: hidden;
background-color: #F25f70;
font-family: "Oswald", sans-serif;
border-bottom: 2px solid rgba(0, 0, 0, 0.15)
}
img {
width: 98.4%;
height: 500px;
margin-left: 10px;
margin-right: 10px;
object-fit: cover;
}
You should just wrap your navigation in a <div>. Give it 100% width. Then assign a background-image to your <ul> and make that 98% width. including these background properties
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
I created a DEMO HERE
woohooo moving to Cali in a week!!! So I made it Cali themed.
Note: The Image I used is the same dimensions specified in your post.
Also you may wana check out the background-size properties at w3schools

Background image over background image

I am trying to a background image over background image but it hides the first one image . My code is as follows
<li class="collapsed">
<a>Getting Started</a>
</li>
.collapsed {
background-image: url(../images/expand_new1.png)!important;
background-repeat: no-repeat;
background-position: 141px 5px;
background-size: 35px;
-moz-background-size: 30%;
-webkit-background-size: 30%;
z-index:50;
li.collapsed a{
opacity: 0.8;
background-image: url(../images/assets/faq/faq_list_bg.png);
display:block;
padding-left:27%;
font-family: 'Roboto';
font-size: 20px;
font-weight: 300;
color: #fff;
z-index:-1;
I want to display expand_new1.png display top of faq_list_bg.png
please help to resolve this issue.
expand_new1.png image is white and faq_list_bg.png image is blue . it totally hide the first image.
[![When i replace the plus icon with white color plus icon then image disappears][1]][1]
Remove
background-image: url(../images/assets/faq/faq_list_bg.png);
EDIT BASED ON NEW INFO:
li.collapsed a:after {
background-image: url('../images/expand_new1.png');
background-size: 20px 20px;
display: inline-block;
width: 20px;
height: 20px;
content: "";
}
http://puu.sh/pBTSS/ffc491e491.png
If you want to change the + to a - or nothing all together once expanded:
li.collapsed.expanded a:after {
background-image: url('NEW IMAGE LINK HERE');
background-size: 20px 20px;
display: inline-block;
width: 20px;
height: 20px;
content: "";
}
It hides the first image because you used the z-index property but didn't set the position value.
z-index is not working because it will only work on an element whose position property has been explicitly set to absolute, fixed, or relative.
In your case, set position for both to absolute.

Force div's background-image fetch it's size

I've got a div which absolutely needs an auto width that depends on text length inside it. I want a blue halo showing off as background image of that button when I hover it with my mouse.
But here's the challenge I can't solve: I want that blue halo png image to fetch the exact width of the div, I want a real distortion of the halo image without respecting any proportion.
How can I accomplish this without giving an absolute value for the width of the div? And without using anything more than HTML and CSS3?
HTML side:
<div class="button">
<p>Hover here!</p>
</div>
CSS side:
.button {
width: auto;
height: 80px;
line-height: 81px;
font-family: sans-serif;
display: inline-block;
}
.button:hover {
background: url("http://img15.hostingpics.net/pics/300291bluehalo.png") center bottom no-repeat;
}
JSFiddle: https://jsfiddle.net/ynwsmkrz/5/
Everything you have to do is add a background-size: cover; to the .button:hover like this:
CSS:
.button {
width: auto;
height: 80px;
line-height: 81px;
font-family: sans-serif;
display: inline-block;
}
.button:hover {
background: url("http://img15.hostingpics.net/pics/300291bluehalo.png") center bottom no-repeat;
background-size: cover;
}
It makes the background image cover the whole div, without cropping it. Hopefully my answer was helpful!