stick one image over another - css

I have a structure like below:
.a {
display: block;
height: auto;
left: 11px;
top: 89.3px;
width: auto;
position: absolute;
}
.a img {
display: block;
height: auto;
width: 100%;
}
.b1 {
position: absolute;
}
.prev {
background: rgba(0, 0, 0, 0) url("http://ww1.prweb.com/prfiles/2014/04/10/11752526/gI_134971_best-image-web-hosting.png") no-repeat scroll 0 0 !important;
border: medium none !important;
height: 25px;
left: -807px;
overflow: hidden;
padding: 0;
position: absolute !important;
top: -220px;
width: 25px;
}
.prev span {
text-indent: -9999px;
}
<div class="a">
<div class="a1">
<img src="http://s.hswstatic.com/gif/shasta-daisy-3.jpg" />
</div>
<div class="b">
<div class="b1">
<button class="prev">
<span>previous</span>
</button>
<button class="nxt">
<span>next</span>
</button>
</div>
</div>
</div>
Now the problem is, I need to fixed previous and next button images on my shasta-daisy-3.jpg image. For this I used position: absolute for my nxt and prev classes. But when I resized the window, my previous image continously dragged to its left until it disappears, I am unable to stick it to one place over an image

You need create wrapper with position: relative;.

The main problem is your CSSHere I've created a JSFiddle and updated your CSS slightly as:
.b {
position: absolute;
left: 0px;
right: 0px;
top: 50%;
margin: auto;
width: 100%;
}
.b1 > button {
background: rgba(0, 0, 0, 0) url(http://ww1.prweb.com/prfiles/2014/04/10/11752526/gI_134971_best-image-web-hosting.png) no-repeat scroll 0 0;
position: absolute;
top:0;
height:25px;
width:25px;
margin:0;
padding:0;
text-indent: -999px;
overflow: hidden;
border: none;
display: inline-block;
}
.prev {
left: 0;
}
.nxt {
right: 0;
}
And this will give the output as:
In this position of next and prev buttons won't change if you resize the browser window. Hope it will work for you.

Your problem is that you have not given top and left values to position .b, so it doesn't really get absolutly positioned just by saying: position: absolute. You have to add: top:0; left:0 (or right, bottom) so it gets just over your image, like this:
.a {
display: block;
height: auto;
left: 11px;
top: 89.3px;
width: auto;
position: absolute;
}
.a img {
display: block;
height: auto;
width: 100%;
}
.b1 {
position: absolute;
top: 0;
left: 0;
}
.prev {
background: rgba(0, 0, 0, 0) url("http://ww1.prweb.com/prfiles/2014/04/10/11752526/gI_134971_best-image-web-hosting.png") no-repeat scroll 0 0 !important;
border: medium none !important;
height: 25px;
left: ;
overflow: hidden;
padding: 0;
position: absolute !important;
top: 0;
width: 25px;
}
.prev span {
text-indent: -9999px;
}
<div class="a">
<div class="a1">
<img src="http://s.hswstatic.com/gif/shasta-daisy-3.jpg" />
</div>
<div class="b">
<div class="b1">
<button class="prev">
<span>previous</span>
</button>
<button class="nxt">
<span>next</span>
</button>
</div>
</div>
</div>

Related

For a picture preview I need to put 2 div elements vertically in front of a picture

For a picture preview I want to put 2 invisble divs (red/blue in the picture) in front of a picture for next/previous image functionality.
I would like to have the div ("pictureContainer"/ green bordered zone) to automatically take over the dimension of the containing picture but I can't find a PURE CSS solution without setting the width and the height manually.
.container {
position: fixed;
width: 100%;
height: 100%;
border: 3px solid black;
}
.pictureContainer {
/* I don't want to set width and hight manuyally.
The container should have the size if the contained image. */
height: 50%;
width:300px;
position: relative;
margin: auto;
border: 3px solid green;
}
.leftSide {
background-color: blue;
float: left;
height: 100%;
width: 50%;
opacity: 80%;
}
.rightSide {
background-color: red;
float: right;
height: 100%;
width: 50%;
opacity: 80%;
}
.picture {
position: absolute;
top: 0;
left: 0;
margin: auto;
z-index: -1;
}
<div class="container">
<div class="pictureContainer">
<div class="leftSide"></div>
<img class="picture" src="https://www.9skips.com/wp-content/uploads/2018/01/anger-300x300.jpg">
<div class="rightSide"></div>
</div>
</div>
Also the container should be horizontally aligned.
Note: The full screen white div with the black border is used to close the picture preview.
You should change so the divs have absolut: position, let the image have it's natural size, container should be display: inline-block;
.container {
display: flex;
align-items: center;
justify-content: center;
position: fixed;
width: 100%;
height: 100%;
border: 3px solid black;
}
.pictureContainer {
position: relative;
display: inline-block;
margin: 0 auto;
border: 3px solid green;
}
.picture {
display: block;
}
.leftSide {
position: absolute;
top: 0;
bottom: 0;
left: 0;
background-color: blue;
width: 50%;
opacity: 80%;
z-index: 1;
}
.rightSide {
position: absolute;
top: 0;
bottom: 0;
right: 0;
background-color: red;
height: 100%;
width: 50%;
opacity: 80%;
z-index: 1;
}
<div class="container">
<div class="pictureContainer">
<div class="leftSide"></div>
<img class="picture" src="https://www.9skips.com/wp-content/uploads/2018/01/anger-300x300.jpg">
<div class="rightSide"></div>
</div>
</div>

css circle with text overlayed on an image

I am trying to overlay a circle over a square image. The text needs to be centered hoziontally and verticaly in the circle.
I have almost got it right with a square div, but as soon as I put an image into the mix, the circle moves below the image.
My code.
.Container {
width: 300px;
height: 300px;
}
.Square {
height: 100%;
width: 100%;
background-color: yellow;
}
.Square img {
width: 100%;
height: 100%;
}
.Circle {
position: relative;
height: 70%;
width: 70%;
top: 15%;
left: 15%;
background-color: rgba(0, 0, 200, 0.5);
border-radius: 50%;
/*80px;*/
margin-bottom: 50%;
/*30px; */
float: left;
margin-right: 20px;
}
.Circle h3 {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
width: 50%;
height: 30%;
margin: auto;
text-align: center;
}
<div class="Container">
<div class="Square">
<img src="SiteData/Images/ProfilePics/ProfileImg.png" />
<div class="Circle">
<h3>Words Here</h3>
</div>
</div>
</div>
The Container will ultimately be of variable width, determined by bootstrap col
Since you want to position your circle over the image, you have to use position: absolute instead of relative. This will take it out of the document flow and you can position it anywhere you want within the parent element.
In order for this to work, you will also have to declare position: relative on the parent.
See proof-of-concept example below:
.Container {
width: 300px;
height: 300px;
}
.Square {
height: 100%;
width: 100%;
background-color: yellow;
position: relative; /* To allow children to be absolutely positioned */
}
.Square img {
width: 100%;
height: 100%;
}
.Circle {
position: absolute; /* Use absolute positioning */
height: 70%;
width: 70%;
top: 15%;
left: 15%;
background-color: rgba(0, 0, 200, 0.5);
border-radius: 50%;
/*80px;*/
margin-bottom: 50%;
/*30px; */
float: left;
margin-right: 20px;
}
.Circle h3 {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
width: 50%;
height: 30%;
margin: auto;
text-align: center;
}
<div class="Container">
<div class="Square">
<img src="SiteData/Images/ProfilePics/ProfileImg.png" />
<div class="Circle">
<h3>Words Here</h3>
</div>
</div>
</div>

How do I embed a change image tag just right at the bottom of a picture on hover?

Have you noticed facebook's profile picture has this change profile picture on hover at the lowest part of the image?
It's like this example but it has the user's name instead.
I have this but it looks pretty nasty.
HTML
<div class="image">
<img src="./data/picture_caption/{{picture_caption}}" alt="polaroid" />
<p class="label">This image looks super neat.</p>
</div>
CSS
.image {
position: relative;
height: 200px;
width: 257px;
}
.label {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
color: #fff;
visibility: hidden;
opacity: 0;
}
.image:hover .label {
visibility: visible;
opacity: 1;
}
How can I achieve this?
Here following is your edited code. It will display name from bottom on hover.
.image {
height: 100px;
overflow: hidden;
position: relative;
width: 100px;
}
img {
height: 100px;
width: 100px;
}
.label {
background: rgba(0, 0, 0, 0.5) none repeat scroll 0 0;
bottom: -20px;
color: #fff;
left: 0;
margin: 0;
position: absolute;
right: 0;
text-align: center;
transition:0.1s all;
}
.image:hover .label {
bottom: 0px;
}
<div class="image">
<img src="http://i.stack.imgur.com/gLiJy.png" alt="polaroid" />
<p class="label">Name</p>
</div>
Try this method, it's a bit rudimentary but it works.
http://codepen.io/anon/pen/bEmGJv
HTML:
<div class="img-container">
<img src="http://blog.ramboll.com/fehmarnbelt/wp-content/themes/ramboll2/images/profile-img.jpg" alt="Profile">
<span class="img-txt">User name</span>
</div>
CSS:
.img-container{
position:relative;
display: inline-block;
}
img-container img{
display:block;
}
.img-txt{
position:absolute;
bottom:0;
left:0;
width:100%;
height:30px;
line-height: 30px;
padding-left: 10px;
background: rgba(255,0,0,0.5);
display:none;
}
.img-container:hover .img-txt{
display:block;
}

how to center (V,H) div inside div

My problem is that I wanted to have split page by two divs side by side (50% width). Inside of them I wanted to place another divs and make them aligned vertically and horizontally at the same time.
I think that it is possible to make it without JS, but I'm not able to do that.
Can anybody make my two circles placed in the center (V,H) of their parent DIV, which are 50% of width and 100% of height so that when I will resize my window the circles will always be in center (and side by side as is now)?
Here is my code:
<div id="container">
<div class="left">
<div class="kolo1">
sometext1
</div>
</div>
<div class="right">
<div class="kolo2">
sometext 2
</div>
</div>
</div>
And a JSFiddle for that: http://jsfiddle.net/m5LCx/
Thanks in advance in solving my quest :)
It's actually quite simple, all you need to do is to simulate a table-like behaviour:
HTML markup:
<div id="container">
<div>
<div class="half left">
<div class="circle">hello</div>
</div>
<div class="half right">
<div class="circle">world</div>
</div>
</div>
</div>
CSS styles:
html, body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
#container {
display: table;
width: 100%;
height: 100%;
}
#container > div {
display: table-row;
}
.half {
display: table-cell;
width: 50%;
text-align: center;
vertical-align: middle;
}
.half.left {
background: red;
}
.half.right {
background: blue;
}
.circle {
display: inline-block;
padding: 50px;
border-radius: 50%;
}
.half.left .circle {
background: blue;
}
.half.right .circle {
background: red;
}
Final result http://jsfiddle.net/m5LCx/11/:
Working here http://jsfiddle.net/3KmbV/
add position: relative in .left and .right class and than add margin: auto; position: absolute; top: 0; left: 0; right: 0; bottom: 0; in .kolo1 and .kolo2 class. and remove top position from .left class
try it
body {
background-color: #006666;
margin: 0 auto;
height: 100%;
width: 100%;
font-size: 62.5%;
}
#container {
width: 100%;
min-height: 100%;
height: 100%;
position: absolute;
}
.left {
width: 50%;
min-height: 100%;
float: left;
top: 0;
background-color: #660066;
position: relative;
}
.right {
width: 50%;
min-height: 100%;
float: right;
min-height: 100%;
background-color: #003366;
position: relative;
}
.kolo1 {
background-color: #0f0;
width: 10em;
height: 10em;
border-radius: 5em;
line-height: 10em;
text-align: center;
margin: auto;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
.kolo2 {
background-color: #00f;
width: 10em;
height: 10em;
border-radius: 5em;
line-height: 10em;
text-align: center;
margin: auto;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
you can give postion: relative to .left and .right.
and give below CSS for to .kolo1 and .kolo2
margin: -5em 0 0 -5em;
position: absolute;
left: 50%;
top: 50%;
Updated demo
Another fiddle. This one uses absolute positioning with negative margins to ensure the circles are always in the centre. CSS looks like this
.kolo1 {
position: absolute;
top: 50%;
left: 50%;
margin-left: -5em; /* this must be half of the width */
margin-top: -5em; /* this must be half of the height */
}
As #Tushar points out, you need to set the position of the parent element to relative also.
Working Fiddle
.kolo1 {
background-color: #0f0;
width: 10em;
height: 10em;
border-radius: 5em;
line-height: 10em;
text-align: center;
margin: 50% auto 0 auto;
}
.kolo2 {
background-color: #00f;
width: 10em;
height: 10em;
border-radius: 5em;
line-height: 10em;
text-align: center;
margin: 50% auto 0 auto;
}
Try adding padding-top:50% for parent divs (having class left and right)

anchor tag not responding

My anchor tag is not responding (my mouse does not respond to the link as a link, for example) within the #contentAboutMe... through research I found that the z-index may affect this... However, I commented out anything with a z-index, and it doesn't seem to be the issue.
Any ideas? I would appreciate any help. (anchors are working else where in my mark-up)
#logo {
position: absolute;
top: 50px;
left: 20px;
/*z-index: 50;*/
}
#mainHeader > h1 {
font-size: 18px;
}
#wrapperAboutMe {
position: absolute;
width: 525px;
left: 400px;
top: 40px;
/*z-index: 2;*/
}
#placeHolder {
position: relative;
}
#topAboutMe {
background-image: url(../images/aboutTopBackground.png);
width: 525px;
height: 47px;
}
#contentAboutMe {
width: 525px;
background-image: url(../images/aboutMainBackground.png);
}
#contentAboutMe p {
padding: 0 40px 0 40px;
text-align: justify;
}
.firstCharacter {
display: block;
float: left;
color: #155763;
font-size: 330%;
line-height: .5em;
padding-top: 10px;
padding-right: 2px;
}
#bottomAboutMe {
background-image: url(../images/aboutBottomBackground.png);
width: 525px;
height: 71px;
}
#aboutImage {
width: 220px;
height: 45px;
background-image: url(../images/graphicAbout_03.png);
background-repeat: no-repeat;
float: left;
padding: 30px 0 0 0;
position: absolute;
top: -25px;
left: -100px;
}
#aboutImage span {
display: none;
}
#aboutBackground {
position: absolute;
background-image: url(../images/graphicAboutBackground.png);
width: 462px;
height: 125px;
left: -260px;
top: -110px;
z-index: 1;
}
HTML:
<article id="aboutMe">
<div id="wrapperAboutMe">
<div id="topAboutMe"> </div>
<!--End topAboutMe-->
<div id="contentAboutMe">
<p><span class="firstCharacter">M</span>y content</p>
View My Resume
</div>
<!--End contentAboutMe-->
<div id="bottomAboutMe"> </div>
<!--End bottomAboutMe-->
<div id="placeHolder">
<h1 id="aboutImage"><span>About Me</span></h1>
<div id="aboutBackground"></div>
<!--End aboutBackground-->
</div>
<!--End placeHolder-->
</div>
<!--End wrapperAboutMe-->
</article>
<!--End Article_aboutMe-->
Your div with the id of aboutBackground, is over the top of your link, so when you try to click, it's actually registering against that div, isntead of the link.
To fix this, change the #aboutBackground z-index to -1, so it will look like so:
#aboutBackground {
position: absolute;
background-image: url(../images/graphicAboutBackground.png);
width: 462px;
height: 125px;
left: -260px;
top: -110px;
z-index: -1; // this line edited
}
​
just get rid of this style
#placeHolder {
position: relative;
}
This brings the element on top of your link

Resources