When inspecting my elements, i noticed my height on the first li is very low.
I'm trying to add a background to the whole li after selecting the "city (2)".
The background fills only City(2) an half of New York. I tried without floating, but then i can't get them lined up.
I've added 2 photos. One where i have floating, and one without.
<ul class="specs">
<li>
<div class="trigger">› City (2)</div>
<div class="cityByLocation">
<ul>
<li class="cityInfo">
<div class="cityName" style="float: left;">
› New York
</div>
<div class="cityDistance" style="float: left;">
430 miles
</div>
<div class="btn-take"></div>
</li>
<li class="cityInfo">
<div class="cityName" style="float: left;">
› Chicago
</div>
<div class="cityDistance" style="float: left;">
430 miles
</div>
<div class="btn-take"></div>
</li>
</ul>
</div>
</li>
<ul>
css:
.cityName{
float: left;
width: 45%;
}
.cityDistance {
float: left;
width: 20%;
}
.specs {
padding: 0;
}
.specs li {
padding: 0;
padding-top: 10px;
list-style: none;
}
.specs ul {
list-style: none;
padding: 0;
}
You need to clear your floats as Eric said. The simplest way to achieve that is by applying overflow: hidden to the container, so:
.cityByLocation {
overflow: hidden;
}
http://jsfiddle.net/a3GLG/
I think this will solve your problem.
The problem happens when a floated element is within a container box, that element does not automatically force the container’s height adjust to the floated element. When an element is floated, its parent no longer contains it because the float is removed from the flow.
You can use 2 methods to fix it:
{clear:both} or .clearfix
.clearfix:after {
content: ".";
display: block;
clear: both;
visibility: hidden;
line-height: 0;
height: 0;
}
.clearfix {
display: inline-block;
}
html[xmlns] .clearfix {
display: block;
}
* html .clearfix {
height: 1%;
}
source
You can also fix it by setting overflow: hidden to li element. It will clear and auto calculate height.
-- update --
thanks #mickmackusa
https://jsfiddle.net/e94pzbbn/1/
Related
I am currently working with a webshop, and I have some trouble centering the top menu.
The code look like this:
<div id="webshop-topmenu" class="row logoRow ProductMenu_TD">
<div align="center">
<div class="small-12 columns menus">
<nav class="top-bar productmenu" data-topbar role="navigation">
<ul class="title-area">
<li class="name"></li>
<li class="toggle-topbar menu-icon"><span>Menu</span></li>
</ul>
<section class="top-bar-section">[[ProductMenu]]</section>
</nav>
<div class="sub-nav pagelinks TopMenu_TD hide-for-small">[[TopMenu]]</div>
</div>
</div>
</div>
No matter what code I use, the menu always aligns to the right, and I want to center it.
I have tried the <div align"center"> and <center> and a couple of other codes, but nothing seems to work.
Hope you can help me here.
What it looks like
<center> and "align"
are deprecated.
After getting a link to the page:
If you want to center the ul#ProductMenu_List, change your CSS:
.top-bar-section #ProductMenu_List {
margin: 0 auto;
//float: right;
//margin-right: -10px;
}
.top-bar-section ul li {
//float: left;
display: inline-block;
}
If you want to center your div.TopMenu_TD, do following in CSS:
.logoRow .menus .pagelinks {
//float: right;
}
If you want to center elements, "float" is in most case the opposite of helpful. Text-align: center, display: inline-block and/or margin: 0 auto are in most case the solution.
And take your to google for Html5 and CSS3. You will need it.
Update
After seeing that you only have access to the templates - add following code to "Kodefelter" - Head:
<style>
.top-bar-section #ProductMenu_List {
margin: 0 auto;
float: none;
max-width: 400px;//or another value
display: block;
}
#ProductMenu_List > li {
float: none;
display: inline-block;
}
.logoRow .menus .pagelinks {
float: none;
display: block!important;
margin: 0 auto;
max-width: 500px;
}
</style>
After trying to add clamping to my headers, my result does not turn out the way I wanted.
I made a fiddle of the code that I am using to achieve my result: https://jsfiddle.net/73kerhsn/
h3
{
margin: 0;
font-size: 13px;
}
ul
{
list-style: none;
padding: 0;
margin: 0;
}
li
{
display: inline-block;
margin: 2px;
padding: 0;
}
.acontainer
{
background-color: yellow;
width: 500px;
padding: 15px;
}
.background
{
background-color: grey;
width: 196px;
}
.block1
{
height: 110px;
width: 195px;
background-color: red;
}
.clamp
{
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
}
<div class="acontainer">
<ul>
<li class="background">
<div class="block1">
</div>
<h3 class="clamp">
This foo test asdas asdassd saasas dasasa asdasadsd asasddas asdadsg gfhfhg gddfd sddsfsdf
</h3>
<div>
Something
</div>
<div>
Something else
</div>
</li>
<li class="background">
<div class="block1">
</div>
<h3>
This foo test
</h3>
<div>
Something
</div>
<div>
Something else
</div>
</li>
<li class="background">
<div class="block1">
</div>
<h3>
This foo test
</h3>
<div>
Something
</div>
<div>
Something else
</div>
</li>
</ul>
</div>
I want the list items to stay at the same height, even when the header tags get bigger than the ones of the other list items (so for example, the second list item in the jsfiddle appears to be lower from the top than the first list item. I want it to still stick to the top (with the padding still in tact)).
Is there anyone out there that can help me with this?
Thanks in advance.
You probably simply want to add vertical-align: top for your list items.
li
{
display: inline-block;
margin: 2px;
padding: 0;
vertical-align: top;
}
https://jsfiddle.net/73kerhsn/1/
You can just apply this to your css for styling the list-items:
li{
display: inline-table;
}
This will make your li items start from the same height, now you can set the height as you want, it won't hamper your next line contents. If you won't set a fixed height, then only the start of the boxes will remain same.
I want to make an image in the left and the text on the right.
This is a jsfiddle
http://jsfiddle.net/VnnZ2/
I put the image in a div with class imageClass and I put the text in a div with class information and I gave the imageClass left float and the information right float.
I also tried to make this:
display: inline-block;
for both classes but still the result as you see in the jsfiddle.
I tried the same css with label and input and it works but I don't know why it is not working with div and div.
Plus, I already give the imageClass a width 200 and the informaton class a width 300 and the ul width 500px so I tried all what I could
Update 1
Sorry I gave you the wrong jsfiddle by mistake, this is the correct one http://jsfiddle.net/VnnZ2/9/
Check this updated code
HTML:
div class="allRestaurants">
<ul>
<li>
<div class="imageClass">
<img src="https://www.google.com/images/srpr/logo11w.png"/>
</div>
<div class="information">
nameres </div>
</li>
</ul>
<ul>
<li>
<div class="imageClass">
<img src="https://www.google.com/images/srpr/logo11w.png"/>
</div>
<div class="information">
Zuma 2 </div>
</li>
</ul>
</div>
CSS:
.allRestaurants{
background-color: #376b66;
width:100%;
float:left;
}
.allRestaurants ul{
margin: 10px;
padding: 0;
width: 600px;
background-color: #ffffff;
margin-left: 10px;
width:90%;
overflow:auto;
}
.allRestaurants ul li{
margin-bottom: 10px;
list-style: none;
box-sizing: border-box;
border-radius: 10px;
-webkit-border-radius: 10px;
}
.allRestaurants ul li .imageClass{
float: left;
}
.allRestaurants ul li .imageClass img{
width: 200px;
height: 200px;
}
.allRestaurants ul li .information{
width: 250px;
}
.allRestaurants ul li{
float:left;
clear:both;
}
Updated JS FIDDLE CODE
You need to clear your floats to stop the parent element collapsing. There are a number of ways. This is probably the simplest to understand:
WORKING DEMO
<li>
<div class="imageClass">
<img src="https://www.google.com/images/srpr/logo11w.png"/>
</div>
<div class="information">nameres</div>
<div class="clearfix"></div> /* Add an empty element with class .clearfix */
</li>
In your CSS:
.clearfix {
clear: both;
}
Or this method:
WORKING DEMO
.clearfix:before,
.clearfix:after {
content: " ";
display: table;
}
.clearfix:after {
clear: both;
}
Where the clearfix class would be applied to the parent element(li)
Add overflow: auto; to .allRestaurants ul li, that way the li will know that there are elements inside it that float.
Also, check this updated Fiddle.
On my markup I expect the footer with 25 pixels of bottom margin. I did this:
div.footer {
margin-bottom: 25px;
}
Without success — there is no bottom margin. If I do this:
div.footer {
margin-bottom: 25px;
float: left;
}
It works!
I know! I can solve the problem with floating, but it is a good practice? There is no other way?
Thanks in advance.
== UPDATE! / A little piece of my code ==
CSS:
div.rlside-margin {
margin: 0 25px;
}
div.tpside-margin {
margin: 25px 0;
}
div.allside-margin {
margin: 25px;
}
div.max-width {
width: 60em;
margin: 0 auto;
}
div.header {
background-color: #efefef;
width: 100%;
height: 90px;
}
div.post-header {
background-image: url("/Images/PostHeader_Background.jpg");
width: 960px;
height: 50px;
}
div.content {
position: relative;
}
div.footer {
margin-bottom: 25px;
}
HTML:
<div class="header">
<div class="max-width">
<ul class="navigation float-right">
<li>Home</li>
<li>Sobre</li>
<li>Fale conosco</li>
</ul>
</div>
</div>
<div class="max-width">
<div class="post-header">
<ul class="options float-left">
<li><span>Ofertas</span></li>
<li><span>Lista de compras (0)</span></li>
</ul>
<div class="search-bar float-right">
<form>
<input class="float-left" type="text" placeholder="Por qual produto você procura? Digite aqui" />
<button class="magnifier"></button>
</form>
</div>
</div>
</div>
<div class="content">
#RenderBody()
</div>
<div class="max-width">
<div class="footer">
<div class="tbside-margin">
<hr />
<ul class="bottom-navigation">
<li>Home</li>
<li>Sobre</li>
<li>Fale conosco</li>
</ul>
</div>
</div>
</div>
This is occurring because you've taken div out of the "normal flow." You've likely floated other elements, effectively taking them out of the main flow. Now that you want to position the div with margins it's not relative to the elements that have been taken out of the normal flow. That's why adding the float works, it places it into a new flow.
"A floated box is positioned within the normal flow, then taken out of
the flow and shifted to the left or right as far as possible. Content
may flow along the side of a float. [...] When a box is taken out of
normal flow, all content that is still within normal flow will ignore
it completely and not make space for it."
http://coding.smashingmagazine.com/2007/05/01/css-float-theory-things-you-should-know/
That's gonna depend a lot on your layout. Showing some html or URL would help. But, as Christian said, setting up the position would help. You might also try with position:relative; or also, instead of margin, try padding-bottom:25px;
I've solved!
At my footer's navigation, I have the follow markup:
<ul class="bottom-navigation">
<li>Home</li>
<li>Sobre</li>
<li>Fale conosco</li>
</ul>
And my CSS:
div.footer ul.bottom-navigation li {
float: left;
}
The question is: I can't float my menu items to the left. Why? I don't know, but I did this to resolve:
div.footer ul.bottom-navigation li {
display: inline;
}
It works — but I don't know why. The explanation will be very welcome.
Thanks!
You need to clear the float on the floated item's parent element.
Some left floated text
Some more left floated text
ul li span {
float: left;
}
.clearfix {
*zoom: 1;
}
.clearfix:before, .clearfix:after {
content: " ";
display: table;
}
.clearfix:after {
clear: both;
}
<div class="pull_down">
<ul class="zvuc">
<li class="prod">
<div class="conutine">
<div class="prod_name">Asus 15.6-Inch Versati...</div>
<img src="../images/test/lotr.jpg">
<div class="timer"></div>
</div>
</li>
</ul>
</div>
CSS:
div.pull_down
{
padding: 20px 20px 20px 30px;
}
li.prod
{
background: url("../images/test/bg-horizontal.png") no-repeat;
height: 286px;
width: 170px;
text-align: center;
padding-top: 0;
display: list-item;
width: 170px;
min-height: 286px;
float: left;
}
ul
{
list-style: none outside none;
margin: 0;
padding: 0;
text-align: left;
}
When i mouse over the division with firebug, it doesn't contain anything. Why is this?
Your are floating your LI's so you most likely need a "clearfix" on the parent DIV.
A "clearfix" will force an element to self-clear it's children.
http://css-tricks.com/snippets/css/clear-fix/
Demo: http://jsfiddle.net/wdm954/Dxkpx/
You can just add the .group classes to your CSS file and add class="group" to any parent that you need to clearfix.
This is a semantic and scale-able solution. You should avoid adding empty DIVs to your markup or extra CSS to parents (such as floats). That can produce undesirable results and become confusing in the long run.
Hi you need to add <div style="clear:both"></div> after the </ul> to close the float
or to add float: left; to the class .div.pull_down