aligning images and text side by side - html

I've got a list of three service items with an image (intended to float left) and a small bit of text (intended to float right). I've got what I thought to be the proper code in place, but it's not working properly and I'm at a loss for what the problem could be.
<ul id="work">
<li><img src="http://placehold.it/350x150" /><p>SERVICE 1<br/><p>Service 1 description.</p></li>
<li><img src="http://placehold.it/350x150" /><p>SERVICE 2<br/><p>Service 2 description.</p></li>
<li><img src="http://placehold.it/350x150" /><p>SERVICE 3<br/><p>Service 3 description.</p></li>
#work li {
list-style-type: none !important;
}
#work li img {
float: left;
}
#work li p {
float: right;
}
https://jsfiddle.net/feewvmvt/

The issue is that you are nesting <p> elements:
<p>something<br><p>something</p>
Swap out the <br> with a closing </p> and everything lines up:
https://jsfiddle.net/jalbertbowdenii/5axLw1ww/

First you have two open <p> tag and just one closing </p> tag. Kindly fix
that.
The issue is because of the elements you are floating inside
the li. You need to use clear:both to li.
Please find other ways to clear float elements inside li
**
#work li {
list-style-type: none !important;
clear:both;
}
#work li img {
float: left;
}
#work li p {
float: right;
}
<ul id="work">
<li><img src="http://placehold.it/350x150" /><p>SERVICE 1<br/>Service 1 description.</p></li>
<li><img src="http://placehold.it/350x150" /><p>Service 2<br/>Service 2 description.</p></li>
<li><img src="http://placehold.it/350x150" /><p>SERVICE 3<br/>Service 3 description.</p></li>
</ul>

I think you should wrap your text on a div so you can manipulate it easier. I floated both blocks left and they align nicely. Also if you clear the floats the <li> tag recovers it heights
You could try something like this. Here is the fiddle
HTML
<ul id="work">
<li>
<img src="http://placehold.it/350x150" />
<div class="caption">
<p>SERVICE 1</p>
<p>Service 1 description.</p>
</div>
<div class="clear">
</div>
</li>
<li>
<img src="http://placehold.it/350x150" />
<div class="caption">
<p>SERVICE 1</p>
<p>Service 1 description.</p>
</div>
<div class="clear">
</div>
</li>
<li>
<img src="http://placehold.it/350x150" />
<div class="caption">
<p>SERVICE 1</p>
<p>Service 1 description.</p>
</div>
<div class="clear">
</div>
</li>
</ul>
And CSS
#work li {
list-style-type: none !important;
margin-bottom: 10px;
}
#work li img {
float: left;
}
.caption {
float: left;
padding-left: 5px;
}

Change your float: left and float: right to display: inline-block;
The problem is that floated elements do not take up width and height in their parent. Using inline-block, the parent will expand to fit its children and will push the other elements down to make room.
I tried this out and it worked great.

Related

Why does adding "clear:both;" after a row of floated items clears issues with content push-overs?

