Background image isn't displaying full resolution - html

I have a background image that's about 1200 (w) x 800 (h) but i just want to use the whole 100% resolution for it. I have a button inside this div container but it's not displaying correctly. The background image won't expand to it's full resolution. It seems like it's only showing enough to allow the button to show.
.endFoot {
background-image: url('https://via.placeholder.com/900x900');
background-size: cover;
width: 100%;
height: 100%;
}
.customButton {
position: relative;
bottom: 0;
left: 41%;
padding: 25px 35px;
font-size: 16px;
cursor: pointed;
text-align: center;
text-decoration: none;
outline: none;
color: #fff;
background-color: #AB0002;
border: none;
border-radius: 15px;
}
<div class="endFoot">
<button class="customButton">TEXT</button>
</div>
here's a little picture demonstrating what's going wrong vs what i want:

This has nothing to do with background image not expanding. Your div is simply not tall enough to show more of the image. Going off of your diagram, you want to add some padding to .endFoot.
background-size: cover; is a good choice, but you may also want to consider centering the position with background-position: 50% 50%;.
.endFoot {
background-image: url('https://via.placeholder.com/900x900');
background-size: cover;
background-position: 50% 50%;
width: 100%;
background-repeat: no-repeat;
padding: 400px 0 0 0;
height: 100%;
}
.customButton {
position: relative;
bottom: 0;
left: 41%;
padding: 25px 35px;
font-size: 16px;
cursor: pointed;
text-align: center;
text-decoration: none;
outline: none;
color: #fff;
background-color: #AB0002;
border: none;
border-radius: 15px;
}
<div class="endFoot">
<button class="customButton">TEXT</button>
</div>

If you would like the endFoot div to have the same height as the background, just set the height to 800px, because 100% doesn't change anything in this case.
Also set the endFoot position to relative in order to put the botton to the correct position.

If you are trying to achieve full screen background try :
.endFoot {
width: 100vw;
height: 100vh;
}
For browser support informations of vh and vw units check : https://caniuse.com/#feat=viewport-units

Just add text-align:center to .endFoot class to make center button and add some margin to .customButton class for leave some space to bottom.
.endFoot {
background-image: url('https://via.placeholder.com/900x900');
background-size: cover;
background-position: 50% 50%;
width: 100%;
background-repeat: no-repeat;
padding: 400px 0 0 0px;
height: 100%;
position: relative;
text-align: center;
}
.customButton {
padding: 25px 35px;
font-size: 16px;
cursor: pointed;
text-align: center;
text-decoration: none;
outline: none;
color: #fff;
background-color: #AB0002;
border: none;
border-radius: 15px;
margin-bottom: 10px;
}
<div class="endFoot">
<button class="customButton">TEXT</button>
</div>

Related

How to place a button over a shape in CSS?

I am creating a website with a login and sign in feature, and want to place the buttons over a solid dark blue background above the gradient but below the buttons. When I try to create a shape, the buttons move down on the website to accommodate room for it, but I want the shape to be on a layer below the buttons but still visible. Is there any way of doing this in CSS?
If so, how? Thanks :)
Here is my CSS and HTML so far:
HTML:
html {
height: 100%;
background-size: cover;
background: #a5fcff;
background-repeat:no-repeat;
background: linear-gradient(#00033a, #a5fcff);
}
.signinbutton {
background-color: #458af9;
border: none;
color: white;
padding: 15px 32px;
text-align: center;
display: block;
font-size: 75px;
margin: 4px 2px;
cursor: pointer;
transition-duration: 0.5s;
margin-left: auto;
margin-right: auto;
margin-top: 225px;
}
.signinbutton:hover {
background-color: #a7acb7;
}
.createaccbutton {
background-color: #458af9;
border: none;
color: white;
padding: 15px 32px;
text-align: center;
display: block;
font-size: 75px;
margin: 4px 2px;
cursor: pointer;
transition-duration: 0.5s;
margin-left: auto;
margin-right: auto;
margin-top: 100px;
}
.createaccbutton:hover {
background-color: #a7acb7;
}
<html>
<head>
<title>Debate Website</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class = "square"></div>
<button class = "signinbutton">SIGN IN</button>
<button class = "createaccbutton">SIGN UP</button>
</body>
</html>
UPDATE:
Sorry, I want the website screen to look like this:
Login Screen mock-up
But it currently looks like this:
Actual login screen so far
Use position: absolute; as mentioned above. If you end up with something on top of another (covering up the thing underneath) then you can use z-index: [number]; to specify what is on top of what.
You can position the element absolute relative to the html or another container.
example style:
.square {
position: absolute;
top: 0;
margin-left: auto;
height: 200px;
width: 200px;
background: #f00;
margin-right: auto;
left: 0;
right: 0;
}
Working example
1) First, edit your html, body style.
html {
height:100%
}
body {
background: #a5fcff;
background: linear-gradient(#00033a, #a5fcff); /* background first, followed by the other options */
background-size: cover;
background-repeat:no-repeat;
background-attachment: fixed /* for repeating gradient */
}
2) Customize .square element if you want.
.square {
position: absolute;
top:0; /* above the gradient */
left:0;margin-left:auto;right:0;margin-right:auto; /* center position:absolute element */
height: 200px;
width: 200px;
background: #0000ff
}
4) Add one margin line for buttons and remove others.
.signinbutton {
margin: 225px auto 0 auto; /* 225px for top, auto for right&left, 0px for bottom */
}
.createaccbutton {
margin: 100px auto 0 auto; /* 100px for top, auto for right&left, 0px for bottom */
}

