css full image background issue - css

My webpage have 4 background images, each of them needs to be a full screen. On each background, I have some labels and texts. Here is the CSS code, I will address the issue after the code section.
html{
height:100%;
}
body{
font-family:'Roboto', sans-serif;
color:#fff;
-webkit-font-smoothing:antialiased;
-moz-osx-font-smoothing:grayscale;
height:100%;
}
.section{
background-attachment:inherit;
background: no-repeat center center fixed;
height:100%;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size:cover;
}
By using this style. All background images can take full screen. However, when I resize the browser window to a small height, my labels $ text on background 1 starts to across background 1 and background 2.
If I delete the "height:100%" or using "min-height:100%" instead. Each background image will never get to full screen but I will not get my labels & text across two consecutive background images when I resize the browser window to a smaller height. Please help
Here is my HTML for the first two image background. I need each image background to take full screen on any device, with my text fields look good on each background. Here my issue is, when I shrink the height of the browser, some text will disappear (covered by the next background) due to the height of the text field > height of browser
<!-- Page Top Section -->
<div id="page-top" class="section" data-background-image="/images/background/page-top.jpg" style='background-image: url("/images/background/page-top.jpg");'>
<div class="pattern height-resize">
<div class="container">
<h1 class="site-title">
hello I am site title
</h1><!-- /.site-title -->
<h2 class="section-title">
hello I am section-1
</h2>
<div class="next-section">
<a class="go-to-about"><span></span></a>
</div><!-- /.next-section -->
</div><!-- /.container -->
</div><!-- /.pattern -->
</div><!-- /#page-top -->
<!-- Page Top Section End -->
<!-- About Us Section -->
<section id="about" class="section" data-background-image="/images/background/about-us.jpg" style='background-image: url("/images/background/about-us.jpg");'>
<div class="pattern height-resize">
<div class="container">
<h3 class="section-name">
<span>
SECTION NAME
</span>
</h3><!-- /.section-name -->
<h2 class="section-title">
SECTION TITLE
</h2><!-- /.Section-title -->
<p class="section-description">
FJDKLASJLKFJASDKLJFLKSJFLKDJSAKLFJDLKSAJ
</p><!-- /.section-description -->
<div class="next-section">
<a class="go-to-subscribe"><span></span></a>
</div><!-- /.next-section -->
</div><!-- /.container -->
</div><!-- /.pattern -->
</section><!-- /#about -->
<!-- About Us Section End -->
section title css:
.section-title{
text-align:center;
text-transform:uppercase;
font-weight:300;
font-size:80px;
}

