How to align an image with text below? - html

I have an image which I want to align with the edge of text below. The text below is centered, but I can't figure out how keep it aligned on the left.
The code I have is:
<img src="Logo.png" style="margin: auto"/>
<h1 style="text-align: center;>The Collaborative Observer</h1>
<p style="text-align: center; font-size: 100%; padding-left: 6cm">The best thing that has happened to ICE since ICE.</p>
I also use the padding feature to align the bottom text, and I am wondering if there is a better way to do that.
The code above is modified for color, but looks like this.

just simply insert <center><img src="Logo.png" style="margin: auto"/></center>

when img & text in one div box, must set the 'vertical-align:text-bottom',so that the text under the image. sorry my English
<style>
.logo-box{display: table; text-align: center;}
.logo-box img{height: 100px; width: 100px; vertical-align:text-bottom}
</style>
<div class="logo-box">
<img src="Logo.png" />
<h3>The Collaborative Observer</h3>
</div>
<p style="text-align: center; font-size: 100%; padding-left: 6cm">The best thing that has happened to ICE since ICE.</p>

Seems like a good use of <figure> and <figcaption>.
From HTML5 Doctor:
The figure element represents some flow content, optionally with a caption, that is self-contained and is typically referenced as a single unit from the main flow of the document.
The figure element can be used to annotate illustrations, diagrams, photos, code listings, etc., that are referenced in the main content of the document, but that could, without affecting the flow of the document, be moved away from that primary content — e.g., to the side of the page, to dedicated pages, or to an appendix.
So why not...
<figure>
<img src="Logo.png" style="margin: auto"/>
<figcaption>
<h1>The Collaborative Observer</h1>
<p>The best thing that has happened to ICE since ICE.</p>
</figcaption>
</figure>
<figure> and <figcaption> are both block-level elements, so they will take up the full width of their container unless otherwise specified. This will allow the caption below to stretch to the edge of the element on each side, and then image will then be lined up correctly. Then add the following to your CSS file...
figure img {
margin: auto;
}
figcaption {
text-align: center;
}
figcaption p {
font-size: 100%;
padding-left: 6cm;
}

I think this is what you wanted :
<div style="text-align: center;">
<div style="left:10%;display:inline;margin:0 auto;">
<img src="http://almadaenmisr.com/templates/logo/1410252800_1266901625.jpg" width="100px" style="" />
</div>
<h1 style="display:inline;">The Collaborative Observer</h1>
<br />
<p style="text-align: center; font-size: 100%;padding-left: 15%;display:inline;">The best thing that has happened to ICE since ICE.</p>
</div>
Float the image left & inline the text.
Though this is working code, I would like to suggest using frameworks like bootstrap/skeleton for design so that its easier to work with and also makes it readily usable with all screen sizes.

Related

HTML5 - img alignment centre not working

