My html:
<p>
<a href="#">
<img src="image.png" />
</a>
</p>
<p>Some text</p>
I want to move image to center without making it block. With block link goes clickable in all width.
Tried:
img{
margin:0 auto;
display:inline-block;
}
but it doesn't work.
Fiddle.
Fiddle with centered image but wrong link.
Image width can be different.
Any idea how to make image center and leave clickable area only on image?
You can set this CSS for the a tag:
a{
margin:0 auto;
display:table;
}
The demo http://jsfiddle.net/9653Y/4/
try this
<p id="imgPara">
<a href="#">
<img id="image" src="http://httpd.apache.org/docs/current/images/feather.gif" />
</a>
</p>
<p>Some text</p>
#imgPara{
text-align: center;
}
http://jsfiddle.net/Shashi0812/YAusb/
Align parent of img to center.
HTML:
<p class="center">
<a href="#">
<img src="http://httpd.apache.org/docs/current/images/feather.gif" />
</a>
</p>
CSS:
.center{text-align:center;}
Here is the updated fiddle.
change margin to 50%
img{
margin:0 50%;
display:inline-block;
}
Related
How would I go about placing my text at the center of an image, this is what it looks right now: http://gyazo.com/442aa9f927c1c1ee505435c2422f7322.png
and this is how I want it to be: http://gyazo.com/bc3bb2d0472a1c963d4ac00081065461.png
This is my current code:
<p><img src="http://findicons.com/files/icons/941/web_design/32/page_text.png" /> Some random text</p>
I would really appreciate if someone could help me out with this.
try to insert the image inside a div and put the text on it like this:
<div class="img">
<p>your text</p>
</div>
css:
.img{
background: url('http://findicons.com/files/icons/941/web_design/32/page_text.png') no-repeat;
height:100%;
}
DEMO
After you can mode your text where you want
If you don't want to use the image like a background and you want only to put text at the center of your element try this:
<div class="container">
<img src="http://findicons.com/files/icons/941/web_design/32/page_text.png" />
<span>your text</span>
<br style="clear:both;" />
</div>
css
.container{
width:100%;
height:100px;
}
.container span{
line-height:30px;
float:left;
}
.container img{
float:left;
}
DEMO2
Demo:
http://jsfiddle.net/5ser6/1/
<div class="thingy">
<img src="http://findicons.com/files/icons/941/web_design/32/page_text.png" alt="" />
<p>Text</p>
<br style="clear:both;">
</div>
* {font-family:arial}
.thingy img {float:left;}
.thingy {height:32px;float:left;}
.thingy p {float:left;margin:0 0 0 10px;padding:0;line-height:32px;}
If your framework has a clearfix, you don't need the clear:both, just put a clearfix on the outer div.
im making a container that contains 3 images and three "text bits"
My problem is that I cant seem to get the text to appear on the right side of each image.
Here a SS: http://imgur.com/ujBIjYC
The html:
<div class="textandimg">
<div class="image">
<a href="#">
<img src="img/belahotellforside.png" alt="belahotellforside">
</a>
</div>
<div class="text">
<p>asdfer</p>
</div>
<div class="image">
<a href="#">
<img src="img/caprocatforside.png" alt="caprocatforside">
</a>
</div>
<div class="text">
<p>asdfer</p>
</div>
<div class="image">
<a href="#">
<img src="img/granhotellforside.png" alt="granhotellforside">
</a>
</div>
<div class="text">
<p>asdfer</p>
</div>
</div>
and the css:
.textandimage{
clear:both;
}
.image{
float:left;
width: 100%;
margin-left: 10px;
}
.text{
float:left;
}
If I put :
.text{
float:right;
}
The text appears on the right side. But its still inline with the picture. And I want the text to be side by side.
Appreciate any help. Thanks.
If your div with image class has setted width: 100% it take 100% of the width. So you can remove it or set to an value in "px".
Delete all that CSS and just put this:
.image{
float: left;
margin-left: 10px;
}
All you want is just to float the images to the left of the text divs, so that's all you need.
http://jsfiddle.net/M8CQD/
Edit: From your comment, it also looks like you need to put each image and text div together in a div in order to push the images down below the preceding image.
<div class='row'>
<div class="image">
<a href="#">
<img src="img/belahotellforside.png" alt="belahotellforside">
</a>
</div>
<div class="text">
<p>asdfer</p>
</div>
</div>
I have the following markup:
<div class="photo" style="float: left; margin: 2px;">
<a href="#">
<img src="images/image.jpg" alt="My Image" height="240" width="240" />
</a>
</div>
How can I create a layer on top of the image where I can write some text? The layer should have transparency, be aligned to bottom and having a size of 240x60?
Thanks!
Why not make the image a background?
<div class="photo" style="float:left; margin:2px">
<a href="#" style="background:url('images/image.jpg');
width:240px; height:240px; display:inline-block;">Your text here</a>
</div>
The display:inline-block allows you to apply width and height to an otherwise inline element, but here you might even want to just use display:block since it's the only child of the container.
EDIT: You can even put more containers in it, something like this:
<div class="photo" style="float:left; margin:2px">
<a href="#" style="background:url('images/image.jpg'); position:relative;
width:240px; height:240px; display:block;">
<span style="display:block;position:absolute;bottom:0;left:0;right:0;
background:white;background:rgba(255,255,255,0.25);">Your text here</span>
</a>
</div>
Text blocks over images. Website and demo as follows:
http://css-tricks.com/text-blocks-over-image/
I'll do it like with an image container like that :
Html
<div class="image-container">
<img src="path/to/image" />
<p class="caption">My text</p>
</div>
CSS
.image-container {
position:relative;
}
.caption {
width:100%;
background:rgba(0,0,0,0.5);
color:#ffffff;
position:absolute;
top:0;
}
See fiddle !
Markup
<div class="figure-container">
<img src="http://ipadwallsdepot.com/detail/solid-color_00015061.jpg" width="250" height="250" />
<span class="figure-label">FIG 1.1: Caption Text Here</span>
</div>
<div class="figure-container">
<img src="http://ipadwallsdepot.com/detail/solid-color_00015061.jpg" width="250" height="250" />
<span class="figure-label">FIG 1.2: Another Caption Here</span>
</div>
Stylesheet
.figure-container
{
position: relative;
display: inline-block;
}
.figure-label
{
position: absolute;
bottom: 10px;
right: 10px;
color: White
}
I created a JSFiddle here http://jsfiddle.net/AbBKx/ showing how to absolutely position a child element (label) relative to a parent container.
I'm coding it
<div>
<a href="http://example1.com">
<img src="example1.gif" />
</a>
</div>
<div>
<a href="http://example2.com">
<img src="example2.gif" />
</a>
</div>
a {
text-align:center;
height :80px;
display:block;
}
The centering of the horizontal direction do well.
but vertical is not.
How to do it?
By the way, the height of example2.gif is different from example1.gif
You will want to set vertical-align: middle; on your img elements.
I used to know how to put an image on top and then justify the text below the image so that it stays within the borders of the width of the image. However, now I have no idea how to do this. How is this accomplished?
Your HTML:
<div class="img-with-text">
<img src="yourimage.jpg" alt="sometext" />
<p>Some text</p>
</div>
If you know the width of your image, your CSS:
.img-with-text {
text-align: justify;
width: [width of img];
}
.img-with-text img {
display: block;
margin: 0 auto;
}
Otherwise your text below the image will free-flow. To prevent this, just set a width to your container.
You can use HTML5 <figcaption>:
<figure>
<img src="img.jpg" alt="my img"/>
<figcaption> Your text </figcaption>
</figure>
Working example.
In order to be able to justify the text, you need to know the width of the image. You can just use the normal width of the image, or use a different width, but IE 6 might get cranky at you and not scale.
Here's what you need:
<style type="text/css">
#container { width: 100px; //whatever width you want }
#image {width: 100%; //fill up whole div }
#text { text-align: justify; }
</style>
<div id="container">
<img src="" id="image" />
<p id="text">oooh look! text!</p>
</div>
This centers the "A" below the image:
<div style="text-align:center">
<asp:Image ID="Image1" runat="server" ImageUrl="~/Images/opentoselect.gif" />
<br />
A
</div>
That is ASP.Net and it would render the HTML as:
<div style="text-align:center">
<img id="Image1" src="Images/opentoselect.gif" style="border-width:0px;" />
<br />
A
</div>
I am not an expert in HTML but here is what worked for me:
<div class="img-with-text-below">
<img src="your-image.jpg" alt="alt-text" />
<p><center>Your text</center></p>
</div>