When I was building a 2 columns layout and having the first items of each row floated to left, I was faced with an issue. If the element's text was much bigger than intended, the rows would break, items being pushed down, so instead of it looking like this:
it looks like this:
The code being:
<ul class="layout">
<li>
<article>
<div class="thumb">
<img class="img" alt="" src="">
</div>
<div class="post-info">
<h3>Hey there! You should make me bigger to break the layout.</h3>
<p>Some text here...</p>
</div>
</article>
</li>
<li>
<article>
<div class="thumb">
<img class="img" alt="" src="">
</div>
<div class="post-info">
<h3>Hey there! You should make me bigger to break the layout.</h3>
<p>Some text here...</p>
</div>
</article>
</li>
<li>
<article>
<div class="thumb">
<img class="img" alt="" src="">
</div>
<div class="post-info">
<h3>Hey there! You should make me bigger to break the layout.</h3>
<p>Some text here...</p>
</div>
</article>
</li>
<li>
<article>
<div class="thumb">
<img class="img" alt="" src="">
</div>
<div class="post-info">
<h3>Hey there! You should make me bigger to break the layout.</h3>
<p>Some text here...</p>
</div>
</article>
</li>
CSS:
.layout {
list-style: none;
}
.layout > li {
vertical-align: top;
width: 49%;
}
.layout > li:nth-child(odd) {
margin-right: 1%;
float: left;
}
.layout > li:nth-child(even) {
margin-left: 1%;
float: right;
}
Which works, but if we are to make the longer, it'd break.
If we add this line:
.layout > li:nth-child(even) + li {
clear: both;
}
It works just perfectly, no matter what I throw at it.
How come?
Just use only float: left for ALL elements in your case.
.layout {
list-style: none;
}
.layout>li {
vertical-align: top;
width: 49%;
float: left;
}
.layout>li:nth-child(odd) {
margin-right: 1%;
}
.layout>li:nth-child(even) {
margin-left: 1%;
}
<ul class="layout">
<li>
<article>
<div class="thumb">
<img class="img" alt="" src="">
</div>
<div class="post-info">
<h3>Hey there! You should make me bigger to break the layout.</h3>
<p>Some text here...</p>
</div>
</article>
</li>
<li>
<article>
<div class="thumb">
<img class="img" alt="" src="">
</div>
<div class="post-info">
<h3>Hey there! You should make me bigger to break the layout.</h3>
<p>Some text here...</p>
</div>
</article>
</li>
<li>
<article>
<div class="thumb">
<img class="img" alt="" src="">
</div>
<div class="post-info">
<h3>Hey there! You should make me bigger to break the layout.</h3>
<p>Some text here...</p>
</div>
</article>
</li>
<li>
<article>
<div class="thumb">
<img class="img" alt="" src="">
</div>
<div class="post-info">
<h3>Hey there! You should make me bigger to break the layout.</h3>
<p>Some text here...</p>
</div>
</article>
</li>
Application of clear clears out the floats for current container which would have otherwise got applied due to preceding or inherited styles.
The only layout that is now applied to these elements are their own. That's why, it works as desired.
https://developer.mozilla.org/en/docs/Web/CSS/clear
For your layout, you float box 1 to left, then box2 to left. Then, you apply clear:both because you want to stop applying floats. Then, for the next row boxes, you apply floats again because you want to place them left.
"When you apply clear:both to an element, it basically says "stop floating here" — this element and those after it in the source will not float, unless you apply a new float declaration to another element later on."

How to align picture with list of html?

I am new to html coding and I could not find exact and clear solution for my problem.
I want to create a page with this format: I want to do the page with list of html.
Here is my html code:
Although I made alignment center my picture is on the left side of the page. What is wrong or missing with my code?
There is no float: center. Only float: left and float: right. You can left-float all of <p> inside the <li> and set the width of them to 33.33%.
In this case the image has to be responsive:
img {
height: auto;
max-width: 100%;
}
Every <li> represent a row
<ul>
<li>
<p>text</p>
<p><img src=""></p>
<p>text</p>
</li>
</ul>
In total
img {
width: 100%;
height: auto;
}
ul {
list-style-type: none;
}
ul>li>* {
box-sizing: border-box;
display: block;
float: left;
word-break: break-all;
padding: 0 5px;
width: 33.333%;
}
.text-center {
text-align: center;
}
.full-width {
width: 100%;
}
<ul>
<li>
<p>
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
</p>
<p class="text-center">
<img src="http://placehold.it/300x200" alt="">
</p>
<p>
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
</p>
</li>
<li>
</li>
<li>
<p class="full-width">
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
</p>
</li>
<li>
<p class="full-width">
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
</p>
</li>
<li>
<li>
<p>
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
</p>
<p class="text-center">
<img src="http://placehold.it/300x200" alt="">
</p>
<p>
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
</p>
</li>
</ul>
You would probably be best looking into using a grid system. I would recommend using Twitter's Bootstrap - definitely the best as easiest to start using
http://getbootstrap.com/

Div inline not working

