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>
Related
Basically I want to have a small row with 4 social icons in middle of screen. I wanted to have it middle of screen wheather I am opening my page in mobile, laptop or tab.
I have applied width:50% but issue is ul li's images are in left side. What I can do is to use media queries for all screen resolution but that will be not good as then for every screen/resolution point I have to make queries which is not good practise.
I think I am missing something easier about this point but I am not getting that.
You can see my code here
In short : I want to have my all 4 icons in middle of row in every screen(big, small) with fix gap between them.
HTML
<ul class="footerUl">
<li>
<img src="https://cdn0.iconfinder.com/data/icons/social-network-9/50/3-128.png" height="32" width="32">
</li>
<li>
<img src="https://cdn0.iconfinder.com/data/icons/social-network-9/50/3-128.png" height="32" width="32">
</li>
<li>
<img src="https://cdn0.iconfinder.com/data/icons/social-network-9/50/3-128.png" height="32" width="32">
</li>
<li>
<img src="https://cdn0.iconfinder.com/data/icons/social-network-9/50/3-128.png" height="32" width="32">
</li>
<div class="clearfix"></div>
</ul>
CSS
.clearfix{clear:both;}
ul li{list-style-type:none;float:left;padding-left:7%;}
ul li:first-child{padding-left:0px !important;}
ul li:last-child{padding-left:0px !important;}
ul{padding-left:0px;width:50%;margin-left:auto;margin-right:auto;}
You can simply use flex for doing that.
Review the answer below :
.clearfix{
clear: both;
}
ul li{
list-style-type: none;
float: left;
padding-left: 20px;
}
ul li:first-child{
padding-left: 0px !important;
}
ul li:last-child{
padding-left: 0px !important;
}
ul{
padding-left: 0px;
width: 50%;
margin-left: auto;
margin-right: auto;
}
.footerUl {
display: flex;
justify-content: center; /* align horizontal */
align-items: center; /* align vertical */
}
<ul class="footerUl">
<li>
<img src="https://cdn0.iconfinder.com/data/icons/social-network-9/50/3-128.png" height="32" width="32">
</li>
<li>
<img src="https://cdn0.iconfinder.com/data/icons/social-network-9/50/3-128.png" height="32" width="32">
</li>
<li>
<img src="https://cdn0.iconfinder.com/data/icons/social-network-9/50/3-128.png" height="32" width="32">
</li>
<li>
<img src="https://cdn0.iconfinder.com/data/icons/social-network-9/50/3-128.png" height="32" width="32">
</li>
<div class="clearfix"></div>
</ul>
I'm not sure if you like this way. But instant I have this idea.
ul.footerUl{
text-align:center;
}
ul li{list-style-type:none;display:inline-block;}
ul li img{ margin:5px 20px;}
<ul class="footerUl">
<li>
<img src="https://cdn0.iconfinder.com/data/icons/social-network-9/50/3-128.png" height="32" width="32">
</li>
<li>
<img src="https://cdn0.iconfinder.com/data/icons/social-network-9/50/3-128.png" height="32" width="32">
</li>
<li>
<img src="https://cdn0.iconfinder.com/data/icons/social-network-9/50/3-128.png" height="32" width="32">
</li>
<li>
<img src="https://cdn0.iconfinder.com/data/icons/social-network-9/50/3-128.png" height="32" width="32">
</li>
</ul>
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.
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.
The text representing each image is currently located to the right of the image. I want the text to be centered underneath its corresponding image, how do I achieve this?
Please note that I applied display: inline-bock on the list items, so they are in a row.
#footer1 {
float: left;
width: 100%;
border: 10px solid #e3e3e3;
}
#footer1>ul>li {
padding: 0 8px;
display: inline-block;
}
#footer1 a:hover img {
border: 1px solid #5cadff;
text-decoration: none;
box-shadow: 5px 5px 2px 2px #5cadff;
}
#footer1 img {
border: 1px solid transparent;
margin-left: 110px;
}
<div id="footer1">
<h2> SOURCES </h2>
<ul>
<li>
<a href="https://www.wikipedea.com" title="wikipedia">
<img height="50" src="http://www.placehold.it/50" width="50">
</a>
w
</li>
<li>
<a href="https://www.google.com" title="google">
<img height="50" src="http://www.placehold.it/50" width="50">
</a>
Google
</li>
<li>
<a href="https://www.youtube.com" title="youtube">
<img height="50" src="http://www.placehold.it/50" width="50">
</a>
Youtube
</li>
<li>
<a href="https://www.nlm.nih.gov/" title="Nih.gov">
<img height="50" src="http://www.placehold.it/50" width="50">
</a>
Nih
</li>
<li>
<a href="https://www.medindia.net" title="MedIndia.net">
<img height="50" src="http://www.placehold.it/50" width="50">
</a>
MedIndia
</li>
</ul>
</div>
I was able to do this without any changes to your existing HTML by doing this:
li{
display:inline-block;
text-align:center;
width:70px;
}
li img{
margin:0 10px;
}
The text-align centers all text and child elements inside the li. The width needs to be large enough that no caption will be too large to fit in that width. (If a caption won't fit in the allotted width, then the centering is wrecked.)
I added the left and right margin to the image for a little bit of future-proofing in case you later want to include a very short caption in your list. With that margin, even a very short caption will be forced to the next line (instead of next to the image) since 50 px image width + 10 margin on each side leaves no room for text.
Edited for float, keeps these inline and overflows if doesn't fit on page.
<style>
.container {
clear: both;
}
ul li {
width: 50px;
float: left;
text-align: center
}
ul li a {
text-decoration: none;
}
</style>
<div class="container">
<ul>
<li>
<a title="wikipedia" href="https://www.wikipedea.com">
<img src="wikipedia.png" height="50" width="50">wikipedia
</a>
</li>
<li>
<a title="wikipedia" href="https://www.wikipedea.com">
<img src="wikipedia.png" height="50" width="50">wikipedia
</a>
</li>
<li>
<a title="wikipedia" href="https://www.wikipedea.com">
<img src="wikipedia.png" height="50" width="50">wikipedia
</a>
</li>
</ul>
</div>
Please try this
HTML:
<div id="footer1">
<h2> SOURCES </h2>
<div class="item">
<a title="wikipedia" href="https://www.wikipedea.com">
<img src=""/>
</a>
<span class="caption">Text below the image</span>
</div>
<div class="item">
<a title="wikipedia" href="https://www.wikipedea.com">
<img src=""/>
</a>
<span class="caption">Text below the image</span>
</div>
<div class="item">
<a title="wikipedia" href="https://www.wikipedea.com">
<img src=""/>
</a>
<span class="caption">Text below the image</span>
</div>
</div>
CSS:
div.item {
vertical-align: top;
display: inline-block;
text-align: center;
width: 120px;
}
img {
width: 100px;
height: 100px;
background-color: grey;
}
.caption {
display: block;
}
DEMO
I stacked on the following problem. I have got an unordered list with the social icons and kind of a little dot appears on the right down corner of the icons when I change the display to inline.
HTML
<div class="iconos">
<ul class="contacto">
<li>
<a href="mailto:xxxxxx.com" class="socialicon">
<img src="images/mail.png" width="50" height="50">
</a>
</li>
<li>
<a href="https://www.facebook.com/pages/xxxxx" class="socialicon">
<img src="images/facebook.png" width="50" height="50">
</a>
</li>
<li>
<a href="https://www.facebook.com/pages/xxxx" class="socialicon">
<img src="images/twitter.png" width="50" height="50">
</a>
</li>
</ul>
CSS
ul.contacto {
list-style: none;
padding: 0;
margin: 0;
}
.contacto li {
padding: 20px;
display: inline;
}
That dot is an underline from <a> element. You can hide with this:
.contacto li a {
text-decoration: none;
}