Position fixed throws off background image - html

I need to have some text go over a background image. Looking around it seems like the way to do it is like this:
<div align="center" style="">
<h1>About Us</h1>
some text and more for the sub headline
<br/><br/>
<img src="aboutbg.jpg" style="width:500px; position:fixed; z-index:-1;" />
<div style="width:500px; position: relative; z-index:1;" >
About Us
</div>
</div>
but something seems to be off with the position:fixed of the <img>, and it's not centered correctly. The end result is:
What am I missing?

It's obeying the text-align statement you have on an ancestor element. You'll need to set its left position to 0, and possibly top as well.
It would probably be better to make the background an actual background.
.content {
text-align: center;
background-image: url(http://lorempixel.com/1200/800/nature);
background-size: contain;
background-repeat: no-repeat;
background-position: center center;
overflow: hidden;
min-height: 400px;
color: yellow;
}
<div class="content">
<h1>About Us</h1> some text and more for the sub headline
<br/>
<br/>
<div style="width:500px; position: relative; z-index:1;">About Us</div>
</div>

Here it is with inline styles.
<div style="background:url('aboutbg.jpg') no-repeat;width:500px;text-align:center;">
<h1>About Us</h1>
<p>some text and more for the sub headline</p>
<br/>
<br/>
<ul style="list-style:none;">
<li style="border-right:1px solid #000;display:inline;margin-right:7px;padding-right:7px;">About Us</li>
<li style="border-right:1px solid #000;display:inline;margin-right:7px;padding-right:7px;">Terms</li>
<li style="display:inline;">Contact</li>
</ul>
</div>

Related

Why is position: fixed creating whitespace when I use it?

So I have been busy with a navbar and I want to make it fixed but whenever I use position: fixed, the navbar does stay fixed but it creates whitespace and pushes everything down (the parent container and it's sister elements).
So what could be causing this and how do I solve this issue?
Thanks in advance for your help.
Screenshot of how it looks with the issue
The HTML
The CSS
nav {
padding: 15px;
position: fixed;
width: 100%;
z-index: 1;
top: 0;
}
.hero-section {
background-image: url(img/dylann-hendricks-Ll-A9nKuOhk-unsplash.jpg);
background-size: cover;
background-repeat: no-repeat;
background-position: 0px 0px;
height: 100vh;
}
<pre>
<code>
<section class="hero-section">
<nav class="navbar">
<div class="logo">KM</div>
<div class="links-container">
<div>About</div>
<div>Skills</div>
<div>Projects</div>
</div>
</nav>
<div class="intro-container">
<div class="greeting rev-block"><span>Hi there,</span></div>
<div class="my-name rev-block" id="onemore1">
<span>I'm Khanya Mateta</span>
</div>
<div class="job-title rev-block" id="onemore2">
<span>Front End Developer</span>
</div>
<div class="contact-btn">Contact Me</div>
<div class="social-media">
<img src="img/github.png" />
<img src="img/linkedin.png" />
<img src="img/twitter.png" />
</div>
</div>
<div class="box">
<span></span>
<span></span>
<span></span>
</div>
</section>
</code>
</pre>
Try using this in the css for nav element:
left: 0;
right: 0;
Adjust the left and right values while using position: fixed.
Using this I solved the same issue in my site.
Thank you 😊.

How to display an element underneath another element?

I am trying to place my social and email links found with a ul additional-menu, to be displayed under my site's logo and tagline. I seem to be struggling getting it underneath. At the moment it looks like this:
The code below is like so:
.additional-menu {
list-style-type:none;;
margin: 0;
position:relative;
clear:both
}
.additional-menu li{
display:inline-block;
}
.ast-header-html-1{
position:relative;
clear:both;
}
<div class="ast-site-title-wrap">
<h1 class="site-title" itemprop="name">
<a href="https://puffpastrydelights.com/" rel="home" itemprop="url">
Pastry Delights
</a>
</h1>
<p class="site-description" itemprop="description">
Made with love, served with pride
</p>
</div>
<div class="ast-builder-layout-element ast-flex site-header-focus-item ast-header-html-1" data-section="section-hb-html-1">
<div class="ast-header-html inner-link-style-">
<div class="ast-builder-html-element">
<ul class="additional-menu">
<li></li>
<li></li>
<li></li>
</ul>
</div>
</div>
</div>
Wrap the whole thing with div that has display:flex and flex-direction: column
.wholeThing {
display: flex;
flex-direction: column;
border: 1px solid red;
}
.firstBit {
display: flex;
border: 1px solid blue;
}
<div class="wholeThing">
<div class="firstBit">
<div class="logo"><img src="http://placekeanu.com/250" /></div>
<div class="tagline">Keanu is breath taking</div>
</div>
<div class="social">
social one two three
</div>
</div>
`

Position 4 Images Vertically Responisively No Padding

I just want to thank everyone for being so helpful, I would of never learnt so much if it wasn't for your guys continual helpfulness.
I'm trying to make a 4 way vertical "collage" of some images without spaces between each picture that is fully responsive when resizing the window and such. The problem I'm having is with space between each photo; I'm trying to figure out how to allow no space between each.
I also encounter a problem when resizing the window to be smaller in which the images flow away from the lion image above and make more white space or padding without sticking to the lion image. It also starts to overlap the lion image when resizing to a bigger size.
.image {
background-image: url(https://s-media-cache-ak0.pinimg.com/originals/31/91/d7/3191d75f03ba7d4c570358870c855ed7.jpg);
background-repeat: no-repeat;
height: 850px;
background-size: 100%;
}
#collage {
width: 90%;
}
<div class="image">
<ul id="nav">
<li id="brand">MINIMAL</li>
<li id="navm">Men</li>
<li id="navm">Women</li>
<li id="navm">Contact</li>
</ul>
<h1>Simplicity is Minimal</h1>
<div id="home">
Shop Now
</div>
</div>
<div class="row">
<div class="col-md-3" align="center">
<img id="collage" src="https://upload.wikimedia.org/wikipedia/commons/2/27/Panthera_tiger_in_a_marshy_area_in_captivity.jpg">
</div>
<div class="col-md-3" align="center">
<img id="collage" src="https://upload.wikimedia.org/wikipedia/commons/2/27/Panthera_tiger_in_a_marshy_area_in_captivity.jpg">
</div>
<div class="col-md-3" align="center">
<img id="collage" src="https://upload.wikimedia.org/wikipedia/commons/2/27/Panthera_tiger_in_a_marshy_area_in_captivity.jpg">
</div>
<div class="col-md-3" align="center">
<img id="collage" src="https://upload.wikimedia.org/wikipedia/commons/2/27/Panthera_tiger_in_a_marshy_area_in_captivity.jpg">
</div>
</div>
You need to just add below css and I hope it works.-
*{
margin:0px;
padding:0px;
}
.image {
height: auto;
}
body img {
display: block;
}`

Fix position of responsive image in responsive header, next to text

The idea of this is to have a responsive header with text and an image element, which sit on a fixed background image.
I've tried to do this with bootstrap columns, which works on desktop to come out the way I want it. On smaller devices however, the bootstrap media queries do exactly what they are supposed to do and break the columns up to be displayed below each other.
I am out of ideas for this. I know I need to fix the image element somehow to stay consistently on the bottom end of the container, but since the entire thing is responsive I have no idea how to accomplish that.
Here is what I have so far, but this is not the solution. I appreciate any suggestions.
<section class="section swatch-black section-text-shadow section-inner-shadow">
<div class="background-media" style="background-image: url('http://some-url.com/home-intro.jpg'); background-repeat: no-repeat; background-size: cover; background-attachment:fixed; background-position: 50% 60%;"> </div>
<div class="container">
<div class="row">
<div class="col-md-6 text-left element-normal-top element-normal-bottom">
<h1 class="bigger hairline bordered-normal element-tall-top"> Header Text<br>
<strong>More Text </strong> </h1>
<p class="lead"> Even more text </p>
learn more
contact us </div>
<div class="col-md-6 text-right">
<img src="assets/images/uploads/test.png" style="position:relative; right: 0px; bottom: 0px; top: 150px;">
</div>
</div>
</div>
</section>
you can set up your own column structure. Here's an example that I made for you real quick:
http://jsfiddle.net/97wswqvr/
this will need more work obviously, depending on the rest of your header text/buttons etc... but its a good place to start
html
<header>
<div class='content col col-1-2'>
<div>
text text text
</div>
<div>
text text text
</div>
<div>
text text text
</div>
</div>
<div class='col col-1-2 img'>
<img class='col' src='http://store.storeimages.cdn-apple.com/8459/as-images.apple.com/is/image/AppleInc/aos/published/images/i/ph/iphone/compare/iphone-compare-bbh-201411?wid=254&hei=210&fmt=png-alpha&qlt=95&.v=1416449205305'/>
</div>
</header>
css
html,body {
margin: 0;
}
header {
background-image: url(http://wowslider.com/sliders/demo-85/data1/images/southtyrol350698.jpg);
text-align: center;
}
.content {
color: white;
padding: 40px 0;
}
.col {
display: inline-block;
vertical-align: middle;
}
.col-1-2 {
width: 45%;
}
.img {
}
img {
width: 70%;
}

My css sprites are not showing up at all, I have tried everything

I am new here and just learning to code a website, so far I had hit a snag. When I try to use my background: url(../images/sprite.png) it does not seem to work, I got it to work on my navigation bar, but when I try to do it on my billboard section area it does not want to work with me at all. Here is my HTML
<div id="container_header">
<div id="container_header2">
<div id="ram_logo">
<a href="#">
<img src="images/ram_logo.png" border="0" alt="logo" />
</a>
</div>
<div id="menu">
<ul>
<li id="features"><span>Features & Specs</span></li>
<li id="photos"><span>Photo Gallery</span></li>
<li id="brochure"><span>Brochure</span></li>
<li id="getaquote"><span>Get A Quote</span></li>
</ul>
</div>
<div class="clear">
</div>
</div>
</div>
<div id="container_billboard">
<div id="truck_home">
</div>
<div id="billboard_title">
<p id="title_allnew">THE ALL NEW</p>
<p id="title_ram">2013 Ram 1500</p>
<p id="title_laramie">Laramie Longhorn </p>
<p id="title_starting">Starting at</p>
<p id="title_price">$20,500</p>
<div class="clear"></div>
<div id="title_getaquote">
<a href="#">
</a>
</div>
</div>
<div class="clear">
</div>
</div>
now the elements I am wanting to target are: <div id="truck_home"> and <div id="title_getaquote">
<a href="#">
</a>
</div>
here is my css:
#truck_home {
background-image: url(/images/sprite.png) no-repeat 0px -69px;
margin-top: -20px;
margin-right: -150px;
float: right;
height: 293px;
width: 655px;
}
#title_getaquote {
background-image: url(/images/sprite.png) no-repeat -163px -365px;
text-align: left;
margin-top: 20px;
margin-left: 165px;
}
so I am not sure what I am doing wrong here, I tried doing background-position: 0 0
please if anyone can help it would be really appreciated. I have been trying to figure this out for a few hours now...
In your CSS, use background: ... instead of background-image: ....
Demo
http://jsfiddle.net/raunakkathuria/MA8pN/
If you are using background-image don't include no-repeat -163px -365px in it, because background-image is for specifying url only, in this case you have to individually specify
background-repeat: no-repeat
background-position:-163px -365px;
or just update background-image as said by DXL also