If you want four divs with 100% screen size in width and height with different backgrounds that can accept any HTML inside and will fit all screen sizes, there is traditional way to do so:
Preview: http://codepen.io/kunokdev/pen/LRPPdO
HTML:
<section>
<div>Any HTML inside a first div w/ background</div>
<div>Any HTML inside a second div w/ background</div>
<div>Third is here too!</div>
<div>
<h1>Forth</h1>
<p>Forth has even more than that!</p>
</div>
</section>
CSS:
html, body {
height: 100%;
}
section {
height: 100%;
}
div {
height: 100%;
background-size: cover;
}
div:nth-child(1){
background-image: url(http://i.imgur.com/BMaWw5C.jpg);
}
div:nth-child(2){
background-image: url('http://i.imgur.com/sznCGw4.jpg');
}
div:nth-child(3){
background-image: url(http://i.imgur.com/BMaWw5C.jpg);
}
div:nth-child(4){
background-image: url('http://i.imgur.com/sznCGw4.jpg');
}
or else with viewport units:
HTML:
<div></div>
<div></div>
<div></div>
<div></div>
CSS:
div {
height: 100vh;
}
So I think you need background-size: cover; and maybe a little bit of background-position property too. In case your content overflows, consider using overflow: auto.
Additionally:
If your viewport height and width are smaller than the html inside containers, consider using media queries.
For example if your content overflows when height is 500px use query such as
media only screen and (max-width: 500px){
div {
height: auto;
}
}
Consider using Mozilla Firefox responsive design view when testing. Similar feature exists in Chrome too.
Then your contents will no longer be 100% after viewport max-width of 500px, instead they will be as large as contents inside.

Related

Why background image is overflow the footer?

https://ibb.co/m9QvTND
Live
http://nafidev.com/t1/
Background image is overflow footer.
body {
background-image: url(../img/planet.jpg);
background-repeat: no-repeat;
background-size: cover;
}
Footer:
.footer {
padding-top: 5rem;
padding-bottom: 5rem;
background-color: #2c3e50;
color: #fff;
}
Footer will stay in the last. I don't want to fixed the footer, then content will go under footer.
I'm not sure why the body bg is overflowing, but if you want the planet background to stop with the footer, you can wrap the HTML inside of another element and apply the background setting to that element.
<body>
<div class="main-wrapper">
<nav class="navbar navbar-default navbar-fixed-top">...</nav>
<!-- Image Section -->
<section class="page-section portfolio" id="portfolio">...</section>
<!-- Copyright Section -->
<section class="copyright py-4 text-center text-white">...</section>
</div> <!-- close main-wrapper -->
</body>
Then you can style the main-wrapper element instead of the body
.main-wrapper {
background-image: url(../img/planet.jpg);
background-repeat: no-repeat;
background-size: cover;
}

image with overflow: hidden within container-fluid --does not hide image

Problem: img {Overflow: hidden;} isn't working as expected.
<link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
<style>
.container-fluid {
background-color: #092876;
color: white;
overflow:hidden; <!-- change visible to hidden to see effect -->
margin: 1% 5% 1% 5%;
max-width: 100%;
}
</style>
<html>
<div class="container-fluid"> <!-- container-fluid-->
<div class="about-me" id="about-me"> <!-- ABOUT ME SECTION-->
<h1 class=about-me_h1>Lee Yang </h1>
<img src="http://res.cloudinary.com/dsy2w1n70/image/upload/c_scale,h_461,w_450/v1492552203/p3_2_d3xydb.jpg" alt="Profile Picture"
align=left>
<p class=about-me_p1>If i remove hidden the picture renders outside of the element. But if i use hidden, the element expands to capture the picture</p>
</div> <!--END of ABOUT ME SECTION-->
</html>
The element and the image are within a container-fluid.
If i remove overflow (default then set to visible), the image renders outside of the elements box; as expected. But once I add overflow:hidden, the the element expands to cover the whole image. This is what I want, but i stumbled upon this by accident fully expecting overflow:hidden to hide the latter part of the image.

How to center the left edge of background image using css

I've been given a design that I'm having a lot of trouble building as a responsive site.
I'd like the image to extend to the edge of the browser window, so I've placed it as a background image in the fluid container, with a spacer image. The problem is that once we go mobile, the background image will appear beneath the copy above.
I've tried several other versions of this layout, and nothing works. Hoping someone has a suggestion.
Here's a rough markup.
.test {
background-image: url(http://placehold.it/1600x500 );
background-repeat: no-repeat;
background-position: 50% bottom;
background-size: cover;
padding: 0;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container-fluid test">
<div class="container">
<div class="row">
<div class="col-md-6" style="background-color: blue;">left col</div>
<div class="col-md-6"><img src="http://placehold.it/20x500/b0b0b0" alt="spacer"></div>
</div>
</div>
</div>
one way to achieve the responsive effect is to change the background-size accordingly to match the new visualization. That way you can alter from 50% 100% for the desktop version where it's right aligned and to 100% 50% on the mobile version where it fills half the height of the component.
As an example I've created this jsFiddle demo, that goes like this:
The html is pretty much the same:
<div class="container bg-pink">
<div class="row half-bg">
<div class="col-sm-6">
<p class="text-right">
<b>bold text first with some nuances</b> then some normal text to break the line. then some normal text to break the line. then some normal text to break the line.then some normal text to break the line.then some normal text to break the line.then some normal text to break the line.
</p>
</div>
<div class="col-sm-6 no-gutter">
<div class="half-holder">
</div>
</div>
</div>
</div>
The CSS (important bits) we define:
/* Image */
.half-holder {
height: 100px;
}
/* Normal */
.half-bg {
background: url('https://maxwelldemon.files.wordpress.com/2012/03/2x1-triangle.png') no-repeat right bottom;
background-size: 50% 100%;
}
/* The media query for responsive */
#media (max-width: 768px) {
.half-bg {
background-size: 100% 50%;
}
}
Hope it helps!

single page body height

within body I have sections...I expected body to get the whole height: section1.height+section2.height+... but it only gets the top sections height.what am I missing? jsfiddle
<!-- Header -->
<section id="top">
<div class="container">
<div class="row">
<div class="col-lg-12">header</div>
</div>
</div>
</section>
<!--mission-->
<section id="mission" class="mission">
<div class="container">
<div class="row">
<div class="col-lg-12">mission</div>
</div>
</div>
</section>
<!-- contact -->
<section id="contact" class="contact">
<div class="container">
<div class="row">
<div class="col-lg-12">contact</div>
</div>
</div>
</section>
You are looking for min-height on your html and body. Using height: 100% makes the html and body height wrap around all of your content up to the height of the screen/viewport. Using min-height: 100% makes the html and body height equal at least the height of the screen/viewport, and can also expand downward to fit overflowing content.
JSFiddle
html, body {
min-height: 100% !important;
width: 100% !important;
margin: 0;
padding: 0;
}
NOTE - Try to avoid using !important unless it is absolutely necessary. It will create problems down the road if/when you need to override the styling on something for a single page.
You can set your header section.top to the viewport height by using 100vh. Then you can remove the height: 100% of html and body, and they will stay fluid (fiddle):
html,body{
margin:0;
padding:0 ;
}
#top {
width: 100%;
height: 100vh;
background: #802818;
-webkit-background-size: cover;
-moz-background-size: cover;
background-size: cover;
-o-background-size: cover;
}

Stretch div to bottom of screensize, but allow scrolldown

On load I'd like to load the topsection div with a bg image and have it take up the entire screen, but then I have content below it which you can scroll down to. The div should size itself to the window screen only on load and not remain like that on scrolldown. I cannot give the div a position:absolute; either.
I'm banging my head on this one. I've tried a ton of different things
Here is my html:
<div id="topsection" class="row bgimage ">
<div id="logomain" class="mainlogo ">
<div class=" floorplanbuttoncontainer helvetical">
<ul>
<li>Residence A - Duplex</li>
<li>
Residence D - Simplex</li>
</ul>
</div><!-- end floorplanbuttoncontainer -->
</div><!-- end logomain -->
Here is my css for the background image:
.bgimage {
background: url(images/image.jpg) no-repeat center center fixed;
background-size: cover;
.mainlogo {
margin:0 auto;text-align:center;width:100%;height:488px; /*I think this height is messing things up */
background-image:url(images/picture.png);background-repeat:no-repeat;
background-position: center;
}
In order to set a div to take up the entire screen you need to set the height of the body and html element to 100%. You also have to remove the padding and margin from them. Then you create a wrapper class to encase your content and assign it your background-image. Then all ya' gotta do is create the content below your full screen image to scroll into!
Fiddle
Edit
If you run the snippet below and hit full page you can see how it works.
body, html {
height: 100%;
margin: 0;
padding: 0;
}
.wrapper {
min-height: 100%;
background: red;
}
.full {
width: 100%;
}
.footerThing {
width: 100%;
height: 200px;
background: blue;
}
<div class="wrapper">
<div class="full">
asd
</div>
</div>
<div class="footerThing">
</div>
Modern browsers: a simple way is to use vh units to get the Viewport Height
Just to simplify: jsBin demo
<div id="home" class="container full">
<h1>HOME</h1>
</div>
<div id="about" class="container">
<h1>About us</h1>
<p>Content</p>
</div>
CSS:
.container { min-height:400px; }
.full { height:100vh; }
Crossbrowser: use % instead of vh and simply add html, body{height:100%;} jsBin demo

Resources