I am build a page,however I meet some layout related probelms,I can not make the div ajust its size(acutally the height) automatically. See the following markup:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<title>Link one</title>
<style type="text/css">
div#middle{
margin-top: 5px;
margin-bottom: 5px;
}
</style>
</head>
<body>
<div style="background-color: gray;border: solid 1px red" id="top">
<h1>Top<h1>
</div>
<div style="border: solid 1px blue;min-height: 200px" id="middle">
<div id="leftmenu" style="float: left;background-color:gray;width: 190px">
<ul>
<li><a href=''>Link One</a></li>
<li><a href=''>Link Two</a></li>
<ul>
</div>
<div id="content" style="background-color: black;margin-left: 200px">
I am in Link One
</div>
</div>
<div style="background-color: gray" id="foot">
<hr/>
<p>Copyright xxx</p>
</div>
</body>
</html>
Note the div whose id is "middle",I have to set its height manually,if not the div below it (div with id "foot")will not displayed below it. The foot div will go to the same line with "middle" div,just remove the "min-height: 200px" of "middle" div for a test.
And since the content is not sure,so I can not set its size manually,I just want to the height of the middle div to be the larger height of "leftmenu" or "content".
Any ideas?
-----------------------------------------
It does not expand ,
You are not clearing your floats. Add this line <div style="clear:both;"></div> below the the div with id=content
<div style="border: solid 1px blue;min-height: 200px" id="middle">
<div id="leftmenu" style="float: left;background-color:gray;width: 190px">
<ul>
<li><a href=''>Link One</a></li>
<li><a href=''>Link Two</a></li>
<ul>
</div>
<div id="content" style="background-color: black;margin-left: 200px">
I am in Link One
</div>
<div style="clear:both;"></div>
</div>
It does this because of the flow of the page. The flow is the order of the elements on your page. So in your example, your li elements are placed one after the other so the first one will appear before the second one on your page. The same applies to all elements, <a>, <div>, <p>, <img> and also text. When an element is floated it is taken out of the flow and elements that follow it are pushed up next to it; this way you can have text flowing around an image or links lined up next to each other.
Unfortunately when you float all elements within another element (as you have done with #leftmenu and #content) the parent element (#middle) acts as if it contains nothing because it has no child elements in the flow and acting as if it was essentially empty. By adding a clearing <div> we are creating a child element in the flow right below everything else and the parent element can then calculate the correct height.
I hope I explained that well enough.
The float:left is causing the issue. You need to insert a clearing element within middle.
eg
<div style="border: solid 1px blue;min-height: 200px" id="middle">
<div id="leftmenu" style="float: left;background-color:gray;width: 190px">
<ul>
<li><a href=''>Link One</a></li>
<li><a href=''>Link Two</a></li>
<ul>
</div>
<div id="content" style="background-color: black;margin-left: 200px">
I am in Link One
</div>
<div style="clear:both"></div>
</div>
JS Fiddle demo
Use a background-image to fake equal column height.
Check this article:
http://www.alistapart.com/articles/fauxcolumns/
For clearing use this class:
.clearfix:after {
content: ".";
display: block;
clear: both;
visibility: hidden;
line-height: 0;
height: 0;
}
like this
<div style="border: solid 1px blue;min-height: 200px" id="middle" class="clearfix">
Related
my left sidebar has no structure and I want it to be like a menu with a background color. I also have no idea how to make the changes in CSS so I can change the width and height...etc
here is the code for the sidebar
<div class="sidebar">
<nav>
<h1>Menu</h1>
<ul>
<li><strong>Home</strong></li>
<li><strong>Workshop </strong></li>
<li><strong>Team </strong></li>
<li><strong>Resources </strong></li>
<li><strong>Publication </strong></li>
<li><strong>Opportunities </strong></li>
</div><!-- /sidebar -->
CSS syntax can be called for in three ways.
Internal CSS: <style> tags, which must be underneath a <head> element that precede your <body>.
External CSS: Linking external CSS with just the CSS syntax, void of any HTML tags. You connect the two documents with a <link> tag using the href attribute
Block-level/Inline elements: CSS can be placed inside of block-level elements and inline elements (a list of which appear here)
Here is how to color your sidebar's background using the first method:
<head>
<style>
.sidebar {
background-color: gray;
}
</style>
</head>
And here's one way to add containers/boxes around your sidebar using the first method:
<head>
<style>
.box {
background-color: #eee;
margin-top: 5px;
padding: 10px;
text-align: center;
}
.sidebar {
display: block;
width: 150px;
font-family: Arial, sans-serif;
}
.row:after {
clear: both;
content: "";
display: table;
}
</style>
</head>
<body>
<div class="row">
<div class="sidebar">
<div class="box">
<strong>Home</strong>
</div>
<div class="box">
<strong>Workshop</strong>
</div>
<div class="box">
<strong>Team</strong>
</div>
<div class="box">
<strong>Resources </strong>
</div>
<div class="box">
<strong>Publication</strong>
</div>
<div class="box">
<strong>Opportunities</strong>
</div>
</div>
</div>
</body>
I'm not sure if this is exactly what you're looking for, but you can change the font, margins, and padding underneath the <style> tag however you want.
Also, I would suggest going through w3school's CSS introduction just to familiarize yourself with how it all works. Another tip: Make sure all of your starting tags have the necessary end tags! For example, in the code you wrote a closing </ul> and </nav> are missing.
I want to make li fill available width every line to make both side align.
sample
Here are my html and in-line CSS style.
Is there any CSS way to achieve this effect?
HTML:
<div class="row tag-cloud-wrap">
<div class="col-md-12 content-heading">
<a href="#">
<h3>
Find more Content by Keywords
</h3>
</a>
<div class="article-list" style="border: none">
<ul class="list-inline">
#foreach($videoData->keywords as $videokeyword)
<li style="background-color: #999;margin-right: -5px;margin-bottom:0;border-left: 1px solid white; border-bottom: 1px solid white; padding: 5px;">
<a style="padding: 5px;" href="#">
<strong>{{$videokeyword}}</strong>
</a>
</li>
#endforeach
</ul>
</div>
</div>
</div>
On div class article-list set width to whatever width you need the block to be.
Then on each li element add:
display: inline-flex;
You may have to play with it a little more to get exactly what you want, but this should get you started.
See: http://www.w3schools.com/css/css3_flexbox.asp for more information about Flex Boxes.
Right now I've got a webapp working, which I'm trying to add icons to, along with text to describe those icons. I'm trying to scale the icons down to fit in the div, which works great, but also to scale the image to hold text within the div. The issue I'm having is that although the image will scale to fit in the div, it won't scale enough to also allow text in the div.
My HTML code is
<div class="ui-grid-b" id="dashGrid">
<div class="ui-block-a changerbutton" style="height:60px;border-bottom: 1px solid;border-right: 1px solid;display:table-cell; vertical-align:middle">
<center>
<div>
<img src="http://upload.wikimedia.org/wikipedia/commons/8/85/Smiley.svg" class="windowscale-height">
</div>
<h4 class="gotobutton" goto="#formSelect" data-icon="grid">Forms</h4>
</center>
</div>
<div class="ui-block-b" style="height:22%"></div>
<div class="ui-block-c changerbutton" style="height:90px;border-bottom: 1px solid;border-left: 1px solid;display:table-cell; vertical-align:middle">
<center>
<div>
<img src="http://upload.wikimedia.org/wikipedia/commons/8/85/Smiley.svg" class="windowscale-height">
</div>
<h4 class="gotobutton" goto="#entries" data-icon="info">Entries</h4>
</center>
</div>
<div class="ui-block-a" style="height:22%"></div>
<div class="ui-block-b" style="height:22%"></div>
<div class="ui-block-c" style="height:22%"></div>
<div class="ui-block-a changerbutton" style="height:22%;border-top: 1px solid;border-right: 1px solid;display:table-cell; vertical-align:middle">
<center>
<h4 class="gotobutton" goto="#mapScreen" data-icon="star">Map</h4>
<div>
<img src="http://upload.wikimedia.org/wikipedia/commons/8/85/Smiley.svg" class="windowscale-height">
</div>
</center>
</div>
<div class="ui-block-b" style="height:22%"></div>
<div class="ui-block-c changerbutton" style="height:22%;border-top: 1px solid;border-left: 1px solid;display:table-cell; vertical-align:middle">
<center>
<h4 class="gotobutton" goto="#locSettings" data-icon="gear">Settings</h4>
<div>
<img src="http://upload.wikimedia.org/wikipedia/commons/8/85/Smiley.svg" class="windowscale-height">
</div>
</center>
</div>
</div>
, and the relevant CSS is
.windowscale-height
{
max-height: 100%;
max-width: 100%;
min-height: 1%;
min-height: 1%;
}
I've got a JSFiddle that shows the issue, http://jsfiddle.net/jDDmC/.
Ideally, the text, as well as the image, would both fit into the outlined boxes.
Any help would be appreciated!
A couple of things:
1) Remove the <center> tag since it's been deprecated. Use text-align: center in your css, instead.
2) Your divs have a specific height, and because of that, the text goes out of the box. So in the inline css, remove the height property.
3) Finally, consider using only an external stylesheet (instead of inline css), since it's easier to maintain and reuse.
Please take a look at:
http://jsfiddle.net/jDDmC/1/
Maybe you're looking for something like Fluid Images ?
I have a problem with this example: http://jsfiddle.net/JYkUS/
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>FSou1::Верстка макета</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<div class="logo-wrapper">
<div class="logo">
<a href="#">
<img src="images/logo.png" alt="Logo" width="90" height="90" />
</a>
</div>
<div class="logo-text">
<span>Happy Nanny</span>
</div>
<div class="menu">
<ul>
<li class="first">HOME</li>
<li>SERVICES</li>
<li>NEWS & PRESS</li>
<li>FIND JOB</li>
<li>CONTACTS</li>
</ul>
</div>
<div class="clear"></div>
</div>
<div class="header">
<div class="header-text">
<span class="easy-way">THE EASY WAY</span>
<span class="find-the-best">TO FIND THE BEST</span>
<div class="clear"></div>
<p>babysitters, childminders, nannies or private tutors</p>
</div>
</div>
</body>
</html>
Span with text
<span class="easy-way">THE EASY WAY</span>
as default has margin-left, but i don't know why. I really don't want to set a negative value to margin-left. Is it possible to align this span to left border and why does it now have margin with such value?
P.S. Watched in Google Chrome (firefox doesn't have this margin)
EDIT:
Just if i remove this style:
.logo-wrapper .logo, .logo-wrapper .logo-text {
float: left;
}
my span goes to left border =\ but why is it so?
EDIT2: Other way, to move <div class="clear"></div> from 'logo-wrapper' container, to root-level as
<div class="logo-wrapper">
<div class="logo"></div>
<div class="logo-text"></div>
<div class="menu"></div>
<!-- FROM HERE -->
</div>
<div class="clear"></div> <!-- MOVE HERE -->
<div class="header">
<div class="header-text">
<span class="easy-way">THE EASY WAY</span>
<span class="find-the-best">TO FIND THE BEST</span>
<div class="clear"></div>
<p>babysitters, childminders, nannies or private tutors</p>
</div>
</div>
But still can't understand, why floating still work after inner clear:both div
EDIT3: Is it because float:right menu even goes "righter", than div with clear:both?
The margin is actually applied on the body tag. You can remove it using:
body {
background: none repeat scroll 0 0 #F8F7E5;
font-family: Arial;
font-size: 100%;
margin-left: 0;
margin-top: 40px;
}
Working Example: http://jsfiddle.net/JYkUS/2/
This is commonly handled using a reset.css file which removes all browser specific styling from the page, so you can start from a single base point when creating a cross browser compliant webpage. I would recommend applying such a strategy to the site.
That is because you haven't set the body margin to 0
Make it margin:40px 0 0 0
body {
margin: 40px 0 0 0;
font-size: 100%;
font-family: Arial;
background: #f8f7e5;
}
DEMO
The following code blends both DIVs together instead of displaying them vertically, one after another. Both are set to display: block and I'd like to know which style attribute makes them behave like this?! See demo on jsfiddle.
<div data-role="page">
<div data-role="content">
<div>
Do something
<span href="#" style="float: right; border-radius: 10px; background-color: white; padding: .6em">Something</span>
</div>
<div>
<ul data-role="listview">
<li>Foo list entry</li>
</ul>
</div>
</div>
</div>
After using the floating elements you have to close them with element containing clear:both style, so the part of the code will be:
<div>
Do something
<span href="#" style="float: right; border-radius: 10px; background-color: white; padding: .6em">Something</span>
<div style="clear:both"></div>
</div>
Here is the working JSFiddle (with a little bit of margin modification as well): http://jsfiddle.net/Cw86p/9/