slogan and background image attach responsively

I am trying to design such header where the slogan and background image are attached in the stated picture. I want to use flex to make it work but it is not working. Giving width breaks the responsiveness. I have created a jsbin to show the demo and here it is
http://jsbin.com/muguwavosa/edit?html,css,output
The source code
.header {
display: flex;
flex-direction: column;
background-image: url('https://www.rj-investments.co.uk/wp-content/uploads/2018/02/Home-Featured.jpg');
background-size: cover;
background-repeat: no-repeat;
background-position: center center;
background-attachment: fixed;
padding: 100px 0;
}
.slogan-wrapper {
background: #fff;
padding: 80px 0 0 40px;
margin-top: 70px;
}
.slogan-text > h1 {
font-size: 3.375rem;
font-weight: 900;
letter-spacing: 5px;
color: #373f48;
}
.slogan-text {
padding: 100px 70px 100px 0;
position: relative;
background: #fff;
z-index: 1;
}
<div class="header">
<div class="slogan-wrapper grid">
<div class="slogan">
<div class="slogan-text">
<h1>Hustle, Loyalty, Respect</h1>
</div>
</div>
</div>
This is what I wanted exactly and its a full width header
Did you notice that the class 'span' div is closed with a p tag? If you wanted to put the width there then that would be the problem.
Change the below code in CSS file and try once.
.header {
display: flex;
flex-direction: column;
background-image: url('https://www.rj-investments.co.uk/wp-content/uploads/2018/02/Home-Featured.jpg');
background-size: cover;
background-repeat: no-repeat;
background-position: center center;
background-attachment: fixed;
padding: 100px 0;
}
.slogan-wrapper {
margin-top: 70px;
}
.slogan-text > h1 {
font-size: 3.375rem;
font-weight: 900;
letter-spacing: 5px;
color: #373f48;
background-color: #fff;
padding: 80px 40px;
width: auto;
max-width: 319px;
}
.slogan-text {
padding: 100px 30px 100px 0;
position: relative;
z-index: 1;
}

How to squash a div vertically and keep element below 100% on screen

So I have this code here: http://jsfiddle.net/nUwgX/ which has a little arrow at the bottom. What I'd like to happen is when the window get's resized is to keep the arrow about 15% from the bottom of the screen but I'm not sure how I'd do that. Any help would be appreciated.
HTML:
<div class = "container">
<div class = "top-wrapper">
<a id = "name" href = "#">Bigfoot Games</a>
</div>
<div class = "bottom-wrapper">
<p>Content</p>
</div>
</div>
CSS:
.container {
width: 100%;
height: 100%;
margin: 0 auto;
position: relative;
padding: 0;
text-align: center;
}
.top-wrapper {
position: relative;
background: #0f0f0f;
height: auto;
height: 100%;
max-height: 900px;
width: 100%;
margin: 0 auto;
padding: 0;
display: table;
}
.top-wrapper:after {
top: 100%;
left: 50%;
border: solid transparent;
content: " ";
height: 0;
width: 0;
position: absolute;
pointer-events: none;
border-color: rgba(15, 15, 15, 0);
border-top-color: #0f0f0f;
border-width: 30px;
margin-left: -30px;
}
#name {
display: table-cell;
text-align: center;
vertical-align: middle;
padding: 20px;
color: white;
font-size: 80px;
text-decoration: none;
margin: auto 0;
}
.bottom-wrapper {
background: white;
margin: 0 auto;
padding: 20px;
}
Edit: Okay, so saying that I wanted the arrow about 15% above is not what I meant! Ha! What I mean is, I want the .top-wrapper to be 100% so that it covers the whole window, and you scroll down to see the .bottom-wrapper - however when the screen is resized (other than my 1920 x 1080 resolution) the arrow get's hidden just out of sight, what I'd like is the arrow to be visible regardless of resolution and have the look (in terms of padding/distance) as a 1920 x 1080 resolution.
Change the css of .top-wrapper to only take up 85%, that leaves 15% for the "arrow" on the bottom to take up.
.top-wrapper {
...
height: 85%;
...
}
see the jsfiddle:
http://jsfiddle.net/nUwgX/1/
Change your .top-wrapper height to 85%
I changed just that in the jsfiddle and it maintains when the screen is resized. If that isn't what you are looking for, please elaborate on the question.
Good Luck!
If you want to keep your bottom-wrapper at the bottom fixed position ...
Replace your .bottom-wrapper class with below
.bottom-wrapper {
position:fixed;
bottom: 0px;
height: 15%;
width: 100%;
background-color: white;
margin: 0 auto;
}
.bottom-wrapper p{
padding-top: 20px;
}
Then change .top-wrapper:after to .bottom-wrapper:before

