Image with background image not showing - html

Look at the following JSFiddle
.container {
width: 100%;
background-color: yellow;
}
.classic {
display: block;
position: relative;
margin-left: auto;
margin-right: auto;
background-position: center center;
background-image: url("http://www.pulsarwallpapers.com/data/media/3/Alien%20Ink%202560X1600%20Abstract%20Background.jpg");
background-size: contain;
background-repeat: no-repeat;
}
.classic-img {
display: block;
position: absolute;
overflow: hidden;
width: 100%;
height: 100%;
top: 0%;
left: 0%;
}
.classic-img img {
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
}
.top-menu {
width: 100%;
height: 50px;
position: relative;
background-color: red;
}
.top-menu-buttons {
position: absolute;
margin-left: auto;
margin-right: auto;
bottom: 0;
left: 0;
right: 0;
width: 50%;
text-align: center;
}
.top-menu-buttons .button {
display: inline-block;
vertical-align: middle;
font-size: 25px;
color: white;
}
.top-menu-buttons span {
display: inline-block;
vertical-align: middle;
font-size: 25px;
color: white;
}
.bottom-menu {
width: 100%;
height: 50px;
position: relative;
background-color: green;
}
.bottom-menu-buttons {
position: absolute;
margin-left: auto;
margin-right: auto;
bottom: 0;
left: 0;
right: 0;
width: 80%;
text-align: center;
}
.bottom-menu-buttons .button {
display: inline-block;
vertical-align: middle;
font-size: 35px;
color: white;
padding-left: 10px;
padding-right: 10px;
}
<div class="list">
<a class="item">
<div id="container" class="container">
<div class="top-menu">
<div class="top-menu-buttons">
<button>-</button>
<span>20</span>
<button>+</button>
</div>
</div>
<div id="classic" class="classic">
<div id="classic-img" class="classic-img">
<img src="http://bc03.rp-online.de/polopoly_fs/1.4643662.1415087612!httpImage/2100575733.JPG_gen/derivatives/d540x303/2100575733.JPG" />
</div>
</div>
<div class="bottom-menu">
<div class="bottom-menu-buttons">
<button class="button button-icon ion-eye">1</button>
<button class="button button-icon ion-refresh">2</button>
<button class="button button-icon ion-crop">3</button>
<button class="button button-icon ion-android-options">4</button>
<button class="button button-icon ion-social-tumblr">5</button>
</div>
</div>
</a>
</div>
CSS:
What i want to achieve is something like the following:
The red area should be a top menu. It should not be a fixed top position it should just always be on top of the image.
As you can see the image has a white background and a black forground. It should look like a polaroid.
The green area should be a menu at the bottom but also not fixed to the bottom it should just always be underneath the image. If there is not enough space it should simply scroll not clinch or esize any of the divs. I guess the main problem is the div in the middle where the image with the background image is.
I try for ages now to get the correct css but unfortunately im very unexperienced and all i can do at the moment is try and error but i cant get it working.

remove position: absolute from .classic-img and .classic-img img
add margin: 100px auto; adjust 100px as per your need, also you have set background-size: contain and the aspect ratio of bg image is almost equal to the image, therefore you would see only small portion of bg image here in the fiddle - jsfiddle.net/18vg13dt/3
additionally if you want gap from left and right also the use - margin: 100px 50px; similarly according to your needs.
jsfiddle

I guess this is what you want?
.classic {
background: url("http://www.pulsarwallpapers.com/data/media/3/Alien%20Ink%202560X1600%20Abstract%20Background.jpg")no-repeat center center;
background-repeat: no-repeat;
background-size: cover;
}
.classic-img {
padding: 10px;
box-sizing: border-box;
}
.classic-img img {
display:block;
width:100%;
height:100%;
}

You need to set the height for the class .classic-img
Try this :
.classic-img {
display: block;
position: relative; /*---absolute to relative*/
overflow: hidden;
width: 100%;
height: 100px; /*----Adjust the height---*/
top: 0%;
left: 0%;
}
If you still face the issue, do come back and let us know.

Related

DIV position with z-index

