-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hero background image #1007
Comments
I was able to accomplish the background effect I think your looking for, utilizing the following markup/styles. Let me know if it doesn't work for you. ---hero section markup---
---scss---
|
I've been using a similar way that @grantmoran described to get background images. Is there however a way to make it generic somehow? For eg
In the above example, the The application I am working on has some pages with such background images and one of the pages has several |
That would require JavaScript. Using jQuery, something like:
|
If you're using Sass, an easy way to choose background images for your hero is to extend the hero class for each background image you need to use. <section class="hero-foo is-fullheight">
<div class="hero-body> ... </div>
</section>
And in your Sass files, extend the Hero class. .hero-foo
@extend .hero
background-image: url('/img/foo.jpg') Alternatively, you could use a Sass map to define your backgrounds. $backgrounds: (foo: '/img/foo.jpg', bar: '/img/bar.jpg')
@each $key, $image in $backgrounds
.hero-#{$key}
@extend .hero
background-image: url(#{'$image'})
While this approach requires that you assign images to classes in your stylesheets instead of creating an |
@nedjo Cool tip!! Thanks! |
Got it working! Tnx for suggestions Sent from my Xiaomi MI 5 using FastHub |
Good idea, thank you for this! However, it should be But you could add the quotes right after the normal brace: |
Hi, is there by any chance a way to achieve the same result without having to do it with sass? This solution works only if you have only one image you want to render on the hero background, but how do you get to this when you have several HTML pages with a hero (and a navbar) and you want a specific image for each pages (and set it up dynamically if possible) ? If some CSS wizard come to a solution let me know! |
The only other way to add a background image to a hero would be to use an inline style="" attribute, which removes the CSS requirement for all background-related properties. You have a couple options. Option 1 -- using the background: property which is short hand for background-image, background-size, etc. More info here: https://developer.mozilla.org/en-US/docs/Web/CSS/background <div class="hero is-fullheight" style="background: center top/cover url('https://source.unsplash.com/random/1920x1080/');">
<div class="hero-head"></div>
<div class="hero-body"><div class="container is-fullhd"><div class="content"><h1>Hero w/Background</h1></div></div></div>
<div class="hero-foot"></div>
</div> Option 2 -- This will make the html a little longer (which may or may not be a concern), indicate each of the background-related properties individually in the style="" attribute. For a background to show you need a minimum of background-image, background-size and background-position indicated. <div class="hero is-fullheight" style="background-image: url('https://source.unsplash.com/random/1920x1080/'); background-position: center top; background-size: cover;">
<div class="hero-head"></div>
<div class="hero-body">
<div class="container is-fullhd">
<div class="content">
<h1>Hero w/Background</h1>
</div>
</div>
</div>
<div class="hero-foot"></div>
</div> Probably worth also noting that content inside the hero is partially controlled by the hero color specification, so if you use the Similarly text colors are controlled via their inline properties too, which also presents additional challenges. <div class="hero is-danger is-fullheight" style="background-image: url('https://source.unsplash.com/random/1920x1080/'); background-position: center top; background-size: cover;">
<div class="hero-head"></div>
<div class="hero-body">
<div class="container is-fullhd">
<div class="content">
<h1 class="title">Hero w/Background</h1>
</div>
</div>
</div>
<div class="hero-foot"></div>
</div> Codepn should you want to test out the code above: https://codepen.io/digitigradeit/pen/NWeayaW |
Thanks a bunch @digitigradeit, it works like a charm! |
Cant get to add a backround img for hero section:
<section class="hero is-primary is-fullheight header-image"> <!-- Hero header: will stick at the top --> <div class="hero-head"> <header class="navbar"> <div class="navbar-brand"> <a class="navbar-item" href="http://bulma.io"> <img src="http://bulma.io/images/bulma-logo.png" alt="Bulma: a modern CSS framework based on Flexbox" width="112" height="28"> </a>
and CSS part:
.header-image { background-image: url("http://orig14.deviantart.net/7584/f/2015/181/2/7/flat_mountains_landscape_by_ggiuliafilippini-d8zdbco.jpg"); background-position: center center; background-repeat: no-repeat; background-attachment: fixed; background-size: cover; background-color: #999; }
Maybe theres some workaround???
The text was updated successfully, but these errors were encountered: