stop image jumping out of position when screen size reduced - css

When I reduce screen size after running the code below, the image phone.png and all the text jump out of position. How can I stop this from happening.
css:
<style type="text/css">
#wrapperlp {
width: 100%;
height:700px;
margin-left:13%;
margin-top:5%;
background-image:url(https://***/blackbg.png);
background-repeat:no-repeat;
opacity:1;
}
#designbg {
background-repeat:no-repeat;
margin-left: 5%;
padding-top: 3%;
}
styling for text
#ad_head {
color: #f2852d;
font-weight: bold;
margin-left: 28%;
margin-top: -21.5%;
font-size: 21px;
}
#ad_message {
margin-left: 28%;
font-size:10px;
color:white;
font-weight:normal;
}
style for phone.png image:
#ad_logo {
height: 500px;
margin-left: 2%;
margin-top: -42%;
}
#logobtm {
margin-left: 2%;
margin-top: -42%;
}
</style>
Html:
<div id="wrapperlp">
<div id="designbg"><img src="https://*****/image.png" />
<div id="ad_logo"><img src="https://****phone.png" /></div>
<div>
<div id="ad_head">Text1<br />Text...</div>
<div id="ad_message">Text2</div>
<div id="logobtm"><img src="**.png" /></div>
</div>
</div>
</div>

You are using margin-top in percentages. However, percentages for margins are measured relatively to the window width, not the window height!
See http://www.w3.org/TR/CSS2/box.html#value-def-margin-width
Solution: use another unit to express the margin of the elements in, or use another way to position them on the screen (for instance top:5% in combination with position:absolute).

Related

How do I make div background color certain size with contents having position absolute?

I'm trying to make a div have a background color with a specific size, but whenever i put position absolute on the content inside of the div it removes the background color.
Heres an image of what i'm trying to do:
[![enter image description here][1]][1]
* {
font-family: 'Poppins', sans-serif;
}
.background {
position: relative;
background: #DFEDFF;
height: 100%;
width: 100%;
}
.hero-text {
position: absolute;
top: 50%;
transform: translateY(-50%);
}
.title {
font-size: 8.4375rem;
font-weight: 800;
line-height: 130px;
margin: 0;
}
.description {
margin: 0;
font-size: 2.75rem;
font-weight: 300;
}
<div class="background">
<div class="hero">
<div class="hero-text">
<h1 class="title">Hello,<br>I'm Ian</h1>
<p class="description">Website coming soon.</p>
</div>
<img class="callum" src="images/callum.png" alt="">
</div>
</div>
When you make an element position:absolute; it's width/height will no longer influence the width and height of it's parent element. The div's height is defined by its child if there is no set height specified (100% doesn't really work, thats just css magic for you).
If there is no child to give it a height (because it has been discounted because it is now position:absolute;) you need to set a specific px height for your div eg height:100px
I Applied min-height to main_container 410px and then both set absolute ,background div and hero-text
,hero-text setup in center just like you already did and then set left 100px to background so it will start setting up background by leaving 100px space, top:10px ,bottom:10px,right:10px so on....
.main_container{
min-height:410px;
width:100%;
position:relative;
}
.title {
font-size: 8.4375rem;
font-weight: 800;
line-height: 130px;
margin: 0;
}
.description {
margin: 0;
font-size: 2.75rem;
font-weight: 300;
}
.background{
position:absolute;
top:10px;
bottom:10px;
left:100px;
right:10px;
content:'';
display:block;
background:#DEEDFE;
z-index:-1;
}
.hero-text {
position: absolute;
top: 50%;
transform: translateY(-50%);
}
<div class="main_container">
<div class="background"></div>
<div class="hero-text">
<h1 class="title">Hello,<br>I'm Ian</h1>
<p class="description">Website coming soon.</p>
</div>
</div>
https://jsfiddle.net/3pL5srvq/1/
the background will auto growth height by hero-text.
calc(25% - 4rem) means a position to center and offset-top by padding space(3rem) + balance height up to you, I just set to 1rem
25% to center
-4rem (remove padding-top space(3rem) + balance offset-top(1rem))
* {
font-family: 'Poppins', sans-serif;
}
.background {
position: relative;
background: #DFEDFF;
width: 80%;
margin: 0 auto;
}
.hero-text {
transform: translate(-5% , calc(25% - 4rem));
padding: 3rem 0;
}
p.description {
margin: 0;
}
<div class="background">
<div class="hero">
<div class="hero-text">
<h1 class="title">Hello,<br>I'm Ian</h1>
<p class="description">Website coming soon.</p>
</div>
<img class="callum" src="images/callum.png" alt="">
</div>
</div>