Good morning everyone
How can I place the different DIVs on top of each other?
I have a row that contains left and right DIVs.
In the right I have image and in the left text.
I also have a DIV that needs to be placed between the text and the background.
I've tried and gotten a few things, but I can't get the right DIV sticky-top in the right place.
I don't want to use Java but only CSS
.infosite-container {
margin: 0 auto;
width: 100%;
position: relative;
}
.infosite-container .row {
display: table;
}
.infosite-container [class*="col-"] {
float: none;
display: table-cell;
vertical-align: top;
}
.sticky-top {
height: 150px;
width: 150px;
position: absolute;
background: red;
top: 50%;
left: 50%;
z-index: 999;
transform: translate(-50%, -50%);
}
.infosite-left-content {
padding-top: 175px;
padding-bottom: 175px;
padding-left: 120px;
text-align: left;
background-image: url(../../images/img-01.jpg);
background-repeat: no-repeat;
background-size: cover;
background-position: center center;
min-height: 680px;
/* height: 680px; */
z-index: 99;
}
.infosite-right-content {
padding-top: 175px;
padding-bottom: 175px;
padding-right: 120px;
padding-left: 60px;
text-align: left;
background-color: #bebebe;
min-height: 680px;
/* height: 680px; */
position: relative;
z-index: 99;
}
.uptxt {
position: relative;
z-index: 9999;
}
<section class="infosite" id="infosite-section">
<div class="container-fluid infosite-container">
<div class="row">
<div class="col-md-6 infosite-left-content">
<div class="">
</div>
</div>
<div class="sticky-top">
<p>Sticky Top</p>
</div>
<div class="col-md-6 infosite-right-content">
<div class="uptxt">
</div>
</div>
</div>
</div>
</section>
Can I get some help. I am sorry but I am not an expert.
Thanks
It's not working because you're parent is way larger than it's child. Because the div's could have different widths I suggest you to put the sticky-top div into the infosite-left-content class.
Like this:
<div class="container-fluid infosite-container">
<div class="row">
<div class="col-md-6 infosite-left-content">
<div class="sticky-top">
<p>Sticky Top</p>
</div>
</div>
<div class="col-md-6 infosite-right-content">
<div class="uptxt">
</div>
</div>
</div>
</div>
</section>
Second you need to adjust you css accordingly:
/* InfoSite ---------------------------------- */
.infosite-container {
margin: 0 auto;
width: 100%;
position:relative;
}
.infosite-container .row {
display: table;
}
.infosite-container [class*="col-"] {
float: none;
display: table-cell;
vertical-align: top;
}
.sticky-top {
height: 150px;
width: 150px;
position: absolute;
background:red;
top:50%;
right:-75px;
z-index:999;
transform: translateY(-50%)
}
.infosite-left-content {
position: relative;
background-color: blue;
padding-top: 175px;
padding-bottom: 175px;
padding-left: 120px;
text-align: left;
background-image: url(../../images/img-01.jpg);
background-repeat: no-repeat;
background-size: cover;
background-position: center center;
min-height: 680px;
/* height: 680px; */
z-index:100;
}
.infosite-right-content {
padding-top: 175px;
padding-bottom: 175px;
padding-right: 120px;
padding-left: 60px;
text-align: left;
background-color: #bebebe;
min-height: 680px;
/* height: 680px; */
position: relative;
z-index:99;
}
.uptxt {
position: relative;
z-index:9999;
}
/* ---------------------------------------------- */
I hope this works for you :D
Thank you for your response and possible solution.
Unfortunately it doesn't work as I would like, the sticky DIV stays on top of everything and not between the two divs.
I attach a picture of the result of how I would like its visualization.
Insert the sticky DIV between the background and the descriptive text that should appear as the last layer.
A possible solution is to use a single background DIV, ok it works, but I would like to have two of them so I can insert two images for example.
Thanks
Your css should be like this:
.infosite-container {
margin: 0 auto;
width: 100%;
position:relative;
}
.infosite-container .row {
display: table;
}
.infosite-container [class*="col-"] {
float: none;
display: table-cell;
vertical-align: top;
}
.sticky-top {
height: 150px;
width: 150px;
position: absolute;
background:red;
top:50%;
right:-75px;
z-index:500;
transform: translateY(-50%)
}
.infosite-left-content {
position: relative;
background-color: blue;
padding-top: 175px;
padding-bottom: 175px;
padding-left: 120px;
text-align: left;
background-image: url(../../images/img-01.jpg);
background-repeat: no-repeat;
background-size: cover;
background-position: center center;
min-height: 680px;
/* height: 680px; */
z-index:100;
}
.infosite-right-content {
padding-top: 175px;
padding-bottom: 175px;
padding-right: 120px;
padding-left: 60px;
text-align: left;
background-color: #bebebe;
min-height: 680px;
/* height: 680px; */
position: relative;
z-index:900;
}
.uptxt {
position: relative;
z-index:9999;
}
You can change the order in which the elements are stacked on top of each other with z-index - the greater it is, the higher the element will be !

