Background-image not working correctly? - html

I am trying to get a background image on some text that heads to the left of the screen whilst the text is on the right. I want it to be a background image so I can do:
background-position: left center;
I have done the same thing just above within the same CSS file, however, this time it doesn't want to work and I cannot work out why for the life of me.
HTML:
<section class="skillset">
<div class="spaceage">
<h1>-filler-</h1>
<p>-filler-</p>
</div>
<div class="ability">
<h3>-filler-</h3>
<p>-filler-</p>
<img src="img/xdlogo.svg" alt="Adobe Experience Design Logo">
<img src="img/pslogo.png" alt="Adobe Photoshop Logo">
<img src="img/html5logo.png" alt="HTML 5 Logo">
<img src="img/css3logo.svg" alt="CSS 3 Logo">
</div>
</section>
<section class="aboutMe">
<div class="aboutMeText">
<h1>-filler-</h1>
<p>-filler-</p>
<p>-filler-</p>
</div>
</section>
I did the same thing in the in the 'skillset' section but cannot achieve it in the about me section. Here is my CSS for both:
.skillset {
font-family: 'Montserrat', sans-serif;
position: relative;
margin-top: 50px;
background-image: url(img/asteroid.gif);
background-repeat: no-repeat;
background-position: right center;
background-size: 40%;
}
.aboutMe {
margin-top: 150px;
margin-right: 5%;
font-family: 'Montserrat', sans-serif;
position: relative;
background-image: url(img/asteroid.gif);
background-repeat: no-repeat;
background-position: left center;
background-size: 40%;
}
I cannot see why the background image isn't displaying next to the text. Does anyone else know why?
EDIT:
I have now discovered that if I add an image using the tag underneath the text in the HTML, the background image miraculously appears!?!?!

