Align text in the centre of an image slider - html

I have a image slider and I am trying to align some explanatory text in the horizontal and vertical centre of each image.
How can I archieve this in HTML/CSS?
Here is my Slider: jsbin
// Note I edited ur jsbin - now the text is visible and the question clear.

You could make a CSS class that looks like:
display:block;
line-height:*same as your slider height*;
margin:0 auto;
position:relative;
z-index:99;
and put within the slider. Some tweaks have to be made to that CSS but the basic idea remains.

Use following HTML and CSS
<article>
<div class="text">hihihi</div>
<img alt="an interesting rock" src="http://placehold.it/300x300/123456/000000/&text=1">
</article>
.text {
color: white;
height: 300px;
position: absolute;
top: 47%;
width: 100%;
}
#slides article {
float: left;
position: relative;
width: 25%;
}

You need to do two changes.
Add position:relative to the parent.
#slides article
{
width:25%;
float:left;
position:relative;
}
Add positions(top, left, bottom, right) to your text class.
.text
{
position:absolute;
display:table;
width:100%;
color:#fff;
height:30px;
top:0;
bottom:0;
right:0;
left:0;
margin:auto;
}
The display:table property and fixing some small height with margin:auto will do the magic.
FIDDLE DEMO

Related

How to place an image on top left of another image without using Javascript?

I have an image in the center of a div
The image is centered in the parent div using the following css:
img { margin:0px auto; }
The image can have arbitrary dimensions.
How can I position the Magnifying Glass (zoom) image on top left of the image without using Javascript, while the main image can have any width or height?
User position:relative and position:absolute. Look at the following HTML and CSS.
HTML
<div class="parent">
<div class="test"><img src="http://isc.stuorg.iastate.edu/wp-content/uploads/sample.jpg" border="0" />
<img src="http://www.beyotta.net/images/icon_magnifier.png" border="0" class="absimg" />
</div>
</div>
CSS
.parent {width:100%; height:400px; border:1px solid blue; text-align:center;}
.test
{
display:inline-block;
position:relative;
}
.absimg
{
position:absolute;
top:5px;
left:5px;
}
FIDDLE DEMO
Giving a position relative to the image and absolute to the magnifying glass image would do the trick here's the demo on what I've done.
http://jsbin.com/yumelamive/5/edit?html,css,output
i am not sure it will work or not but try using before will help
img:before {
content: 'img/zoom.png ';
position:absolute;
top:0px;
left:0px;
}
for proper help atleast provide a jsfiddle or code of your work
Try Use this
jsfiddle
div{
content:"";
display:block;
height:300px;
width:300px;
border:solid 1px #CCCCCC;
background-image: url("http://www.codeproject.com/KB/GDI-plus/ImageProcessing2/img.jpg");
position: absolute;
}
div:before {
content:"";
background-image: url("http://icons.iconarchive.com/icons/icontexto/search/48/search-red-icon.png");
top:0;
left:0;
position:absolute;
width: 40px;
height: 48px;
}
I would make a div for the image, set the background the image and add:
position: relative;
for that div. Then put the magnifying glass within the div and set:
position: absolute: top: 0; left: 0;
.image {
background: url(eiffel.jpg);
position: relative;
width: 100px;
height: 200px;}
.image img {
position: absolute;
top: 0;
left: 0:}
The 'relative' is what any 'absolute' objects..relate to.
I hope that helps.
set the image Magnifying Glass to absolute:positionand use left: right: for right position then the parent div set to position:relative

Centered oval shape with repeated pattern on either side