Align two elements of different height in the middle of a div

I have two elements [a custom button and a paragraph line]in my fixed footer (always stays on page) that I've been trying to horizontally align in the center.
<div class="footer">
<div class="co_footer_content">
<button class="func_button" >
<span class="func_button_ico"></span>
</button>
<p class="footer_txt">Small one liner {{varContent}}</p>
</div>
</div>
Here's the CSS
.footer{
height: 87px;
position: fixed;
bottom: 0;
width: 100%;
background-color: #ffffff;
}
.func_button{
background: transparent;
border: 0;
height: 44px;
width: 44px;
margin: auto;
display:block;
position: absolute;
cursor: pointer;
left: 0;
margin-left: auto;
margin-right: auto;
}
.func_button_ico{
background:url(./assets/func_button.png) no-repeat top left;
display: inline-block;
margin: auto;
height: 44px;
width: 44px;
float: right;
}
.footer_txt{
text-align: center;
padding: 0;
margin:0;
}
As seen in the above html snippet, there is varConent which changes the width of my content to some extent. So everytime the content changes, the <p> recenters. The height is fixed however i.e. the content doesn't go to more than one line.
I want the custom button to stick with this variable width <p> so that they are in the same line but also to be able adjust the button's position independent of <p> What would be the right way to do this?
Here's the codepen: https://codepen.io/johnsackson/pen/ZobMLj
<div class="co_footer_content">
<button class="func_button">
<span class="func_button_ico"></span>
</button>
<p class="footer_txt">Small one liner {{varContent}}</p>
</div>
</div>
CSS:
.footer{
height: 87px;
position: fixed;
bottom: 0;
width: 100%;
background-color: #ffffff;
}
.co_footer_content {
display: table;
margin: 0 auto;
}
.func_button{
background: transparent;
border: 0;
height: 44px;
width: 44px;
margin: auto;
display:block;
cursor: pointer;
margin-left: auto;
margin-right: auto;
display:table-cell;
vertical-align: middle;
text-align: center;
margin-right: 20px;
}
.func_button_ico{
background:url(./assets/func_button.png) no-repeat top left;
display: inline-block;
margin: auto;
height: 44px;
width: 44px;
}
.footer_txt{
text-align: left;
padding: 0;
margin:0;
display:table-cell;
vertical-align: middle;
}

Firefox and IE border-box not working properly?