Fixed position stop the element to fill the parent containber

I am facing a problem with fixed position. I have two rows on top of each other and I want them to look like this:
which is what I want. Now because I need to use position fixed in my project to have the second row docked I changed the position to fixed. here is my css file:
.header {
font-weight: bold;
background-color: #4070CB;
color: #EFF0F2;
height: 5vw;
padding-top: 15px;
}
.story-board-header {
font-weight: bold;
background-color: #072e77;
color: #EFF0F2;
height: 3vw;
padding-top: 15px;
position:fixed;
}
Now here is what I get :
As you see the second div does not fill all its container.
Also here is my jsfiddle:
jsfiddle
Can anyone help?
Just use width: 100%.
* {
margin: 0;
padding: 0;
}
.header {
font-weight: bold;
background-color: #4070CB;
color: #EFF0F2;
height: 5vw;
padding-top: 15px;
}
.story-board-header {
font-weight: bold;
background-color: #072e77;
color: #EFF0F2;
height: 3vw;
padding-top: 15px;
position: fixed;
width: 100%;
}
<div class="container-fluid">
<div class="row header">
<div class="col-xs-12">
</div>
</div>
<div class="row" style="position:relative;">
<div class="col-xs-12 story-board-header">
eweweweewew
</div>
</div>
</div>
You forgot to link bootstrap.css to project:
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
https://jsfiddle.net/pb7vptm8/1/
I am not 100% sure of what you are trying to accomplish.
Position fixed makes the element relative to the browser window and not it's container (source).
You can use both width: 100% or left: 0; right: 0; to make the element as width as the whole screen.
Fixed also causes the element to stay in place when you scroll the page. Is that what you want?

Can't align css elements

I am trying to code a website using CSS. My header looks like this below. It is consisted of two child divs - logo and topright. Whenever I minimize the width of the screen, topright gets shunted downwards onto the next row. The two divs are floated left and right respectively, and should share the same row. However, I do not want topright to be shunted to the next row. How can I fix this?
<div id="header">
<div id="logo">
<h1>Logo</h1>
</div>
<div id="topright">
<div id="phone">
<p>here</p>
<h6>Learn about out services</h6> </div>
<div id="ssl">
<img src="images/ssl.png" width="150" height="39" align="right" />
</div>
</div>
My css code is
#header {
width: 100%;
position:relative;
clear:both;
}
#logo {
float: left;
margin-top: 20px;
display: block;
}
#logo h1 {
text-indent: -2000px;
background:url(images/logo.png) no-repeat;
display:block;
}
#logo h1 a {
display:block;
width: 381px;
height: 97px;
}
#topright {
float: right;
margin-top: 20px;
display: block;
}
#phone {
float: left;
background:url(images/phone.png) no-repeat right;
height: 70px;
padding-top: 40px;
padding-right: 60px;
text-align:right;
}
#phone p {
font-weight:bold;
font-size: 1.4em;
}
#phone h6 {
font-weight:bold;
font-size: 0.8em;
color:#6F694F;
}
#ssl {
float: right;
margin-top: 40px;
margin-left: 20px;
}
Put min-width: 1000px into logo's css. This ensures that there is always 1000px, however hidden, that the topright div can fit inside even if it is off the screen.

How to overlap auto-scaling images with an auto-scaling background