I have an image that isn't as big as all screen sizes, yet I want it to be displayed on screens with whatever width by adding a repeated pattern on either side. I can of course make the image a lot wider but that would cause the page to load a lot slower as well.
It's a bit hard to explain by text so here are some images and the JSFiddle Demo.
#layer_top {
background:url("http://puu.sh/cajm0/c0c2cc9475.jpg") repeat;
width:100%;
height:136px;
}
#layer_transition {
width:100%;
height:36px;
margin-top:-36px;
background-image:url("http://puu.sh/cajG0/2768274649.png");
background-repeat:no-repeat;
background-position:center;
}
#layer_bottom {
width:100%;
height:100px;
background:url("http://puu.sh/cajmN/9b1e9ef79f.jpg") repeat;
}
<div id="layer_top"></div>
<div id="layer_transition"></div>
<div id="layer_bottom"></div>
Result:
Wanted Result:
You could achieve that by adding a pseudo-element to the top layer which is formed as ellipse and it's positioned with the respect of the layer.
Then simply apply the same background image to both, layer and the pseudo-element:
Example Here
#layer_top, #layer_top:after {
background:url("http://puu.sh/cajm0/c0c2cc9475.jpg") repeat;
}
#layer_top { width:100%; height:136px; position: relative; }
#layer_top:after {
content: "";
position: absolute;
z-index: -1;
width: 500px; height: 100%;
left: 0; right: 0; top: 20%;
margin: auto;
border-radius: 50%;
}
You could also use clip to cut the extra part of the oval shape.
A bit of a different solution but it might just work:
Why don't you replace the mask image? So instead of overlaying this gray thing, make an overlay for the purprle one. If you position that centered against the top of the grey area, you've got the same result/
Well, the problem is with the div elements you created its hard to get it work.
An easy solution is to use for the bottom part 3 diffrent divs.
<div id="side_layer"></div>
<div id="layer_bottom"></div>
<div id="side_layer"></div>
I created a simple jsfiddle for you: jsfiddle
It does work responsive until 500px width.
You could simply add a media query and hide the right and left layer then.
You can do this it is easy.
Add CSS class to body or create parent div above body and style it.
Working Fiddle
http://jsfiddle.net/7n06und5/11/
.parent {
margin:0;
background:url("http://puu.sh/cajm0/c0c2cc9475.jpg") repeat;
width:100%;
}
#layer_top {
background:url("http://puu.sh/cajm0/c0c2cc9475.jpg") repeat;
width:100%;
height:136px;
}
#layer_transition {
width:100%;
height:36px;
margin-top:-36px;
background-image:url("http://puu.sh/cajG0/2768274649.png");
background-repeat:no-repeat;
background-position:center;
}
#layer_bottom {
width:100%;
height:300px;
background:url("http://puu.sh/cajmN/9b1e9ef79f.jpg") repeat;
width:500px;
margin:0 auto;
}
HTML
<body class="parent">
<div id="layer_top">
</div>
<div id="layer_transition">
</div>
<div id="layer_bottom">
</div>
</body>
Hope it helps you!
you can try this with css border-raidus
HTML
<div id="header">
<div id="inner"></div>
</div>
CSS
#header{
background:url(http://puu.sh/cajm0/c0c2cc9475.jpg) repeat-x;
//height:75px;
//width:100%;
padding:3% 15%;
}
#inner{
background:url(http://puu.sh/cajm0/c0c2cc9475.jpg) repeat-x;
height:75px;
width:100%;
border-radius:0 0 50% 50%;
}
Fiddle Demo

Overlay image on the bottom of a responsive image slider

I'm trying to add an image to the bottom of a responsive slider and need help sticking it to the bottom.
When in full screen mode it works fine, but as I shrink the page it keeps floating up, higher and higher.
I know I can set media queries to fix the issue on certain breakpoints, but I'm looking for a more adaptive solution that will work without having to use media queries.
Here is an image of what the slider looks like at full width. (This is fine.)
Then as I start to scale the screen you can notice the grass image moving up.
This is my problem. I need that grass to stay glued to the bottom of the slider.
I don't want to post all the slider code so I made a simple version on JSFiddle.
Here is the code.
HTML:
<div class="pic" align="center"><img src="http://i.imgur.com/8uVGUkM.jpg" class="slider"/></div>
<div class="grassframe"><img src="http://i.imgur.com/vw8soIm.png" class="img-max"/></div>
CSS:
.slider{width:100%; max-width:960px; height:auto; position:relative; z-index:1;}
.grassframe {
position:relative;
max-width:1200px;
margin:-135px auto;
z-index:2;
}
.img-max { width:100%; height:auto; }
I created a JSFiddle if someone wouldn't mind taking a look.
You can use absolute position and margin-top with % value. DEMO
Vertical padding or margin using % value use the parent's width as reference. So once tuned it will worke with any width.
.slider {
width:100%;
max-width:960px;
height:auto;
position:relative;
z-index:1;
border:solid;
}
.grassframe {
position:absolute;
margin-top:-12.5%;
max-width:1200px;
left:0;
right:0;
z-index:2;
}
.img-max {
width:100%;
height:auto;
}
If you use a wrapper in relative position and set to same max-width, it even works better (grass in absolute or relative position doesn't matter much here as long as z-index is avalaible ): DEMO
.slider {
width:100%;
max-width:960px;
height:auto;
position:relative;
z-index:1;
border:solid;
}
.grassframe {
position:relative;
margin-top:-12%;
max-width:1200px;
left:0;
right:0;
z-index:2;
}
.img-max {
width:100%;
height:auto;
}
.container {
position:relative;
margin:auto;
max-width:1200px;
}
Try out the below code:
HTML
<div class="pic" align="center">
<img src="http://i.imgur.com/8uVGUkM.jpg" class="slider" />
<div class="grassframe"></div>
</div>
CSS
.pic {
position: relative;
}
.slider {
max-width:100%;
}
.grassframe {
background: url("http://i.imgur.com/vw8soIm.png") no-repeat scroll center top / 1920px auto rgba(0, 0, 0, 0);
bottom: -87px;
height: 310px;
position: absolute;
width: 100%;
}
Have a look at the JSFiddle

Absolute Position - Center - Max-width

I have som problems, regarding Max-width and Absolute Positioning.
In the top of my site, I have a '100%-width section' with a background-image.
I want a small image partly covering the bottom of the top image. To do so, I use Position:relative on the section (top image) and position:absolute on the small image. So far so good..
My problem is, that i want the small image to be centered and have a max-width, so it aligns to the content on the site. (Which have a max-width of 500px..)
I really can't figure out, how to do it...
So, is there a way to only affect vertically, when using position:absolute, or maybe something else i can do?
I hope it makes sense.. :)
screens:
http://cvdmark.com/images_help/screens.jpg
<body>
<section id="img_heading">
<img src="#">
</section>
<section id="content">
<ul>
<li>
</li>
</ul>
</section>
</body>
body {
width:100%;
min-width:100%;
background-color:#000;
float:left;
}
#img_heading{
width:100%;
min-width:100%;
height:150px;
margin-bottom:6em;
background:url(../img/heading_img_test.jpg);
background-position: center center;
float:left;
position:relative;
}
#img_heading > img{
width:90%;
height:100px;
position:absolute;
bottom:-75px;
margin: 0 auto 0 auto;
max-width:500px;
/*left:5%;*/
background-color:#F69;
}
#content{
width:90%;
margin: 0 auto 0 auto;
max-width:500px;
}
#content ul{
width:100%;
list-style-type: none;
}
#content ul li{
width:100%;
float:left;
margin-bottom:30px;
}
JS Fiddle : http://jsfiddle.net/rpatil/ukKgx/
I think what you'd want is to align an absolute position div to the bottom of the section and center it.. (this following assumes you have your content in the section centered too..) replace div with img if you want to and give it your required id.. I ve given "foo-id"
div#foo-id
{
position: absolute;
bottom: 0px; /*since you want it at the bottom of section*/
z-index: 2;
width:90%; /*since your asked for 90%*/
max-width: 500px;
/*the following to center your image*/
margin-left:-45%;
left:50%;
}
Believe that helps!
And here is an updated jsfiddle.. thanks #rubyist..
http://jsfiddle.net/ukKgx/2/
This is an other solution to make it centred --> jsFiddle
<section style="position: absolute; left: 50%;width:50%">
<div style="position: relative; left: -50%;background-color:#ccc; border: dotted red 1px;width: 90%;max-width:500px;height:150px">
</div>
</section>
If you want to make it more custom, you have to use Javascript onLoad page to calculate screen width % picture width