I am trying to align my profile picture in the middle of my webpage yet cannot seem to get it working. I have attempted both align="middle" & float methods yet it still refuses to leave the left hand side.
The code I have attempted to use (HTML5) is
<header>
<h1> Luke Johnson Portfolio</h1>
<div class="image-cropper" style="text-align">
<img src="lukeprofile.jpg" align="center" alt="Luke Profile Pic" class="rounded" />
</div>
</header>
Any help would be appreciated, thank you.
align attribute for the image is aligning it relativelly to the text or other images on webpage (for more info: https://www.w3schools.com/tags/att_img_align.asp).
And notice (info from w3schools):
"The align attribute of is not supported in HTML5. Use CSS instead."
So align attribute will not do the trick in your case, you can center image using:
img {
display: block;
margin: 0 auto;
}
instead. Here is an example:
img {
display: block;
margin: 0 auto;
}
<header>
<h1> Luke Johnson Portfolio</h1>
<div class="image-cropper" style="text-align">
<img src="https://pbs.twimg.com/profile_images/378800000017423279/1a6d6f295da9f97bb576ff486ed81389_400x400.png" alt="Luke Profile Pic" class="rounded" />
</div>
</header>
You Have misused the inline style tag, proper use would be as follows:
<div class="image-cropper" style="text-align: center">
<img src="lukeprofile.jpg" alt="Luke Profile Pic" class="rounded" />
</div>
I could help you more if I had the URL to the website.
Compatibility Notes
The align attribute of img tag is not supported in HTML5. Use CSS instead.
For the image to align middle, top, or bottom use the CSS property.

Float left not applying?

I can't seem to float my image to the left? Can't figure out why?
I've applied a class of align-left which contains float: left.
Live version at - https://www.workbooks.com/salesforce-alternative (see the review grid half way down below the heading 'High customer satisfaction ratings').
Code:
<section class="bluesection card__content__headings">
<img alt="Reviews-6.png" class="align-left" data-entity-type="" data-entity-uuid="" height="395" src="/sites/default/files/2017-03/Reviews-6.png" width="400" />
<h2 style="height: 400px;"></h2>
<p></p>
</section>
CSS:
.align-left {
float: left;
}
.bluesection {
background-color:#ecf0f2;
padding: 50px 100px 50px 100px;
}
Try this code:
<section class="bluesection card__content__headings">
<h2 class="heading--two inline-block__heading" style="margin: 0px 0px 20px; text-align:center;">High customer satisfaction ratings</h2>
<img alt="Reviews-6.png" class="align-left" data-entity-type="" data-entity-uuid="" src="/sites/default/files/2017-03/Reviews-6.png" width="400" height="395">
<p class="inline-block__copy">With our world class software, our CRM expertise and proven implementation best practices, we are a genuine partner you can rely on to accompany you on your CRM journey - helping you transform your business and drive ongoing success.</p>
<p class="inline-block__copy">But don't just take our word for it. Over 268 independent customers have reviewed Workbooks on G2 Crowd where Workbooks consistently scores above Salesforce in satisfaction and richness of functionality.</p>
<p class="inline-block__copy">The G2 Crowd Report compare Workbooks to its competitors based on independent user reviews. Workbooks is rated higher than Salesforce in most categories.</p>
<p style="clear:both;"></p>
</section>
As you can see, I change the img after h2, and I have added a p with clear:both style to the end inside of the section. Also I have added and removed some CSS styles to get a nice look.
It's not float-left but float: left;. That's not the only issue though.
The image is already floating left but the reason it doesn't work the way you want it to work is because of the padding of the blue section.
Keep in mind that the image is floating to the left relative to the element it is enclosed in. If you change the value of padding to padding: 20px 50px 20px 50px; you can see that the image will move further to the left because the padding got smaller than it was initially.
I figured it out.
The image was floated to the left, the reason why the text wasn't wrapping was due to an inline height: 400px being applied to the heading rather than the section.
Sam
it already floated left, the reason it cant go any further is because it reached the edge of the div. padding shrinks the edges relative to the child elements, but maintains it defined size unless values are bigger.
here is a recommended fix:
HTML
<section class="bluesection card__content__headings">
<img alt="Reviews-6.png" class="align-left" data-entity-type="" data-entity-uuid="" height="395" src="/sites/default/files/2017-03/Reviews-6.png" width="400" />
<div class="text">
<h2></h2>
<p></p>
</div>
</section>
CSS
.bluesection {
position: relative;
width: 100%;
display: flex;
}
.text {
width: 100%;
}
example in jsfiddle: https://jsfiddle.net/qf6w18p1/
I figured it out.
The image was floated to the left, the reason why the text wasn't wrapping was due to an inline height: 400px being applied to the heading rather than the section.
You can fix the height, but when you see your code in a phone device (360px x 640px), the section title h2 will be located under img, and it will not look nice.
My advice is to change the orden of the h2 and img tags.

How to place Text and an Image next to each other in HTML?

I want the text and the image to be next to each other but I want the image to be on the far left of the screen and I want the text to be on the far right of the screen. This is what I currently have....
<body>
<img src="website_art.png" height= "75" width= "235"/>
<h3><font face="Verdana">The Art of Gaming</font></h3>
</body>
How can I do this?
Thanks
img {
float:left;
}
h3 {
float:right;
}
jsFiddle example
Note that you will probably want to use the style clear:both on whatever elements comes after the code you provided so that it doesn't slide up directly beneath the floated elements.
You want to use css float for this, you can put it directly in your code.
<body>
<img src="website_art.png" height= "75" width="235" style="float:left;"/>
<h3 style="float:right;">The Art of Gaming</h3>
</body>
But I would really suggest learning the basics of css and splitting all your styling out to a separate style sheet, and use classes. It will help you in the future. A good place to start is w3schools or, perhaps later down the path, Mozzila Dev. Network (MDN).
HTML:
<body>
<img src="website_art.png" class="myImage"/>
<h3 class="heading">The Art of Gaming</h3>
</body>
CSS:
.myImage {
float: left;
height: 75px;
width: 235px;
font-family: Veranda;
}
.heading {
float:right;
}
You can use vertical-align and floating.
In most cases you want to vertical-align: middle, the image.
Here is a test: http://www.w3schools.com/cssref/tryit.asp?filename=trycss_vertical-align
vertical-align: baseline|length|sub|super|top|text-top|middle|bottom|text-bottom|initial|inherit;
For middle, the definition is: The element is placed in the middle of the parent element.
So you might want to apply that to all elements within the element.

HTML/CSS misplaced header and missing images

I am having a little issue with a few headers being misplaced on the site I am working on and also an image that's supposed to show below each one of them is not showing.
You can see what I am talking about here:
Here's my HTML:
<!-- main-content -->
<div id="main-content">
<h1> Check out all our DEADicated sites: </h1>
<div class="sites">
<a href="http://www.thedeadicated.tumblr.com" target="_blank">
<img src="images/sites/tumblr.jpg" width="215" height="150" alt="Tumblr"/></a>
<p> Tumblr </p>
</div>
<div class="sites">
<a href="http://www.twitter.com/thedeadicated" target="_blank">
<img src="images/sites/twitter.jpg" width="215" height="150" alt="Twitter"/></a>
<p> Twitter </p>
</div>
<div class="sites">
<a href="http://www.youtube.com/user/DeadicatedRepository" target="_blank">
<img src="images/sites/youtube.jpg" width="215" height="150" alt="YouTube"/></a>
<p> YouTube </p>
</div>
<h2> To join TheDEADicated, click HERE! </h2>
<h2> To get your own DEADicated wristband, click HERE! </h2>
<h2> Can't get enough of Dead Sara?! Dead Sara Addiction Treatment Facility </h2>
<h2> Email us at: TheDEADicated#TheDEADicated.org </h2>
</div> <!-- close main-content -->
And this is the CSS code for the main-content & headers:
#main-content{
padding: 50px 50px 30px 50px;
background: #fff url('images/shadow.png') repeat-x;
min-height: 800px;
}
#main-content h2{
margin-top: 30px;
padding-bottom: 8px;
background: url('images/ink-line.png') no-repeat left bottom;
clear: both;
}
Any kind of help would be greatly appreciated. Thanks!
I can't tell exactly what is happening here, but taking a guess at how the elements above the headers look, I'd say you have a float issue. Try removing the "clear: both" from the h2 and add "float: left; width: 100%;" in its place.
The comments are correct that you're not really clear about what you should see but don't, but if I interpret you correctly you mean that "my headings aren't showing the margin and padding or background images that I expect".
I'm going to take another leap of faith to offer up a possible solution. I see
</div> <!-- close main-content -->
at the end of your html but I don't see a <div id="main-content> anywhere. It should either be at the top of the page, or before the block of h2s, depending on what you desire the outcome to be. Try adding <div id="main-content> before the first h2 tag and see if that solves it for you.
Edit: I see your problem more clearly now, but this is tricky to resolve without the live url to inspect. It could be a float issue, but the clear should resolve that, unless it's being overridden, so you could change to:
clear: both !important;
It could be a display problem, so try adding:
h2 { display: block !important; }
If there's a live url that would certainly help. Final thought is to make sure every tag in the entire page html is properly opened and closed. Redundant or unclosed divs can cause issues like this in my experience.