So I have been trying to figure this out for a day or so without any luck, and figured I would turn to the CSS masters of the universe here.
Anyway, in Chrome my page looks fine (like always), but Firefox and IE both seem to have issues w/resizing images. I basically have 2 parts, a 'left div' and a 'right div', and the on the left just has right-padding to make it be the entire width, minus the width of the 'right div'.
Inside 'left div', there is an image who's size is set to be 100% of the width and height of the containing element, which in Chrome, works out wonderfully, and leaves the image in the center and looking good. FF and IE don't resize it at all, and worse, they don't respect the padding set on 'left div' so it looks even more weird.
The simplified HTML:
<div>
<div class="dialog-bg"></div>
<div id="view-larger-dialog" class="mc_report_dialog dialog-container">
<div class="details-container staticimage">
<span id="openPostModal">
<span class="modal-body cardDetails">
<div class="closeOpenModal">×</div>
<div class="cardContent">
<div class="cardBody">
<div id="card-content" class="card-content-staticimage">
<span class="image">
<img class="annotatable" src="https://s-media-cache-ak0.pinimg.com/originals/5a/28/22/5a282241e64e41d605384bb261ea581f.jpg">
</span>
</div>
</div>
</div>
</span>
</span>
<span class="detailBox">
<div class="cardContent cardDetails">
<div class="content">
<p>
blank white space
</p>
</div>
</div>
</span>
</div>
</div>
</div>
The CSS:
.dialog-bg {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: black;
opacity: 0.6;
z-index: 1001;
}
.mc_report_dialog .details-container {
padding: 0px;
}
span#openPostModal {
position: fixed;
top: 0;
left: 0;
height: 800px;
margin-top: 0px;
margin-left: 0px;
display: table;
z-index: 5000;
height: 100%;
background: none;
width: 100%;
box-sizing: border-box;
padding-right: 24rem;
border: none;
}
span.detailBox, span.shareNewBox {
width: 24rem;
height: 100%;
padding: 0;
position: fixed;
top: 0px;
right: 0px;
background-color: white;
z-index: 5005;
}
span#openPostModal .modal-body {
border: 0px solid #ffffff;
padding: .6rem 1rem;
display: table-cell;
vertical-align: middle;
width: 100%;
max-height: 50%;
background: none;
overflow-y: visible;
}
.closeOpenModal {
font-size: 2rem;
color: #fff;
float: right;
position: absolute;
right: 1rem;
top: 1rem;
font-weight: 700;
cursor: pointer;
padding-right: 24rem;
opacity: 0.8;
}
span#openPostModal .cardContent {
background: none;
border: none;
position: relative;
width: 90%;
margin: auto;
}
span#openPostModal .cardContent .cardBody {
padding: 0;
}
span#openPostModal .cardContent .cardBody #card-content {
height: 100%;
padding: 0;
}
#card-content.card-content-staticimage .image {
position: relative;
display: inline-block;
width: 100%;
height: 100%;
}
#card-content.card-content-staticimage .image img {
max-height: 100%;
max-width: 100%;
}
You can see the result of that here on my jsFiddle
Any help would be greatly appeciated.
Apparently the whole display: table; and display: table-cell were messing it up. Just changing those to display as block worked. Sorry for the question.
Your problem isn't box-sizing:border-box, it's display:table.
Just add table-layout:fixed; right after the display:table declaration and you should be ok.

Aligning divs underneath each other

I have this html:
<div id="container" class="container">
<div id="menu-top">
<div class="top-menu">
<div class="top-menu-buttons">
<button class="button button-icon ion-minus-circled"></button>
<span>{{amount}}</span>
<button class="button button-icon ion-plus-circled"></button>
</div>
</div>
</div>
<div id="classic" class="classic">
<div id="classic-img" class="classic-img">
<img ng-src="{{image.filtered}}" />
</div>
</div>
<div id="menu-bottom">
<div class="bottom-menu">
<div class="bottom-menu-buttons">
<button class="button button-icon ion-eye"></button>
<button class="button button-icon ion-refresh"></button>
<button class="button button-icon ion-crop"></button>
<button class="button button-icon ion-android-options"></button>
<button class="button button-icon ion-social-tumblr"></button>
</div>
</div>
</div>
</div>
And this css:
.container {
width: 100%;
}
.classic {
display: block;
position: relative;
margin-left: auto;
margin-right: auto;
background-position: center center;
background-image: url("../img/frames/postcard_00.png");
background-size: contain;
background-repeat: no-repeat;
}
.classic-img {
display: block;
position: absolute;
overflow: hidden;
width: 100%;
height: 100%;
top: 6%;
left: 5%;
}
.classic img {
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
}
.top-menu {
position: relative;
width: 100%;
height: 50px;
background-color: red;
}
.top-menu-buttons {
position: absolute;
margin-left: auto;
margin-right: auto;
bottom: 0;
left: 0;
right: 0;
width: 50%;
text-align: center;
}
.top-menu-buttons .button {
display: inline-block;
vertical-align: middle;
font-size: 25px;
color: white;
}
.top-menu-buttons span {
display: inline-block;
vertical-align: middle;
font-size: 25px;
color: white;
}
.bottom-menu {
position: relative;
width: 100%;
height: 50px;
background-color: green;
}
.bottom-menu-buttons {
position: absolute;
margin-left: auto;
margin-right: auto;
bottom: 0;
left: 0;
right: 0;
width: 80%;
text-align: center;
}
.bottom-menu-buttons .button {
display: inline-block;
vertical-align: middle;
font-size: 35px;
color: white;
padding-left: 10px;
padding-right: 10px;
}
The result i want to have:
The result i got from above code:
My css is designed so that the blue content is under the red (top menu) and the green (bottom menu) is under the blue content. I cant find the mistake i made.
See this fiddle
position:absolute was the culprit.
You have to remove that from .classic-img and .classic-img img. Also, remove height: 100%; from .classic-img img. So the changed CSS would be as below
.classic-img {
display: block;
/* position: absolute; */
overflow: hidden;
width: 100%;
height: 100%;
top: 6%;
left: 5%;
}
.classic-img img {
/* position: absolute; */
width: 100%;
/* height: 100%; */
top: 0;
left: 0;
}
I'm not sure why you need an absolute position for both the image & the image container, if that is really necessary, you need to give the parent #classic a height.
Or you can remove the absolute positioning for the image & the image container like this
Or if you want the image to be fluid, just set it width to 100% instead of absolute positioning
.classic-img img {
width: 100%;
}
Try to give style rule position:absolute and bottom:0 to the .bottom-menu element. This will bring the .bottom menu at the bottom of page.
This will hopefully work for you.