I want to display the menu in inline form but it's not working .Any help ?(Don't worry about the pictures).Here is a screenshot of what I want to achieve.The "As seen " will occupy the red holder on the screenshot.
<div class="header" style="display:inline;">
<div style="font-size:26px;">
<span> As seen on</span>
</div>
<div>
<img style="vertical-align: middle; background-color:#000;" src="<?php echo get_template_directory_uri(); ?>/images/marketing_ignite_logo.png" />
</div>
<div>
<img src="<?php echo get_template_directory_uri(); ?>/images/logo.gif" alt="Logo Buyseoleads">
</div>
<div class="seenBefore2" style="font-size:26px;">
<span>As seen on</span>
</div>
<div>
<img style="vertical-align: middle; background-color:#000;" src="<?php echo get_template_directory_uri(); ?>/images/release_wire_logo.png"/>
<!--img src="<?php //echo get_template_directory_uri(); ?>/images/daily-news-newspaper-headline.jpg" alt="Daily News Newspaper Headline"-->
</div>
</div>
Not a lot to go on here but I'll give it a try.
Every <div> has block context by default. Setting display: inline; on a parent <div> will not get inherited by child <div>s. Apply display: inline; to all <div>. Use <span> instead of <div> as it's an inline element by default and won't try to take up the whole width of the parent element by default.
Personally I would change the markup a bit if you're Looking to create a menu. Use <nav>, <ul>, <li>, <a> etc. instead. Perhaps something like I have below.
ul,
li {
margin: 0;
padding: 0;
list-style: none;
}
li {
padding: 3px 6px;
float: left;
}
li img {
vertical-align: middle;
}
<header>
<nav>
<ul>
<li>As seen on
<a href="#">
<img src="http://placehold.it/50x50/ffcc00/">
</a>
</li>
<li>As seen on
<a href="#">
<img src="http://placehold.it/50x50/cc0000/">
</a>
</li>
</ul>
</nav>
</header>
The problem is that display: inline; won't allow any block styling. And you used it on block element. If you want elements to be on the same line, you should consider using, for example, float property
.header div {
float: left;
}
But do not forget about clearing the floats.
If I understand you correctly, you want your blocks (as seen on, with image) in a row? If so, you can use floats. Note also I have replaced your images with placeholdit ones.
https://jsfiddle.net/aa8zs200/
<div style="width: 100%; position: relative;">
<div style="float: left; margin-right: 10px;">
<div style="font-size:26px;"><span> As seen on</span></div>
<div>
<a href="https://www.marketingignite.com/basic-commonsensical-seo-tips-and-tricks/" target="_blank">
<img style="vertical-align: middle; background-color:#000;" src="http://placehold.it/350x150" /> </a>
</div>
</div>
<div style="float: left; margin-right: 10px;">
<div style="font-size:26px;"><span> As seen on</span></div>
<div>
<img src="http://placehold.it/350x150" alt="Logo Buyseoleads">
</div>
</div>
</div>
span{
margin:0;
padding:0;
}
or
span{
display:block;
float:left;
padding:0 10px;
}
For this question,You should set the display:inline attribute for all of the inner divs, not for the outer div.

CSS - Display images side by side