background image inline with text

I have an image 200px x 100px which acts as a background image to a link.
On hovering, the bg image changes.
Fiddle here: http://jsfiddle.net/EnsFK/
As you can see from the image, the text is not aligned with the image and appears at the bottom. Is there a way to align the text so it is in the middle (Aligned with the small dot?) I've tried vertical-align and
line-height but to no avail.
.current-location {
line-height: 24px;
background-size: 48px 24px;
height: 24px;
width: 24px;
text-decoration: none;
position: relative;
line-height: 24px;
vertical-align: middle;
}
.current-location span {
background: url(images/mobile/current-location.gif) left top no-repeat;
display: inline-block;
background-position: 0px 0px;
background-size: 48px 24px;
height: 24px;
width: 24px;
margin-right: 10px;
}
.current-location:hover span {
display: inline-block;
background-position: -24px 0px;
background-size: 48px 24px;
height: 24px;
width: 24px;
}
Rather than using an empty span in your markup, you could use pseudo elements.
Something like this:
.current-location:before {
content: '';
/* image here */
margin-right: x px; /* however much you need */
vertical-align: middle;
}
FIDDLE
Markup:
Use this location
CSS
.current-location {
line-height: 24px;
background-size: 48px 24px;
height: 24px;
width: 24px;
text-decoration: none;
position: relative;
}
.current-location:before {
content: '';
background: url(http://i39.tinypic.com/2lk5lci.png) left top no-repeat;
display: inline-block;
background-position: 0px 0px;
background-size: 48px 24px;
height: 24px;
width: 24px;
margin-right: 10px;
vertical-align: middle;
}
.current-location:hover:before {
background-position: -24px 0px;
}
You can either change the line-height of the text to fit the image's location, or play with background-position property for the image's position to fit it to the text.
Working jsFiddle - also removed some of the unnecessary code.
.current-location {
line-height: 24px;
height: 24px;
text-decoration: none;
position: relative;
line-height: 26px;
display:inline-block;
}
.current-location span {
background: url(http://i39.tinypic.com/2lk5lci.png) left top no-repeat;
display: inline-block;
background-position: 0px 0px;
background-size: 48px 24px;
height: 24px;
width: 24px;
margin-right: 10px;
vertical-align:top;
}
.current-location:hover span {
background-position: -24px 0px;
}
Note: this is usually done without the <span> element using background on the anchor itself. However you method will work just as fine with the new CSS..
I like to use this css snippet for vertical centering
#text{
position:absolute;
top:50%;
height:240px;
margin-top:-120px; /* negative half of the height */
}
#container {
position: relative;
height: 400px;
}
<div id="container">
<div id="text"><span>Text.....</span></div>
</div>
Your link is aligned properly look at your image instead
background: url(images/mobile/current-location.gif) left top no-repeat;
If you want it to be center aligned you should consider doing...
background: url(images/mobile/current-location.gif) center center no-repeat;
Also give the true width and height of the image for this method to work.
display: inline-block;
has problems with ie6 you will need to use:
display:inline-block;
*zoom: 1;
*display: inline;
try and stay away from vertical alignment.
How about a version with no images and no extra markup? http://jsfiddle.net/6aaZX/
For this HTML:
Use this location
This CSS:
a {
display: inline-block;
color: #333;
text-decoration: none;
font-family: sans-serif;
padding-left: 4em;
line-height: 2;
}
a:before {
-webkit-border-radius: 50%;
-moz-border-radius: 50%;
border-radius: 50%;
background: #81B995;
content: '';
display: inline-block;
width: 0.7em;
height: 0.7em;
border: 0.4em solid #B7E2C8;
margin-right: 1em;
vertical-align: -0.3em;
}
It requires support for border-radius, but that's it - nothing fancy otherwise. If you did need to use an image, you could apply it to the :before pseudo element, as suggested by Danield

Adding an image hover to a link

I have the following image with dimensions of 200px w x 100px h. Basically, I need the link to look like this
* link
where * is the image. The hover state should kick in when both the image and link are hovered on. My html & css is as follows, but it doesn't seem to work:
Us this location
.current-location {
background-position: 0 0px;
background: url(images/current-location.png) left top no-repeat;
background-size: 48px 24px;
height: 24px;
width: 24px;
text-decoration: none;
}
.current-location:hover {
background-position: -24px 0px;
background-size: 48px 24px;
height: 24px;
width: 24px;
}
I think a better solution would be not to use images at all:
add a span in the <a>:
<span>*</span> Us this location
Style it to show on hover:
.current-location {
background-size: 48px 24px;
height: 24px;
width: 24px;
text-decoration: none;
position: relative;
padding-left: 20px;
}
.current-location span {
display: none;
color: red;
position: absolute;
left: 0;
}
.current-location:hover span {
display: inline-block;
background-position: -24px 0px;
background-size: 48px 24px;
height: 24px;
width: 24px;
}
SEE FIDDLE
Maybe you should try to set display: block to the .current-location class. Also I don't think that Us this location will be nicely put in 24px by width.