I am trying to put images over a virtual whiteboard that sits in a scalable div.
I followed this guide to make the "whiteboard" scale: Stretch and scale CSS background
You can see the demo here: http://staging1.populearn.com/new.html
I can't figure out how I can move those red boxes over the whiteboard, and have them scale too. Is it even possible?
Cheers
Here is the HTML:
<div class="lesson-pane">
<div id="chalkboard-background">
<img src="/img/whiteboard_teacher.png" class="stretch" alt="" />
<div id="chalkboard">
<div id="chalkboard-images">
<span id="image1" class="33"><img src="/img/1.png" alt="" /></span>
<span id="image2" class="33"><img src="/img/2.png" alt="" /></span>
<span id="image3" class="33"><img src="/img/3.png" alt="" /></span>
</div><!--/chalkboard-images-->
</div><!--/chalkboard-->
</div><!--/chalkboard-background-->
</div><!--/lesson-pane-->
And here is the CSS:
.lesson-pane {
padding: 20px;
margin-bottom: 30px;
background-color: #f5f5f5;
background-image:url('/img/background_europe.png');
-webkit-border-radius: 6px;
-moz-border-radius: 6px;
border-radius: 6px;
border-style:solid;
border-width:3px;
max-width: 850px;
}
.lesson-pane h1 {
margin-bottom: 0;
font-size: 60px;
line-height: 1;
letter-spacing: -1px;
}
.lesson-pane p {
font-size: 18px;
font-weight: 200;
line-height: 27px;
}
#chalkboard {
position: relative;
}
#chalkboard-background {
width: 100%;
position: relative;
}
.stretch {
width:100%;
}
.33 {
width:33%;
}
#chalkboard-images {
position: relative;
width:100%;
}
If you're scaling, you need to ensure you're using the same kind of measurements, in this case percentages. Then, absolutely position your chalkboard on top of the graphic, then tell each of the three image container to take up 1/3 of it's space, and each image inside to stretch to 100%.
This is the CSS to make that work (in addition to your existing CSS, you could paste this after)
/* Make .lesson-pane use relative % padding */
.lesson-pane {padding:2%;}
/* Absolutely position ".chalkboard" over graphic (approx) */
#chalkboard {position:absolute; left:3%; top:5%; width:77%; height:75%;}
/* Make each image take up 1/3 of space and scale */
#chalkboard-images {white-space:nowrap; font-size:0px; text-align:center;}
#chalkboard-images > span {display:inline-block; width:31.3%; margin:1%;}
#chalkboard-images > span > img {width:100%; height:auto;}

Centering two divs in a div: one of fixed width and the other of variable width/height

I have a situation where I have one div of fixed width, containing an image pulled from Twitter, and another div of variable width containing user text of variable length. What I want to achieve is something like the following:
I can do this well enough with a single div that has background-image and padding-left. But I want to be able to apply border-radius to the img element, which simply won't be possible with a background-image.
If I do text-align: center on the outer div, it gets me halfway there. Here's a DEMO and a screenshot:
But this obviously isn't fully what I want.
How can I accomplish this?
Ask and you shall receive — a simplified jsFiddle example:
As an added bonus, the text is vertically centered too!
HTML:
<div class="logo">
<div class="logo-container">
<img src="http://img.tweetimag.es/i/appsumo_b.png" />
</div>
<div class="logo-name">
AppSumo is a really really long title that continues down the page
</div>
</div>
CSS:
.logo {
background-color: #eee;
display: table-cell;
height: 100px;
position: relative;
text-align: center;
vertical-align: middle;
width: 600px;
}
.logo-container {
background-color: #fff;
border-radius: 10px;
left: 10px;
position: absolute;
top: 10px;
width: 75px;
}
.logo-name {
font: bold 28px/115% Helvetica, Arial, sans-serif;
padding-left: 85px;
}
Would it be something like this?
http://jsfiddle.net/uPPTM/6/
.logo {
width:80%;
margin:auto;
background-color: red;
}
.logo-container {
border: 1px solid gold;
width:73px;
height: 73px;
display: inline-block;
vertical-align:middle;
}
.logo-name {
display: inline-block;
}
You can float the image container (or image itself without the container) to the left, clearing anything the left... and then float the text to the left, clearing anything to the right.
.logo-container{
float:left;
clear:left;
}
.logo-name{
float:left;
clear:right;
}
You can adjust the distance of the text using margins.
.logo-name{
float:left;
clear:right;
margin-top:10px;
margin-left:5px;
}
Use absolute positioning with a left position to push the title text past the image.
http://jsfiddle.net/uPPTM/9/
.logo { width: 50px; }
.title {
position: absolute;
top: 0;
left: 50px;
font-size: 32px;
text-align: center;
}
img {
border: 1px solid gray;
border-radius: 15px;
}
<div class="logo">
<div class="logo-container">
<img src="http://img.tweetimag.es/i/appsumo_b.png">
</div>
<div class="logo-name">AppSumo</div>
</div>

Resources