I'm creating a web page that shows pictures of cute dogs. For every dog, I want to show the name of the dog and then a picture below it.
I would like the images to be shown side by side, but they are shown stacked vertically.
Here is my fiddle
http://jsfiddle.net/53bnhscm/2/
Here is my HTML
<h1>Listing dogs</h1>
<ul>
<li> Dog 1 </li></br>
<li>
<a href="/dogs/2">
<img alt="Dog 1" src="http://renterswarehouse.com/wp-content/uploads/2013/12/Cute-Dog-dogs-13286656-1024-768-200x200.jpg" />
</a>
</li>
</ul>
<ul>
<li> Dog 2 </li></br>
<li>
<a href="/dogs/3">
<img alt="Dog 2" src="https://v.cdn.vine.co/r/avatars/1D8A5A9AD81112510785588019200_21ff866832a.1.0.jpg?versionId=0I_eiPNigLBtjlgOMJIQyCYY4fKf2YNs" />
</a>
</li>
</ul>
Here is my CSS
li {
list-style: none;
display: inline;
}
I thought a break statement after every list item and a display:inline property would do the trick, but I guess not.
Another solution is to use display: table-cell to ul elements:
ul {
display: table-cell;
}
li {
list-style-type: none;
}
<h1>Listing dogs</h1>
<ul>
<li>Dog 1</li>
</br>
<li>
<a href="/dogs/2">
<img alt="Dog 1" src="http://renterswarehouse.com/wp-content/uploads/2013/12/Cute-Dog-dogs-13286656-1024-768-200x200.jpg" />
</a>
</li>
</ul>
<ul>
<li>Dog 2</li>
</br>
<li>
<a href="/dogs/3">
<img alt="Dog 2" src="https://v.cdn.vine.co/r/avatars/1D8A5A9AD81112510785588019200_21ff866832a.1.0.jpg?versionId=0I_eiPNigLBtjlgOMJIQyCYY4fKf2YNs" />
</a>
</li>
</ul>
Your lis are contained within their own ul so you need to inline that instead.
ul {
list-style: none;
display: inline-block; //use instead of inline
}
FIDDLE
Also li tags are more for list items so this isn't a real efficient way of doing this. Plus its a lot of extra code. You could simply wrap your sections in a container and inline that:
HTML
<h1>Listing dogs</h1>
<div class="wrapper">
Dog 1
<a href="/dogs/2">
<img alt="Dog 1" src="..." />
</a>
</div>
<div class="wrapper">
Dog 2
<a href="/dogs/3">
<img alt="Dog 2" src="..." />
</a>
</div>
CSS
.wrapper{
display: inline-block;
}
.wrapper a{
display: block;
}
EXAMPLE
Here a fiddle. Your markup is messy by the way, I recommend to use HTML5 markup <figure> so you can easily add a <figcaption>: http://jsfiddle.net/53bnhscm/7/
<h1>Listing dogs</h1>
<figure>
<figcaption>Dog 1</figcaption>
<img alt="Dog 1" src="http://renterswarehouse.com/wp-content/uploads/2013/12/Cute-Dog-dogs-13286656-1024-768-200x200.jpg" />
</figure>
<figure>
<figcaption>Dog2</figcaption>
<img alt="Dog 2" src="https://v.cdn.vine.co/r/avatars/1D8A5A9AD81112510785588019200_21ff866832a.1.0.jpg?versionId=0I_eiPNigLBtjlgOMJIQyCYY4fKf2YNs" />
</figure>
CSS
figure {
float:left;
display:inline-block;
}
ul > li {
list-style: none;
display: inline;
float: left;
margin: 0 5px;
}
And I think may be you are looking something like this. In that case you have to edit your html code
http://jsfiddle.net/ahmadsharif/p0cbmy2h/
The following answer is correct for your markup.
ul {
list-style: none;
display: inline-block; //use instead of inline
}
But if you mean exactly what is written in your question then one thing that I need to mention and it is “You should take care of your HTML markup.”
<ul>
<li>
<a href="/dogs/2">
<b>Dog 1</b>
<img alt="Dog 1" src="http://renterswarehouse.com/wp-content/uploads/2013/12/Cute-Dog-dogs-13286656-1024-768-200x200.jpg" />
</a>
</li>
<li>
<a href="/dogs/3">
<b>Dog 2</b>
<img alt="Dog 2" src="https://v.cdn.vine.co/r/avatars/1D8A5A9AD81112510785588019200_21ff866832a.1.0.jpg?versionId=0I_eiPNigLBtjlgOMJIQyCYY4fKf2YNs" />
</a>
</li>
</ul>
and then your CSS will be:
ul li{
display: inline-block;
}
ul li a b{
display: block;
text-align: center;
margin-bottom: 5px
}
Just use UIKIT and its grid system. This way they will stack automatically on phones.
http://getuikit.com/docs/grid.html
<div class="uk-grid">
<div class="uk-width-1-2">Your Image HERE</div>
<div class="uk-width-1-2">Another Image Here</div>
</div>

I am having problems with CSS getting ads to line up

