Bar notsticking to picture css/html - html

I'm having a problem with css.
When my image becomes smaller than the list next to it, the grey bar at the bottom of the picture (.meter) won't stick anymore to the picture. I don't know how to solve this. I think it's the opposite of clear that I need, But I couldn't find it on the internet
here is the jsFiddle:
http://jsfiddle.net/RnSq7/
<img src="http://images7.alphacoders.com/407/407975.jpg" />
<section>
<p>
<ul>
<li>long list</li>
<ul>
</p>
</section>
<div class="meter"><span style="width: 50%"> </span></div>
I hope sombeody can help me, thanks in advance.

Just change the order in your markup :
FIDDLE
<img src="http://images7.alphacoders.com/407/407975.jpg" />
<div class="meter"><span style="width: 50%"> </span>
</div>
<section>
<p>
<ul>
<li>shalalalala</li>
<li>shalalalala</li>
<li>shalalalala</li>
<li>shalalalala</li>
...
</ul>
</p>
</section>
I didn't mention but you are missing the / sign on your closing ul tag in your fiddle. I corrected that typo in the demo too.

Simplest way is to take the div and put it just after the img. But if your div will not house any other element, I would suggest to take it off and use 'border-bottom' property.
Option 1:
<img src="" />
<div class="meter"><span style="width: 50%"> </span>
</div>
<section>
<p>
<ul>
<li>shalalalala</li>
<li>shalalalala</li>
<li>shalalalala</li>
<li>shalalalala</li>
</ul>
<p>
</section>
Options 2:
<img src="" class="test"/>
and then in stylesheet
.test {
border-bottom: 20px solid black;
}

Related

How do I center a bullet point on a screen?

When I use the <center> tag along with the <ul> tag in my html code, The bullet points are staying on the left while the text is appearing in the center. How do I fix this?
here is the problematic code:
<center>
<h2>future projects</h2>
<div>
<ul>
<li>Weird dreams</li>
</ul>
</div>
</center>
I've tried everything I can think of, but none of it has worked.
UPDATE:
<center> is Deprecated in HTML4 onwards. So, it can be replaced using CSS as:
<div style="text-align:center">
<h2>future projects</h2>
<div>
<ul style="list-style-position: inside;">
<li>Weird dreams</li>
</ul>
</div>
</div>
Use list-style-position to center the unordered list bullets.
<center>
<h2>future projects</h2>
<div>
<ul style="list-style-position: inside;">
<li>Weird dreams</li>
</ul>
</div>
</center>
set style as list-style-position: inside; for "ul"
The center tag is deprecated.
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/center
Use style-sheet instead...
Like here :
#center{
text-align: center;
}
#center ul{
margin:0px;
padding:0px;
}
<div id="center">
<h2>future projects</h2>
<div>
<ul>
<li>Parrot</li>
<li>stiff</li>
<li>Pining for the flords</li>
<li>resting</li>
</ul>
</div>
</div>

Want to align image in front of text but at center

I want to align image in front of text and in the middle .
<div id="info">
<ul>
<h3>
<li>NAME: Mohit Kumar Singh</li>
<li>CONTACT:1234567890</li>
<li>ADDERESS:police line</li>
</h3>
</ul>
</div>
<div id="over" style="width:100%; height:100%" align="center">
<img src="mks.jpg" height="150" width=120" >
</div>
If you mean you want the image and the text to be displayed on the same link, then this should work:
I added a container div around both divs and then displayed them inline-block (inline to be on the same line, block so that the image can have a width).
However, for this to work, your style for id="over" was removed.
#container {
text-align: center;
}
#container div {
display: inline-block;
}
<div id="container">
<div id="info">
<h3>
<ul>
<li>NAME: Mohit Kumar Singh</li>
<li>CONTACT:1234567890</li>
<li>ADDERESS:police line</li>
</ul>
</h3>
</div>
<div id="over">
<img src="mks.jpg" height="150" width="120">
</div>
</div>

Div in LI causes extra row before content

If I have the following HTML. Why does the content of the li drop down a line?
I am looking for an explanation of the behaviour and how to fix
<html>
<body>
<div>
<ol>
<li>
<div>
<div style='width:65%;float:left;'>
Left Text
</div>
<div style="width:35%;float:left;font-style: italic;">
Right Text
</div>
<div style='clear:both;'></div>
</div>
</li>
</ol>
</div>
</body>
</html>
<html>
<body>
<div>
<ol>
<li>
<table>
<tbody>
<tr><td>left</td><td>right</td></tr>
</tbody>
</table>
</li>
</ol>
</div>
</body>
</html>
The DIV's are set as display: block by default, therefore it does not stay in the same line as the LI..
If you set it as display: inline; it will force it to stay in the same line
<html>
<body>
<div>
<ol>
<li>
<div style="display: inline;">
<div style='width:65%;float:left;'>
Left Text
</div>
<div style="width:35%;float:left;font-style: italic;">
Right Text
</div>
<div style='clear:both;'></div>
</div>
</li>
</ol>
</div>
</body>
</html>
Edit:
as Billy said there is an issue with the floats, but changing them to inline-block adds another issue, the margin look at this explanation
Adding a SPAN instead of a div won't solve the issue, because the difference is that the SPAN is display: inline; by default, (the same as we have now with the DIV)
<html>
<body>
<div>
<ol>
<li>
<div style="display: inline;">
<div style="width:65%;display: inline-block;margin-right: -2px;">Left Text</div>
<div style="width:35%;display: inline-block;font-style: italic;margin-left: -2px;">Right Text</div>
</div>
</li>
</ol>
</div>
</body>
</html>