How to center a text under an image regardless of the size of that text

Let's say I have an Image.
<img src="lala.png" />
This image has a width=400px;.
and I want to type "Lala" under this Image.
<img src="lala.png" />
<br>
<span>Lala</span>
Note that I'm gonna be fetching those images and those texts from a database, the width of the images is fixed at 400px, but of course the texts will vary in size, so I can't use margin-left:100px; to push the text to the middle because It will look wrong on other texts...
What is the best way to do it?
You can use a div instead of span.
HTML:
<div class="underImage">Blah</div>
Style:
.underImage {
width: 400px;
text-align: center;
}
you can do this by text-align:center;
<div style="text-align:center;">
<img src="lala.png" />
<br>
<span>Lala</span>
</div>
Just wrap the image and text in an element and use the text-align CSS attribute on the wrapping element.
HTML
<p class="center-wrapper">
<img src="lala.png" />
<br>
<span>Lala</span>
</p>
CSS
.center-wrapper { text-align: center; }
There are several ways to achieve that, but the most flexible and most effective way is to use a one-cell table, with the caption text in a caption element:
<table class="image">
<caption align="bottom">caption text</caption>
<tr><td><img ...></td></tr>
</table>
There are many people who oppose such use of a table on quasi-religious grounds, but it’s still the flexible way that does not require you to set the width of the text explicitly (as opposite to letting it be determined by the width of the image) and works independently of CSS support.