How to keep a div constantly above a single point on the background?

I have a div which has a background of a map. The map is centred and has a background size of 'contain'. The page is responsive so when the window resizes, so does the map. I need to be able to have a div on top of a certain country on the map, and on resize of the background map, the div stays directly on top of it.
So far I have
<div id="map-holder">
<div class="content">
<div class="placeholder"></div>
</div>
</div>
The div with the class of placeholder is the div i wish to keep on top of a certain country. The div with map-holder for ID is the div with the map background. Content is just to keep it all in place.
CSS
.content {
text-align: center;
width: 1200px;
margin: 0 auto;}
#map-holder {
position: relative;
height: 1000px;
width: 100%;
background: #F0F0F0;
background-image: url(../images/image-mapster.min.png);
background-size: contain;
background-position: center center;
background-repeat: no-repeat;
padding: 30px;
}
.placeholder {
position: absolute;
right: 30px;
background: #fff;
width: 80px;
height: 50px;
border: 1px solid #000;
margin: 5px;
padding: 5px;
padding: 0;
cursor: pointer;
}
.placeholder img {
width: 100%;
height: 100%;
padding: 0;
}
.placeholder:before {
position: absolute;
top: 30%;
left: 45%;
font-weight: bold;
content: '+';
}
The only solution I can think if actually putting an image over the map.
You can do this by having multiple CSS backgrounds. Just change your code for #map-holder to this:
#map-holder {
position: relative;
height: 500px;
width: 500px;
background: #F0F0F0;
background-image: url(this_image_goes_on_top.png), url(your_map.jpg);
background-size: contain, contain;
background-position: center center, center center;
background-repeat: no-repeat, no-repeat;
padding: 30px;
}
I made a little JSFiddle out of your code for demonstration: https://jsfiddle.net/zamofL9g/1/
Basically, it's a little difficult, as I recall, when using background images.
Since the image is, technically speaking "content" you can use an inline image and suitable wrapping divs. The 'pins' can then be positioned using % based positioning values.
Here's a Codepen demo I made some time ago. This one has a tooltip too!
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.map {
width: 90%;
margin: 10px auto;
position: relative;
}
.map img {
max-width: 100%;
}
.box {
width: 2%;
height: 5%;
background-image: url(http://www.clipartbest.com/cliparts/ncX/qyL/ncXqyLdcB.png);
background-position: top center;
background-repeat: no-repeat;
background-size: contain;
position: absolute;
}
#pin-1 {
top: 25%;
left: 38%;
}
.box:hover > .pin-text {
display: block;
}
.pin-text {
position: absolute;
top: -25%;
left: 110%;
width: 300%;
display: none;
}
.pin-text h3 {
color: white;
text-shadow: 1px 1px 1px #000;
}
<div class="map">
<img src="http://connect.homes.com/wp-content/uploads/2012/05/200392710-0012.jpg" alt="" />
<div id="pin-1" class="box">
<div class="pin-text">
<h3>My House</h3>
</div>
</div>
</div>