CSS Layout is unexpected

I am designing a website for software created by my self. For this, I need a layout in which three boxes are on the same horizontal position. But as I put text in those they start shifting.
What might be the possible cause?
<body class="metro">
<nav class="navigation-bar">
<nav class="navigation-bar-content">
<div class="element">My Software Name</div>
<span class="element-divider"></span>
<a class="element place-right" href="#">Download</a>
</nav>
</nav>
<div class="slideImage"></div>
<div class="about">
<div class="infoBar">
<h2>What is ?</h2>
<span class="paragraph">
this is example text to illustrate the real problem regardig the info bar alingment
</span>
</div>
<div class="infoBar"><h2>Why this ?</h2>
<span class="paragraph">
</span>
</div>
<div class="infoBar"><h2>About</h2></div>
</div>
</body>
Here is full Scree Example
You could do it by set the vertical-align:top; to .infoBar to remove the vertical whitespace between inline-block elements.
JSFiddle - DEMO
CSS:
.infoBar {
vertical-align:top;
}

section tag inside unordered list or around?

i'm still very confused about the use of "section" in html 5. I'd just like to which of the below solutions is the better one. The contents inside the list are not related to each other. So do I have to give a section to each of them or do I have to put it all in one section. See below:
Solution one:
<ul>
<li>
<section>
<header>
<h2>Services</h2>
</header>
<img src="img/foto/testpic1.jpg" alt="" title="" border="0"/>
<p>This is text</p>
</section>
</li>
<li>
<section>
<header>
<h2>Products</h2>
</header>
<img src="img/foto/testpic2.jpg" alt="" title="" border="0"/>
<p>This is text</p>
</section>
</li>
<li>
<section>
<header>
<h2>Contacts</h2>
</header>
<img src="img/foto/testpic3.jpg" alt="" title="" border="0"/>
<p>This is text</p>
</section>
</li>
</ul>
Solution two:
<section>
<ul>
<li>
<header>
<h2>Services</h2>
</header>
<img src="img/foto/testpic1.jpg" alt="" title="" border="0"/>
<p>This is text</p>
</li>
<li>
<header>
<h2>Products</h2>
</header>
<img src="img/foto/testpic2.jpg" alt="" title="" border="0"/>
<p>This is text</p>
</li>
<li>
<header>
<h2>Contacts</h2>
</header>
<img src="img/foto/testpic3.jpg" alt="" title="" border="0"/>
<p>This is text</p>
</li>
</ul>
</section>
I'm not sure why you need the list (<ul>) in the first place here. I'd remove it since it makes sense to use it for actual lists only ( or list-like elements, i.e. menus ) which is not the case here.
Now about the <section>. According to specs:
The <section> element represents a generic section of a document or application. A section, in this context, is a thematic grouping of content, typically with a heading.
Which eliminates your solution #2.
More:
Authors are encouraged to use the <article> element instead of the <section> element when it would make sense to syndicate the contents of the element.
So In your case I's do this:
<article>
<header>
<h2>Services</h2>
</header>
<img src="img/foto/testpic1.jpg" alt="" title="" border="0"/>
<p>This is text</p>
</article>
<article>
<header>
<h2>Products</h2>
</header>
<img src="img/foto/testpic2.jpg" alt="" title="" border="0"/>
<p>This is text</p>
</article>
<article>
<header>
<h2>Contacts</h2>
</header>
<img src="img/foto/testpic3.jpg" alt="" title="" border="0"/>
<p>This is text</p>
</article>
And if you need a wrapper for styling purposes - you can use the good ol' <div>
The <section> element is not a generic container element. When an element is needed for styling purposes or as a convenience for scripting, authors are encouraged to use the <div> element instead.
The section element
An article on topic
<section> and <div> are similar in that they are both used for sectioning. The difference is that if the intended section is for the purpose of styling, <div> should be used... but if the section is literally for content then use <section>. Have a look at the following quote:
“When an element is needed only for styling purposes or as a
convenience for scripting, authors are encouraged to use the div
element instead…A general rule is that the section element is
appropriate only if the element’s contents would be listed explicitly…
~ WHATWG”
Please note that the general idea of <section> is to list content like <li>. However, the latter is more appropriate for bullet pointing... whereas, the former is more appropriate for things like blog posts, etc.
So, I don't really recommend either of your solutions. You should use something similar to the following:
<div class="blog">
<article class="post">
<h2 class="post-title">Services</h2>
<img src="img/foto/testpic1.jpg" alt="" title="" border="0"/>
<p class="post-excerpt">This is text</p>
</article>
<article class="post">
<h2 class="post-title">Products</h2>
<img src="img/foto/testpic2.jpg" alt="" title="" border="0"/>
<p class="post-excerpt">This is text</p>
</article>
<article class="post">
<h2 class="post-title">Contacts</h2>
<img src="img/foto/testpic3.jpg" alt="" title="" border="0"/>
<p class="post-excerpt">This is text</p>
</article>
</div>
I hope that helps. All the best.
[ref: https://azizecomm.wordpress.com/2016/01/04/html5-section-vs-div/]