What I like to do is to use a DIV's vs. Table.
I like to show an image and to the right of that image show text. The text should be aligned to the top edge of the image. There should be some spacing between the text the image.
I have the following code but seems like the image comes and then the text comes below it:
<div style="float:left">
<img src="../../images/img1.png" alt="Description" width="32" height="32"></a></p>
</div>
<div style="clear:left"></div>
<div style="float:left">
%#Eval("title")
</div>
<div style="clear:left"></div>
You could use a float/overflow trick:
<div class="imgCont">
<img src="../../images/img1.png" alt="Description" width="32" height="32">
</div>
<div class="text">
%#Eval("title")
</div>
I used classes instead of inline styling:
.imgCont{float:left; margin-right:10px;}
.text{overflow:hidden;}
JSFiddle
You just need to remove the first
<div style="clear:left"></div>
HTML :
<div id="wrapper">
<img src="../../images/img1.png" alt="Description" width="32" height="32"></a></p>
<div>image</div>
</div>
CSS :
#wrapper img, #wrapper div { float: left; }
#wrapper div { margin-left: 100px; } /* the size of your img + the space wanted */
I don't understand why you have this 2 divs:
<div style="clear:left"></div>
They just prevent your text div and your image div to be on the same row. Css property "clear" make your container to NEVER have another container floating, here on his left.
<div style="float:left">
<img src="../../images/img1.png" alt="Description" width="32" height="32"></a></p>
</div>
<div style="float:left">
%#Eval("title")
</div>
It would be enough
Here is the answer!
Obviously use div. Here is a simple example!
You can first create a parent div then inside that parent div, you can create 2 divs like
<div>
<div class="float-left"><img src="~/link_to_file.png" alt="photo" /></div>
<div class="float-right">The text that would flow at the right side..</div>
</div>
Here is the CSS for that.
You will be displaying them inline! I mean one div on left other on right!
You will be displaying the text on the top corner! Which means no margin-top for the text div.
Here is the CSS code:
.float-left {
float: left;
}
.float-right {
float: right;
}
.float-left, .float-right {
display: inline; // use inline-block if you want to add padding or margins..
}
This way, the div with the image will align to the left and the other div will be placed to the right side! And they both will be in a line. As you want them to be.
Good luck, cheers! :)
Related
So I am very new to the whole coding thing and for this site I am building for class I want to align this photo I have at the bottom and move it to the right hand side of the page.
<img src ="halogram%20VR.jpg" alt = "man in halogram type VR setting" width:"200" height= "200">
This is the code for the image and I tried to add put something like align=center, but that has presented no results. What is the proper code for moving my image to the right hand side of the page?
While you can use float:right that will mean you need to clear that float for anything after that element. You can use text-align on the parent element for a simpler option:
div {
text-align: right;
}
<div>
<img src="https://image.shutterstock.com/image-vector/example-sign-paper-origami-speech-260nw-1164503347.jpg" />
</div>
An example of float messing up your layout without clearing it (note that this looks fine on Stackoverflow's small width, clicking full page will show the actual result).
img {
float: right;
}
<div>
<img src="https://image.shutterstock.com/image-vector/example-sign-paper-origami-speech-260nw-1164503347.jpg" />
<h1>HELLO WORLD</h1>
</div>
<h1>HELLO WORLD</h1>
An example using flexbox
div {
display: flex;
justify-content: flex-end;
}
<div>
<img src="https://image.shutterstock.com/image-vector/example-sign-paper-origami-speech-260nw-1164503347.jpg" />
</div>
An example using float and clearing:
.clear::after {
display: block;
content: "";
clear: both;
}
.float {
float: right;
}
<div class="clear">
<div class="float">
<img src="https://image.shutterstock.com/image-vector/example-sign-paper-origami-speech-260nw-1164503347.jpg" />
</div>
</div>
<p>HELLO WORLD</p>
You can do this in your HTML with <img src="image.jpg" alt="image" style="float: right"> or in a seperate .css file with img {float: right;}
I created a div id="A" and div id="B" and placed the latter div inside div A. Div A has a background-color attribute, but the inside div shows up as its own separate div without the A's background-color. I thought a div within a div would take the attributes of parent div. Instead, div A shows up with 0 height on the browser. The divs below follow the same structure and are just named differently: 'AboutPictures'(A) and 'ya'(B)
<div id="AboutPictures">
<div id="ya">
<img style='border:5px solid #F00' src="http://41.media.tumblr.com/3ad1ef80a08560a7e5f6be2b31f13c2/tumblr_n5wto2Ukmf1txjmgjo1_1280.jpg">
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<figure>
<figcaption>Hello I am Edward</figcaption>
</figure>
</div>
</div>
CSS:
#AboutPictures {
background-color: rgb(0,200,255);
height:100%;
}
#ya{
float:right;
}
#ya figure{
float:right;
}
Since your #ya div is floated, the parent div just sees empty content. You need to clear the #AboutPictures div, by applying the clear: both style. See: What is a clearfix?
Working example:
<div id="AboutPictures">
<div id="ya">
<img style='border:5px solid #F00' src="https://placehold.it/350x150">
<div style="clear: both;"></div>
<figure>
<figcaption>Hello I am Edward</figcaption>
</figure>
</div>
<div style="clear: both;"></div>
</div>
Hey there are different possibilities to solve this:
you could add a float: right / left; to your outer div (#AboutPictures)
or you could set it to display: inline-block;
See this fiddle: https://jsfiddle.net/8j2zpfdg/
Another SO answer as reference: How to make div not larger than its contents?
I'd like to align all 3 lines of text to the right of my image. Currently it wraps on the 2nd line.
How do I do this?
http://jsfiddle.net/bhu4p04r/
CSS:
img {
min-width:75px;
height:90px;
vertical-align:middle;
margin-right:30px
}
HTML:
<div class="medium-12 columns"><img src="http://placekitten.com/g/75/90" />1<br />2<br />3</div>
Wrap your text in a div, and make image float:left.
<div class="medium-12 columns">
<img src="http://placekitten.com/g/75/90" class="left" />
<div class="right">1
<br />2
<br />3</div>
</div>
DEMO here.
Vertically middle text:
Give display:inline-block; to image and the text container.
img, .text {
display:inline-block;
vertical-align:middle
}
See DEMO here.
float: left on your image is the way to go.
http://jsfiddle.net/bhu4p04r/2/
Or another alternative (to keep the text centered)
http://jsfiddle.net/Lbbt1uy8/
What is important to know is that vertical-align uses line-height not height to center something vertically.
Try to use <p> elements instead of </br> on your text and add align attribute to your image like this:
<div class="medium-12 columns"><img src="http://placekitten.com/g/75/90" align="left"/><p>1</p><p>2</p><p>3</p></div>
Here fiddle
you had lots errors on the syntax
and you should wrap each element and assign them with separate CSS codes
HTML:
<div class="medium-12 columns">
<img src="http://placekitten.com/g/75/90"></img>
</div>
<div id="txt">
1<br>2<br>3<br>
</div>
and CSS
.medium-12 {
min-width:75px;
height:90px;
margin-right:30px;
float: left;
display: block;
}
#txt {
float: left;
display: block;
margin-top: 0;
}
I have div which includes:
<div class="field-content">
<a href="http://url.com">
<img width="320" height="194" src="http://img.jpg"></img>
<div class="tile_content">
<div class="tile_title">content</div>
<div class="tile_body">content</div>
</div>
</a>
</div>
In some cases this field-content has not img-tag at all. Then I want tile_content to be vertically centered to field-content.
When img-tag exists then image is positioned at top of field-content and tile_content is under image.
This demonstrates those two situations. In first one there is image and under image tile_content. In second one there is only tile_content - no img at all.
Any ideas/tips how to make this work?
My CSS:
.field-content {
margin: 0px 0px 15px;
height: 365px;
width: 320px;
display: block;
overflow: hidden;
float: left;
background-color: #FFF;
.tile_content {
}
The only Thing you Need to know is vertical centering of div. This Problem is already solved here:
How to vertically center a div for all browsers?
You can add class has-image to .field-content do you can define own Styles for block with Image and without it. For example:
<div class="field-content has-image">
<a href="http://url.com">
<img width="320" height="194" src="http://img.jpg"></img>
<div class="tile_content">
<div class="tile_title">content</div>
<div class="tile_body">content</div>
</div>
</a>
</div>
So your CSS Looks like
.field-content.has-image {
}
If I got your question correct, then simply,
Put that img tag inside a div, give that div the same height as that you have given for image, so, it won't matter if the image is inside that div or not. it will always appear as a block, so won't collapse
OK, first time, I took it other way, I thought there are 3 divs, Sorry for that.
Here is the fiddle link:
enter code here
http://jsfiddle.net/happy2deepak/6U3kw/1/
I am trying to make my own website and only know some basic HTML, I've searched the web for a bit and can't seem to figure out how to place text under an image and on the left of the image.
So pretty much:
[image] [text]
[text]
would pretty much be my layout of the web page. At the moment I can only float the image or align it to the left making the text wrap around the image, which I don't want. Can someone help me?
<div style="width:400px; clear:both;">
<img src="http://media.techworld.com/cmsdata/news/3246520/1998_google.jpg" style="width:300px; float:left;" />
<div style="width:100px; float:left;">
text beside image
</div>
</div>
<div style="clear:both;">
text beneath image
</div>
http://jsfiddle.net/Tw2v7/
This is a simple layout matter; I think it should be done without using a table.
You can add an additional "clear: both"-Element behind the text you are floating next to the image, like so:
http://jsfiddle.net/nENVN/
I would suggest using divs instead of tables and then using CSS to size and position the divs
<div class="image">Image goes here</div>
<div class="rtext">text on right of image here</div>
<div class="ltext">text below image here</div>
This is the basic style for the above
.image {width:200px; float:left}
.rtext {width:200px; float:left}
.ltext {width:400px}
the ltext div would then be set to a width that is to wide to sit next to the image or the rtext div. It would then be forced to sit below the other 2 divs. This should achieve the look you want.
Use floats:
<img src="" alt="" class="left" /><span>Your text goes here and will wrap around and below the image</span>
<p>More text to sit below the image</p>
The text will appear beside the image and then wrap around to the bottom if it's long enough
Is this what youre after?
http://jsfiddle.net/ptzDw/
Basic HTML Structure:
<div id="wrap">
<div id="left">
<img src="http://dummyimage.com/300x90/7999/fff" alt="image">
<p>text goes here</p>
</div>
<div id="right">
<p>text goes here</p>
</div>
</div>
CSS:
#wrap { width: 800px; }
#left { width: 300px; float: left; }
#right { width: 400px; float: left; margin-left: 10px;}