How to center the left edge of background image using css - 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!

Related

how to use horizontal over-flow in css

please i'm trying to use horizontal overflow using css , if i use just images i get the horizontal scroll this how i use it with images
<div class="d-flex overflow-hidden overflow-scroll-x ">
<img
class="max-width-200 "
src="../../../../assets/images/Creditrd.svg"
/>
<img
class="max-width-200 "
src="../../../../assets/images/Creditard.svg"
/>
</div>
if i use background images i dont get anything here's how i do it
<div class="d-flex overflow-hidden overflow-scroll-x">
<div class="account-wallet-imag max-width-200 border-radius-16">
heheh
</div>
<div class="account-wallet-imag max-width-200 border-radius-16">
eheehhh
</div>
</div>
this is my css
.account-wallet-imag {
background-repeat: no-repeat; /* Do not repeat the image */
background-size: cover; /* Resize the background image to cover the entire container */
width: 100%;
height: 100%;
background-image: url("#/assets/images/card.png");
}
please how can i go about this

This code in CSS is stacking the background images on top of each other. Why?

I am fairly new to CSS.
I am creating a grid of photos by using divs and classes, and they WOULD be a 3X3 grid of photos, but all the various photo shape aspects just stack on top of each other in the top left corner. It almost seems like the float property simply isnt working. See code.
I basically stripped away everything i had been trying with object-fit and object position, because my overall goal was to take images of varying aspects, which i can object-fit and object-position fine as a single photo to adjust it to be a square photo panned to my liking. But now I am back to basics and testing an instructor's past example of making a 3 x 3 grid as shown in the code snippets, with the only alteration to his code being using my own local photos.
But there is no grid here. All the photos just stack on top of each other in the top left. I am not bothering to make them square yet, as i am just going back to creating a grid first.
One possible difference, is that the instructors photos, who's images were all imported from outside URLs and were ALREADY square. Though i don't know why that would matter as he sets the height and width in the image class. Height is 300 px and width is 30%. I could see the different aspects disorienting the photos for now, but why would they be on top of each other if it includes a float property? Shouldn't they float left to the next photo?
It should be a 3 by 3 responsive photo grid.
Any help for the newbie is appreciated.
Here is the HTML:
<!DOCTYPE html>
<html>
<head>
<title>efaround</title>
<link rel="stylesheet" type="text/css" href="someotherstyle.css">
</head>
<body>
<div class="image image1">
<div class="image image2">
<div class="image image3">
<div class="image image4">
<div class="image image5">
<div class="image image6">
<div class="image image7">
<div class="image image8">
<div class="image image9">
</body>
</html>
And here is the CSS:
.image {
height: 300px;
width: 30%;
float: left;
margin: 1.66%;
background-size: cover;
background-position: center center;
}
.image1 {
background-image: url("14258104_10210446960276194_6288188597623083310_o copy2.jpg");
}
.image2 {
background-image: url("28279596_10212827002964259_2506063728175832972_n.jpg");
}
.image3 {
background-image: url("sethsyes.jpg")
}
.image4 {
background-image: url("sethstudio.jpg")
}
.image5 {
background-image: url("sethsmonkey.jpg")
}
.image6 {
background-image: url("turtles.jpg")
}
.image7 {
background-image: url("turtles.jpg")
}
.image8 {
background-image: url("turtles.jpg")
}
.image9 {
background-image: url("turtles.jpg")
}
i expect a 3 x 3 responsive photo grid.
the output is all photos stacked on top of each other in the top left.
(Float property not working? Because photos arent square? I dont understand)
.img-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
grid-gap: 1rem;
background: #000;
}
.image {
width: 200px;
}
<div class="img-grid">
<div class="image"><img src="https://source.unsplash.com/random/200x200"></div>
<div class="image"><img src="https://source.unsplash.com/random/200x200"></div>
<div class="image"><img src="https://source.unsplash.com/random/200x200"></div>
<div class="image"><img src="https://source.unsplash.com/random/200x200"></div>
<div class="image"><img src="https://source.unsplash.com/random/200x200"></div>
<div class="image"><img src="https://source.unsplash.com/random/200x200"></div>
<div class="image"><img src="https://source.unsplash.com/random/200x200"></div>
<div class="image"><img src="https://source.unsplash.com/random/200x200"></div>
</div>

full background image is not rending properly in a div

I am using a full background image in my div, but when resizing the window it is not resizing properly from left and right, I do not want to use position:fixed because it is creating issues for me.
Kindly help, how can I fix this issue, the image should resize perfectly as per window size (resize).
<div class="row">
<div class="container-fluid">
<div class="col-md-3"></div>
<div class="col-md-9">
<div class="loginbg"></div>
</div>
</div>
</div>
**css:**
.loginbg{
background: url("../../images/TalexAuthbg3.jpg") no-repeat center top;
z-index: 0;
background-size: cover;
height:100vh;
background-position:100%;
}
I want to render a full background image within the .loginbg div but it is not rendering properly.
You can use background-size: contain if you want the full image to show at every window size, because of background-size: cover crops the image to fit the window size without disturbing its aspect ratio.
.loginbg{
background: url("https://longstoryshortdesign.co.uk/wp-content/uploads/2017/03/mc-saatchi-hero-home.jpg") no-repeat center top;
z-index: 0;
background-size: contain;
height:100vh;
}
<div class="row">
<div class="container-fluid">
<div class="col-md-3"></div>
<div class="col-md-9">
<div class="loginbg"></div>
</div>
</div>
</div>

css full image background issue

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.

Bootstrap glitch in pull / push

starting from this question Three column Bootstrap layout with left sidebar at bottom I learned about Bootstrap column push and pull.
The snippet below almost works in getting the result I want:
The problem is the resizing the screen, at around 1200px width the two aside elements (blue and green) are one beside the other (you can check the snippet).
Any help?
div,aside { height: 50px}
.content { background: lightpink;}
.side1 { background: lightblue;}
.side2 { background: lightgreen;}
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" />
<div class="container">
<div class="content left col-md-7 col-lg-push-2"></div>
<aside class="side1 left col-md-2 col-lg-pull-7"></aside>
<aside class="side2 left col-md-3"></aside>
</div>
It's not a glitch. You're mixing sizes. Your pushes and pulls should be set at the same breakpoint as the column declarations.
div,aside { height: 50px}
.content { background: lightpink;}
.side1 { background: lightblue;}
.side2 { background: lightgreen;}
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" />
<div class="container">
<div class="content left col-md-7 col-md-push-2"></div>
<aside class="side1 left col-md-2 col-md-pull-7"></aside>
<aside class="side2 left col-md-3"></aside>
</div>

Resources