I am building a website and I have three ads towards the bottom of my page. They appear but on there own line. I have tried everything from creating a floating div to removing divs. But I can't seem to figure out what part of the CSS isn't allowing these boxes to be straight across the page.
Here is the code for the three boxes:
<div class="wrapper margin-bot1">
<div class="bg-3">
<div class="indent">
<div class="wrapper margin-bot">
<img src="http://www.webstertoolbox.com/media/wysiwyg/images/page1_img1.png" alt="" />
<img src="http://www.webstertoolbox.com/media/wysiwyg/images/logo_archilume.png" alt="" width="150" height="41" />
</div>
<ul class="ul-1">
<li>Made in USA </li>
<li>Expert Domestic Tech Support</li>
<li>High-end installations</li>
<li>Robust features</li>
</ul>
<a class="button-1 margin-left" href="more.html">Click to Order Now!</a>
</div>
</div>
<div class="bg-3">
<div class="indent">
<div class="wrapper margin-bot">
<img src="http://www.webstertoolbox.com/media/wysiwyg/images/page1_img1.png" alt="" />
<img src="http://www.webstertoolbox.com/media/wysiwyg/images/GenLume-Logo.png" alt="" width="103" height="41" />
<div class="extra-wrap"> </div>
</div>
<ul class="ul-1">
<li><a class="test123" href="moreGEN.html">Quick solutions</a></li>
<li>Turn-key applications</li>
<li>Certified</li>
<li>Competitive pricing</li>
</ul>
<a class="button-1 margin-left" href="moreGEN.html">Click to Order Now!</a>
</div>
</div>
<div class="bg-3">
<div class="indent">
<div class="wrapper margin-bot">
<img src="http://www.webstertoolbox.com/media/wysiwyg/images/page1_img1.png" alt="" />
<div class="extra-wrap">
<h4>DuraLume</h4>
<h5>Series</h5>
</div>
</div>
<ul class="ul-1">
<li>Expert Domestic Tech Support</li>
<li>Made in USA </li>
<li>Custom solutions</li>
<li>On-site Engineers</li>
</ul>
<a class="button-1 margin-left" href="more.html">Click to Order Now!</a>
</div>
</div>
</div>
I can't figure out how to properly show the CSS but you can find the actual site here: http://www.webstertoolbox.com/
If you look below the Big banner you will see an ArchiLume, GenLume and DuraLume boxes that run vertically down the page. I want them to appear across the page.
Can someone please tell me what I did wrong and how to fix it?
Thanks,
Frank G.
Very easy and fast to fix it.
Just change your css file named homeads.css on line 128:
.bg-3
{
background: url(../images/bg-4.png) left top no-repeat;
width: 33%; // Changed this from 100% to 33%
height: 322px; //Changed from 268px to 322px
overflow: hidden;
float: left; // Added the float left
}
Cheers,
Thanos
EDIT: After doing the change above you will need to add a couple more changes to fix a couple of things that will get a bit misaligned.
Such as the right border will not be visible anymore. Below are the changes you will need to do to fix that as well.
On homeads.css line 33:
.main
{
width: 950px; // Reduced this to match with the parent's width
padding: 0;
margin: 0 auto;
position: relative;
}
On sceleton.css line 25:
.grid_1, .grid_2, .grid_3, .grid_4, .grid_5, .grid_6, .grid_7, .grid_8, .grid_9, .grid_10, .grid_11, .grid_12, .grid_13, .grid_14, .grid_15, .grid_16, .grid_17, .grid_18, .grid_19, .grid_20, .grid_21, .grid_22, .grid_23, .grid_24
{
float: left;
display: inline;
//margin-left: 5px; Remove these 2
//margin-right: 5px; Remove these 2
}
EDIT2: The first box is getting pushed down a little bit. That is caused because on the first box you are missing a div <-> on the second and third box you have an extra div inside them.
<div class="wrapper margin-bot">
<img src="http://www.webstertoolbox.com/media/wysiwyg/images/page1_img1.png" alt=""> <img src="http://www.webstertoolbox.com/media/wysiwyg/images/duralume.gif" alt="" width="103" height="41">
<div class="extra-wrap"> </div> // THIS IS THE EXTRA DIV
</div>
You have 2 choices here:
1) Add the div
<div class="extra-wrap"> </div>
to the first box
2) Remove that div from box 2 and 3.
.cms-home class help you do not affect other pages layout. Add in your stylesheets:
.cms-home .wrapper {
overflow: visible; //For big banner
}
.cms-home .bg-3 {
overflow: visible;
width: 33%;
display: inline-block;
}