Is this what you want?
I used text-align:right; on .aboutMe
.skillset {
font-family: 'Montserrat', sans-serif;
position: relative;
margin-top: 50px;
background-image: url(https://placehold.it/250x150);
background-repeat: no-repeat;
background-position: right center;
background-size: 40%;
}
.aboutMe {
text-align:right;
margin-top: 150px;
margin-right: 5%;
font-family: 'Montserrat', sans-serif;
position: relative;
background-image: url(https://placehold.it/250x150);
background-repeat: no-repeat;
background-position: left center;
background-size: 40%;
}
<section class="skillset">
<div class="spaceage">
<h1>-filler-</h1>
<p>-filler-</p>
</div>
<div class="ability">
<h3>-filler-</h3>
<p>-filler-</p>
<img src="img/xdlogo.svg" alt="Adobe Experience Design Logo">
<img src="img/pslogo.png" alt="Adobe Photoshop Logo">
<img src="img/html5logo.png" alt="HTML 5 Logo">
<img src="img/css3logo.svg" alt="CSS 3 Logo">
</div>
</section>
<section class="aboutMe">
<div class="aboutMeText">
<h1>-filler-</h1>
<p>-filler-</p>
<p>-filler-</p>
</div>
</section>
Updated html structure
.a {
text-align: right;
background-image: url(https://placehold.it/250x150);
background-repeat: no-repeat;
background-position: left center;
padding-left: 50%;
}
body {
padding: 15px;
}
<div class="a">
<h1>This is some textThis is some textThis is some textThis is some textThis is some textThis is some textThis is some text</h1>
</div>

I ended up taking a break for a drink (I've been designer/making this website for around 5 hours now) after my break I sat, took a breath and started again with the about section. It was much easier to think now this is what I came up with:
<div class="about">
<h1>Hi, I'm Jack</h1>
<div class="aboutTxt">
<p>filler</p>
<p>filler</p>
</div>
</div>
.about {
padding: 0 5%;
background-image: url(img/programmer.gif);
background-repeat: no-repeat;
background-position: left center;
background-size: 30%;
margin-top: 225px;
font-family: 'Montserrat', sans-serif;
margin-left: 5%;
}
.about h1 {
margin-bottom: 30px;
color: #2B9DFF;
text-transform: capitalize;
}
.aboutTxt {
text-align: justify;
}
.about h1,
.aboutTxt {
margin-left: 50%;
background: rgba(211, 211, 211, 0.1);
}
Tbh, I made a big problem out of something that if I took a break and just thought about it, wouldn't have been a problem. Thanks for everyone's help but I got this one ahah!

why don't styling p and h1 separately?
because you are more flexible at the end.
By the way, the section should have an id aboutMe instead of a class name. makes more sense. keep that in mind.
Jsfiddle
https://jsfiddle.net/L0cbe709/
HTML:
<section class="skillset">
<div class="spaceage">
<h1>-filler-</h1>
<p>-filler-</p>
</div>
<div class="ability">
<h3>-filler-</h3>
<p>-filler-</p>
<img src="img/xdlogo.svg" alt="Adobe Experience Design Logo">
<img src="img/pslogo.png" alt="Adobe Photoshop Logo">
<img src="img/html5logo.png" alt="HTML 5 Logo">
<img src="img/css3logo.svg" alt="CSS 3 Logo">
</div>
</section>
<section class="aboutMe">
<div class="aboutMeText">
<h1>-filler-</h1>
<p>-filler-</p>
<p>-filler-</p>
</div>
</section>
CSS
.ability {
width: 100%;
}
.skillset {
font-family: 'Montserrat', sans-serif;
position: relative;
margin-top: 50px;
background-image: url(https://placehold.it/250x150);
background-repeat: no-repeat;
background-position: right center;
background-size: 40%;
}
.aboutMe {
width: 100%;
margin-top: 150px;
margin-right: 5%;
font-family: 'Montserrat', sans-serif;
position: relative;
background-image: url(https://placehold.it/250x150);
background-repeat: no-repeat;
background-position: left center;
background-size: 40%;
}
.aboutMe p {
text-align: right;
}
.aboutMe h1 {
text-align: center;
}

Related

How to make a responsive div in css

So I have this small webpage I am trying to build. Everything looks good til I try to scale-in and out the browser windows to check it's responsiveness.
It looks good with 320x568 as below.
But when it scaled in (reduce the browser window, it shows like this, which I don't want that black box (`.transbox) to go down beyond the photo.)
I am using bootstrap framework and I DON'T NEED TO USE css media queries to make it responsive.
How can I do it with css instead?
This is my current html and css
.masthead {
height: 20vh;
min-height: 370px;
background-image: url("http://lorempixel.com/1920/1080");
background-size: cover;
background-position: center;
background-repeat: no-repeat;
}
div.transbox {
margin: 30px;
background-color: rgba(0, 0, 0, 0.6);
min-height: 300px;
}
div.transbox p {
font-weight: bold;
color: white;
}
.transbox h1 {
color: white;
}
<header className="masthead">
<div className="container">
<div className="row align-items-center">
<div className="col-12 text-center">
<div class="transbox">
<h1 className="font-weight-light">
All your Escort needs within a single place!
</h1>
<p className="lead">
Find the best set of escort services in Sri Lanka
</p>
</div>
</div>
</div>
</div>
</header>
Can someone please help me? Is there a bootstrap class or pure css way to do this?
Here is the working example:
body {
margin: 0;
padding: 0;
}
.masthead {
width: 100%;
height: 100%;
min-height: 100vh;
background-image: url("http://lorempixel.com/1920/1080");
background-size: cover;
background-position: center;
background-repeat: no-repeat;
display: flex;
align-items: center;
}
div.transbox {
margin: 30px;
background-color: rgba(0, 0, 0, 0.6);
min-height: 300px;
}
div.transbox p {
font-weight: bold;
color: white;
}
.transbox h1 {
color: white;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<header class="masthead">
<div class="container">
<div class="row align-items-center">
<div class="col-12 text-center">
<div class="transbox">
<h1 class="font-weight-light">
All your Escort needs within a single place!
</h1>
<p class="lead">
Find the best set of escort services in Sri Lanka
</p>
</div>
</div>
</div>
</div>
</header>
.masthead {
height: 20vh;
min-height: 400px;
background-image: url("http://lorempixel.com/1920/1080");
background-size: cover;
background-position: center;
background-repeat: no-repeat;
}
div.transbox {
margin: 30px;
background-color: rgba(0, 0, 0, 0.6);
min-height: 300px;
}
div.transbox p {
font-weight: bold;
color: white;
}
.transbox h1 {
color: white;
}
<header className="masthead">
<div className="container">
<div className="row align-items-center">
<div className="col-12 text-center">
<div class="transbox">
<h1 className="font-weight-light">
All your Escort needs within a single place!
</h1>
<p className="lead">
Find the best set of escort services in Sri Lanka
</p>
</div>
</div>
</div>
</div>
</header>
Your content is more as compare to width of background image. So, just increase the height of your background image or just reduce the font-size via media query.

CSS Grid 50% Divided Width Cell With Background Image Does not fit Screen

I am trying to use css grid to make 2x2 rectangles with equal width(dividing screen into 2) but for some reason right side ones are expanding pages width and creates scrollbar.
not fiting to screen image
CSS:
.indexGridContainer{
display:grid;
grid-template-columns: repeat(2, 1fr);
grid-auto-rows: minmax(250px, 450px);
}
.wallets{
position:relative;
background-image: url(https://bellroy.imgix.net/cms_images/686/bellroy-brand-homepage-2.jpg?auto=format&fit=max);
background-position: center center;
background-size: cover;
background-repeat: no-repeat;
}
.bags{
position:relative;
background-image: url(https://bellroy.imgix.net/cms_images/691/bellroy-brand-homepage-7.jpg?auto=format&fit=max);
background-position: center center;
background-size: cover;
background-repeat: no-repeat;
}
.keys{
position:relative;
background-image: url( https://bellroy.imgix.net/cms_images/688/bellroy-brand-homepage-4.jpg?auto=format&fit=max);
background-position: center center;
background-size: cover;
background-repeat: no-repeat;
}
.phonecases{
position:relative;
background-image: url( https://bellroy.imgix.net/cms_images/690/bellroy-brand-homepage-6.jpg?auto=format&fit=max);
background-position: center center;
background-size: cover;
background-repeat: no-repeat;
}
.titleBox{
position: relative;
top: 0;
left: 20px;
padding: 20px;
z-index: 1;
}
.titleBox h1{
font-family: 'PT serif', 'serif';
color: #f2f2f2;
}
.titleBox h3{
font-family: 'Lato', sans-serif;
-webkit-font-smoothing: antialiased;
font-size: 12px;
font-weight: bold;
letter-spacing: 1px;
text-transform: uppercase;
color: #f2f2f2;
}
HTML:
<div class="indexGridContainer">
<a href="#" class="wallets">
<span class="titleBox">
<h1>Men's Wallets</h1>
<h3>>SLIM YOUR WALLET</h3>
</span>
</a>
<a href="#" class="keys">
<span class="titleBox">
<h1>Key Covers</h1>
<h3>>STOP THE JANGLE</h3>
</span>
</a>
<a href="#" class="bags">
<span class="titleBox">
<h1>Bags</h1>
<h3>>Merge work and Play into one</h3>
</span>
</a>
<a href="#" class="phonecases">
<span class="titleBox">
<h1>Phone Cases</h1>
<h3>>Streamline your phone and wallet.</h3>
</span>
</a>
</div>
codepen:
https://codepen.io/anon/pen/bOXooP
Is there a problem with .indexGridContainer ? is repeat(2,1fr); is wrong way to divide screens width 50% ?
thanks
The issue is .titlebox has a property of left: 20px, causing white space on the right when its width is 50% of the page's. Reduce its width, or if you're lazy, add the following CSS to work around the issue:
body {
overflow-x: hidden;
}
You are using span as a container of block elements which is not correct. You need to use div instead and consider margin to create space and not adjust the position because you will simply create an overflow on the right if you push the element from the left.
Also don't forget to remove default body margin if you want to cover all the screen:
body {
margin:0;
}
.indexGridContainer {
display: grid;
grid-template-columns: repeat(2, 1fr);
grid-auto-rows: minmax(250px, 450px);
}
.indexGridContainer > a {
background-position: center center;
background-size: cover;
background-repeat: no-repeat;
}
.wallets {
background-image: url(https://bellroy.imgix.net/cms_images/686/bellroy-brand-homepage-2.jpg?auto=format&fit=max);
}
.bags {
background-image: url(https://bellroy.imgix.net/cms_images/691/bellroy-brand-homepage-7.jpg?auto=format&fit=max);
}
.keys {
background-image: url(https://bellroy.imgix.net/cms_images/688/bellroy-brand-homepage-4.jpg?auto=format&fit=max);
}
.phonecases {
background-image: url(https://bellroy.imgix.net/cms_images/690/bellroy-brand-homepage-6.jpg?auto=format&fit=max);
}
.titleBox {
margin-left: 20px;
padding: 20px;
}
.titleBox h1 {
font-family: 'PT serif', 'serif';
color: #f2f2f2;
}
.titleBox h3 {
font-family: 'Lato', sans-serif;
-webkit-font-smoothing: antialiased;
font-size: 12px;
font-weight: bold;
letter-spacing: 1px;
text-transform: uppercase;
color: #f2f2f2;
}
<div class="indexGridContainer">
<a href="#" class="wallets">
<div class="titleBox">
<h1>Men's Wallets</h1>
<h3>>SLIM YOUR WALLET</h3>
</div>
</a>
<a href="#" class="keys">
<div class="titleBox">
<h1>Key Covers</h1>
<h3>>STOP THE JANGLE</h3>
</div>
</a>
<a href="#" class="bags">
<div class="titleBox">
<h1>Bags</h1>
<h3>>Merge work and Play into one</h3>
</div>
</a>
<a href="#" class="phonecases">
<div class="titleBox">
<h1>Phone Cases</h1>
<h3>>Streamline your phone and wallet.</h3>
</div>
</a>
</div>

Is there a way to remove or hide a part of an image with css or jquery

I am making a website which has a certain background image. When it changes screen size i need the middle part of an image do be removed so the graphic would look slimmer . Here is the picture.
This is how it is now :
This is how i need it when the screen is changed to tablet :
My html :
<section class="hero" style="background-image: url(./images/hero.png)">
<header class="header">
<img src="./images/logo.png" alt="Logo image" class="logo">
<div class="shape hamburger">
<!-- <span class="hide">Hamburger icon</span> -->
<a class="line-shape" href="javascript:;"><span></span><span class="hide">Hamburger icon</span></a>
<span class="shape-txt" >MENU</span>
</div>
</header>
<div class="row">
<div class="col col-2 offset-2 col-2-t offset-2-t">
<h1 class="section-title">
Living our values
Transforming our business
</h1>
<p class="txt">
UDG Healthcare plc</br>
Annual Report and Accounts 2015
</p>
<span class="s s-down-arrow"><span class="hide">download</span></span>Download Full Report <span class="no-under">(PDF, 2.5 MB)</span>
</div>
</div>
<span class="above-btn">Explore our year</br>
in review</span>
<button type="button" class="down"><img src="./images/down.png" alt="Move to the top content"><span class="s s-down-arrow btn-arrow"><span class="hide">Move Down</span></span></button>
My css :
.hero {
background-repeat: no-repeat;
background-size: cover;
background-color: $hero-bg-cream;
overflow: hidden;
.row {
margin: 0;
}
h1 {
padding: 106px 0 7px;
line-height: 1.15;
word-spacing: 5px;
letter-spacing: 0px;
width: 70%;
font-size: 40px;
color: $grey;
}
.txt {
line-height: 19px;
padding-bottom: 14px;
color: $grey;
}
.padded {
padding-bottom: 421px;
}
.s-down-arrow {
&:last-child {
left: -38px;
color: $grey;
top: 0;
}
}
.above-btn {
font-size: 14px;
text-align: center;
display: block;
padding-bottom: 16px;
color: $grey;
}
.down {
transform: translateX(13%);
}
#include breakpoint (tablet) {
h1 {
font-size: 29px;
padding: 217px 0 7px;
}
.txt {
padding-bottom: 10px;
}
.padded {
padding-bottom: 308px;
}
.down {
transform: translateX(10%);
}
}
}
I guess I would need to remove the right part of the image or something like that ?
Ok so the solution was to make the background-size: auto;
You can do this here in HTML :
<section class="hero" style="background-image: url(./images/hero.png); background-size: 100% 100%;">
Or here, in CSS
.hero {
background-repeat: no-repeat;
background-size: 100% 100%;
background-color: $hero-bg-cream;
overflow: hidden;
.row {
margin: 0;
}

Section background overflowing into another section

I apologize in advance for this somewhat lengthy explanation. I am trying to create a website such as http://melaniedaveid.com/ to improve my coding abilities. I created the first section page and it turned out great. But when I added another section, the previous section didn't fill up the whole page anymore (picture: http://imgur.com/a/EbUKn).
In order to solve this I gave full height to the first sections ID:
#header {
height: 100%;}
This fixed the problem(http://imgur.com/a/BlckC) but now when I resize my browser the second section over flows into my first, covering the text(http://imgur.com/a/C1jED). Any suggestions/leads would be greatly appreciated!
body {
background: linear-gradient(rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0.7)), url('/img/roses.jpg') no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
font-size: 20px;
height: 100vh;
}
/*------------------------------------------------ HOME PAGE ------------------------------------------------------------------*/
/*------------------------------
HEADING TEXT
-------------------------------*/
.name h1 {
font-family: 'Muli', sans-serif;
font-size: 500%;
font-weight: 300;
text-align: center;
padding-top: 10%;
color: #ecf0f1;
font-family: 'Cormorant Garamond', serif;
}
.name p {
font-family: 'Play', sans-serif;
font-size: 130%;
text-align: center;
padding-top: 5%;
color: #ecf0f1;
font-family: 'Merriweather', serif;
font-weight: 300;
padding-right: 10%;
padding-left: 10%;
}
/*------------------------------
Nav Bar
-------------------------------*/
.navigation p {
display: inline;
font-family: 'Play', sans-serif;
color: #ecf0f1;
}
.navigation {
text-align: center;
padding-top: 15%;
}
.contents,
.contents:hover {
text-decoration: none;
color: #ecf0f1;
font-family: 'Delius Unicase', cursive;
}
/*------------------------------------------------ ABOUT PAGE ------------------------------------------------------------------*/
/*------------------------------
About Heading
-------------------------------*/
#about {
background-color: black;
background-size: cover;
height: 100%;
}
#header {
height: 100%;
}
<section id="header"> <!------------------------- HOME PAGE -------------------------->
<div class="container">
<div class="row">
<div class="col-xs-12 name">
<h1>Temple Naylor</h1>
</div>
</div>
<div class="row">
<div class="col-xs-12 name">
<p>I create Web-designs with a sense of Feng-Shui in mind; resulting for a intuitive, responsive, harmonious, experience for users across the world.</p>
</div>
</div>
<div class="row">
<div class="col-xs-12 navigation hidden-sm-down">
<p><a class="contents" href="#">ABOUT</a> / </p>
<p><a class="contents" href="#">WORK</a> / </p>
<p><a class="contents" href="#">CONTACT</a> / </p>
<p><a class="contents" href="#">PHOTOGRAPHY</a></p>
</div>
</div>
</div>
</section>
<section id="about"> <!------------------------- ABOUT PAGE -------------------------->
<div class="container">
<div class="row about">
<div class="col-md-6">
<p class="big-text"></p>
</div>
</div>
<div class="row">
<div class="col-md-6 about-text">
<p >Yup</p>
</div>
</div>
</div>
</section>
You can use css vh property for this.
#header {
height: 100vh;
}
here is more info about css units. Hope this helps you.
change #header height to min-height:
#header {
min-height: 100%;
}

White space/ bar at the bottom of the page

I noticed that my web page has a white space/bar right after the footer and at the bottom of the page:
I tried to find the cause of this by using the inspect element in Chrome and can't find anything. I'm using Boostrap and here's my footer HTML/CSS:
<div class="container">
<hr>
</div> <!--end container-->
<div id="footer">
<footer class="container">
<div class="row">
<div class="col-md-3" id="mail"> <img src="images/mail.png" alt="e-kiri" title="Kirjuta mulle!"/>
<p>info#8delfiini.ee</p>
</div>
<div class="col-md-3" id="tel"> <img src="images/phone.png" alt="telefon" title="Helista mulle!"/>
<p>(+372) 52 99 131</p>
</div>
<div class="col-md-3" id="addr"> <img src="images/location.png" alt="asukoht" title="Asukoht"/> <a href="https://goo.gl/maps/ny3wV" title="Asukoht" target="_blank">
<p>Jansuki Shop<br />
Müürivahe 17<br />
Tallinn </p>
</a> </div>
<div class="col-md-3" id="fb"> <img src="images/fb.png" alt="Facebook" title="Facebook"/> <a href="https://www.facebook.com/8Delfiini" title="Facebook" target="_blank">
<p>8 Delfiini Facebookis</p>
</a> </div>
</div>
<!--end row-->
</footer>
</div>
<!--end footer-->
And the CSS for the whole contact page:
/*kontakt*/
#kontakt
{
background: url(../images/IMG_1340.jpg) no-repeat fixed;
width: 100%;
margin-bottom: 0;
}
h2.cont-heading
{
background: url(../images/kontakt.png) no-repeat 0 155px;
background-size: 48.5px 53px;
padding: 160px 0 5px 60px;
color: rgb(255,255,255);
text-transform: uppercase;
}
h1.invitation
{
font-family: 'latoregular', sans-serif;
color: rgb(255,255,255);
font-size: 7em;
}
#logo
{
width: 28px;
height: 40px;
margin-top: 10px;
}
#part3, #part4
{
padding: 40px 40px 40px 0;
}
#part4
{
padding: 30px;
color: rgb(255,255,255);
}
hr
{
border: 0;
height: 1px;
margin: 0;
background-image: -webkit-linear-gradient(left, rgba(255,255,255,0.4), rgba(255,255,255,0.75), rgba(255,255,255,0.4));
background-image: -moz-linear-gradient(left, rgba(255,255,255,0.4), rgba(255,255,255,0.75), rgba(255,255,255,0.4));
background-image: -ms-linear-gradient(left, rgba(255,255,255,0.4), rgba(255,255,255,0.75), rgba(255,255,255,0.4));
background-image: -o-linear-gradient(left, rgba(255,255,255,0.4), rgba(255,255,255,0.75), rgba(255,255,255,0.4));
}
/*footer styles*/
#footer
{
padding: 40px;
color: rgb(255,255,255);
text-align: center;
}
#footer a
{
color: rgb(255,255,255);
font-size: 1.3em;
}
#mail img, #tel img, #addr img, #fb img
{
height: 60px;
width: 60px;
display: block;
margin: 0 auto;
}
#mail a, #tel a, #addr a, #fb a
{
padding: 50px;
font-family: 'latoregular', sans-serif;
}
I'm new to Bootstrap. Is there maybe something special in its CSS that causes this? Thank you for your help. :)
You can fix it by setting a padding for the #footer .row:
#footer .container .row {
padding-bottom:8px;
}
Beautiful layout btw :)
This kind of things has mostly to do with not setting the body style:
body
{
margin: 0;
padding: 0;
}
It can also happen that you have set the heights of other elements wrongly.
It's a good practice to reset all the predefined styles, see http://www.cssreset.com/
And just to be sure; your background image is big enough, right?