Keep a button centered over an fluid image

The last few days i tried to center a button over a fluid image. So far the position is fixed and static. The relevant HTML part looks like the following:
<ul class="moodlegrid sectionwrap">
<li>
<a class="ajax1" href="project1.html">
<img title="Project 1" src="img/projectblur.jpg" alt="Project 1" />
<img title="Project 1" src="img/project.jpg" alt="Project 1" />
<span class="openoverlay">Click</span>
</a>
</li>
</ul>
The CSS looks like that:
.moodlegrid{
li{
a{
position: relative;
display:block;
width: 100%;
img:nth-child(1){
display:block;
}
img:nth-child(2){
display: none;
}
span{
display:none;
}
}
a:hover{
img:nth-child(2){
display: block;
position: absolute;
z-index: 100;
top:0;
left:0;
}
span{
display: block;
position: absolute;
text-align:center;
top: 37%;
left: 28%;
z-index:101;
#include border-radius(5px, 5px);
#include box-shadow(black 2px 2px 10px);
}
}
}
}
img{
width:100%;
max-width: 100%;
height:auto !important;
}
On mouseover a second image as well as a button should float centered on top of the first image. Problem is if the viewport changes the recent version doesn't work anymore and the button isn't centered. The following article on CSS-tricks had a promising solution:
Centering in the unknown
The demo worked fine:
Centering in the unknown demo
But it utilizes inline-block elements which makes it difficult to layer images and show on top of them a centered button in the end - the elements are displayed after each other when the display:inline-block property is set. There is also the problem that in contrast to my HTML the demo aligns a child object towards a parent.
Is there a way to apply the mentioned technique to my problem, or is there a maybe even better suiting approach? Best regards Ralf
If I understand you rightly, you're almost there I think.
<a> needs to be position: relative;
<span> needs to be position: absolute;
On the <span> if you set a specific width, and apply:
width: 100px;
height: 100px;
top: 50%;
left: 50%;
margin-top: -50px /* Half of the height */
margin-left: -50px; /* Half of the width */
http://codepen.io/anon/pen/xjcCf
Does that solve what you're trying to do?
Hi is this what look like
html
<div>
<h1><span>button</span></h1>
<img src="imageSample.jpg" alt="" />
</div>
css
div {
position:relative;
width:100%;
}
div img {
max-width:100%;
width:100%;
}
div h1 {
width:100px;
margin:auto;
}
div h1 span {
position:absolute;
z-index:999;
top:200px;
padding:5px;
background-color:#fff;
}
working demo
note: scroll fiddle so you can see the effect