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>
Related
Can someone show me how to put text under every individual image and also images must be in same line which is working? I understand that default display for "a" tag is block and for "img" tag is display inline.
This is my code:
HTML
<div class="other-content">
<div class="search">
<h1>We Offer best experience in the world</h1>
<img src="../Images/beach.jpg" alt="beach" width="200px" height="150px">
<p>sadasdasd</p>
<img src="../Images/desert.jpg" alt="desert" width="200px" height="150px">
<p>sadasdasd</p>
<img src="../Images/evergreen.jpg" alt="maoutin" width="200px" height="150px">
<p>sadasdasd</p>
<img src="../Images/snow-pathway.jpg" alt="snow-pathway" width="200px" height="150px">
</div>
</div>
CSS
.other-content .search {
background: #ffffff;
height: 300px;
text-align: center;
}
.other-content .search p{
display: inline;
}
Just put the picture with the text in separate divs and make the divs width smaller until the text is below the picture. And with these divs, assign display:inline-block;
I want the first image to stick to the top of the container and the following images should be below it... top:0; lets the image be..200px above the container and if I just say position:relative its always in the middle...;
<div class="container">
<div class="card_left">
<p style="font-size:1.6em; padding: 15px 0;"><b>Title</b></p>
<p style="font-size:1.2em;">Long text</p>
</div>
<div class="card_right">
<img src="../res/images/artikel1bild.PNG"/>
<img src="../res/images/artikel1bild.PNG"/>
</div>
Use display: block so there will be no other images in the same line and margin: auto for centering the image
img {
display: block;
margin: auto;
width: 200px;
}
<div>
<img src="https://www.w3schools.com/css/paris.jpg" />
<img src="https://www.w3schools.com/css/paris.jpg" />
<img src="https://www.w3schools.com/css/paris.jpg" />
</div>
Just add <br /> after each image if you want to stick to HTML:
<div class="card_right">
<img src="../res/images/artikel1bild.PNG"/><br />
<img src="../res/images/artikel1bild.PNG"/><br />
</div>
Or the better way would be to make a separate CSS file and set display: block; for your img tags:
img {
display: block;
}
Example: https://jsfiddle.net/nk8fbr76/
try this
img {
margin: 0, auto;width: 200px;display:inline-block;height:100px;
}
<div class="card_right">
<img src="https://www.w3schools.com/css/img_fjords.jpg"/>
<img src="https://www.w3schools.com/css/img_fjords.jpg"/>
</div>
I'm trying to get the text in this div table/columns/rows to be middle aligned with the images corresponding to each sentence. But so far, all it is giving me is more of a top aligned feel. Could anyone help me with this?
CSS:
.div-table {
display:table;
width:776px;
height: auto;
background-color:#eee;
border:1px solid #666666;
border-spacing:5px;
/*cellspacing:poor IE support for this*/
clear: both;
}
#image-middle {
vertical-align: middle;
float: left;
padding-right: 2px;
padding-top: 2px;
padding-bottom: 2px;
}
.div-table-row {
display:table-row;
width: 776px;
float: left;
clear: both;
}
.div-table-col-first {
display:table-column;
width:49%;
float: left;
}
HTML:
<div class="div-table">
<div class="div-table-row">
<div class="div-table-col-first">
<img width="50" height="50" id="image-middle">First Image Text in the first column and sentence</div>
<div class="div-table-col-first">Second Column Headline
<br />
<img alt="Checkbox" width="30" height="30" id="image-middle">First Image Second Column Text
<br />
<br />
<img id="image-middle" alt="Padlock in a circle">Second Image Second Column Text</div>
</div>
<div class="div-table-row">
<div class="div-table-col-first">
<img width="50" height="78" id="image-middle">Second Image Text in the first column and sentence</div>
<div class="div-table-col-first">
<img id="image-middle" alt="Pie Chart">Third Image Second Column Text
<br />
<br />
<img id="image-middle" alt="A Cover for a Safe">Fourth Image First column Text</div>
</div>
</div>
Below is a JSFiddle generated by the above markup.
JSFiddle
First, wrap the image and the text separately (http://jsfiddle.net/L9FnJ/) This is to get you started, I'll not clean up all of your code or do all of the work, but this should tell you how to do it.:
<body>
<div class="div-table">
<div class="div-table-row">
<div class="div-table-col-first">
<div class="colImg"><img width="50" height="50" id="image-middle" /></div><div class="colText">First Image Text in the first column and sentence</div>
</div>
<div class="div-table-col-first">Second Column Headline<br />
<img alt="Checkbox" width="30" height="30" id="image-middle">First Image Second Column Text<br />
<br />
<img id="image-middle" alt="Padlock in a circle"> Second Image Second Column Text </div>
</div>
<div class="div-table-row">
<div class="div-table-col-first"><img width="50" height="78" id="image-middle">Second Image Text in the first column and sentence</div>
<div class="div-table-col-first"><img id="image-middle" alt="Pie Chart">
Third Image Second Column Text<br />
<br />
<img id="image-middle" alt="A Cover for a Safe"> Fourth Image First column Text</div>
</div>
</div>
</body>
</html>
Then, in your css, add this:
.colImg, .colText {
display: table-cell;
vertical-align: middle;
}
You definitely need to wrap your text within elements, and see #feitla's comment. I have found that this works:
<div style="display: table; height: 400px; overflow: hidden;">
<div style="display: table-cell; vertical-align: middle;">
<div>
everything is vertically centered in modern IE8+ and others.
</div>
</div>
</div>
See this previously asked question.
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.
EDIT: This might make more sense, check this image. http://puu.sh/rt8M
The image just goes through the padding. I want the title div to expand vertically to accommodate the image. While keeping the text centered and the center of the image should intersect the line the text is on.
I want to align an img to the left (and then another after the text to the right). I've tried various properties but none seem to do it right. Can anyone help?
To clarify, I want the image against the left side of the screen or browser window. The div stretches from the left to the right of screen, as you would expect of a header/title div.
Float;left seems to make the img drop out of the div tag. I should mention there is a text-align:center; property on the tag. But it doesn't fix the problem when removed so I'm not sure it's that.
The HTML
<div id="header">
<div id="title">
<h1>
<img class="logo" src="images/logo.png" alt="" width="86" height="98" />
Page Header Title
</h1>
</div>
</div>
I created a little dabblet code example for you. I think this is what you are trying to do?
http://dabblet.com/gist/2492793
CSS:
.logo{
float:left;
width: 86px;
height:98px;
display:block;
}
.img2{
float:right;
display:block;
}
.clear{
clear:both;
}
HTML:
<div id="header">
<div id="title">
<h1>
<img class="logo" src="images/logo.png" alt="" />
Page Header Title
<img class="img2" src="images/img2.png" alt="" />
<div class="clear"></div>
</h1>
</div>
</div>
The reason the logo is dropping out of the div is because it is not cleared.
This should fix things up.
Use this
<div id="header" style="float:left">
<div id="title">
<h1>
<img class="logo" src="images/logo.png" width="86" height="98" />
Page Header Title
</h1>
</div>
#logo{
display: flex;
justify-content: space-evenly;
}
<div id="logo">
<img src="https://images.pexels.com/photos/853168/pexels-photo-853168.jpeg?auto=compress&cs=tinysrgb&dpr=3&h=750&w=1260" alt="something" width="100" height="100"/>
<h1>Hello World</h1>
</div>