Can't make DIV float inside parent div - html

I've got 2 DIV elements (the ones labeled "Module" below that are not acting right! when i try to float them, so that they show up side by side, they jump outside of the parent container and fall below it. i've not been able to figure this out, can someone help?
jsfiddle: jsfiddle
HTML
<div id="contentwrap">
<div id="content">
<div>
<span style="text-align:center;">
<h2>Application Title</h2>
</span>
</div>
<br/>
<br/>
<div class="module">
<a class="modlink" href=" ../csc/index.php">
<img class="modimg" src="./images/csc.png" alt="csc"/>
<br/>Client Support Center
</a>
<br/>
</div>
<div class="module">
<a class="modlink" href=" ../icm/index.php">
<img class="modimg" src="./images/icm.png" alt="icm"/>
<br/>Inventory Control Management
</a>
<br/>
</div>
</div>
</div>
CSS
body {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 13px;
color:#E1E6FA;
background-color:#183152;
}
p {
padding: 10px;
}
h1 {
font-size: 2em;
}
h2 {
font-size: 1.5em;
}
h3 {
margin-bttom:2px;
}
#wrapper {
margin: 0 auto;
width: 1000px;
}
#headerwrap {
width: 1000px;
float: left;
margin: 0 auto;
}
#header {
height: 100px;
background: #375D81;
border-radius: 10px;
border: 1px solid #C4D7ED;
margin: 5px;
}
#contentwrap {
width: 820px;
float: left;
margin: 0 auto;
}
#content {
background: #ABC8E2;
border-radius: 10px;
border: 1px solid #C4D7ED;
margin: 5px;
color:black;
}
#companylabel {
margin: 10px;
top:50%;
position:absolute;
margin-top:-.5em;
}
#loginbox
{
width:100%;
}
#loginboxbot
{
width:100%;
}
.ra
{
text-align:right;
}
#borderresults {
color:orangered;
font-weight:bold;
padding:0px;
margin:0px;
border-radius:10px;
}
#alert {
background-color:yellow;
}
.module {
text-align:center;
width:120px;
padding:5px;
border-radius:5px;
border: 1px solid #E1E6FA;
color:#E1E6FA;
background-color:#375D81;
float:left;
}
.modimg {
height:100px;
width:100px;
}
.modlink {
color:#E1E6FA;
text-decoration:none;
}

It's super easy all you have to do is on content div add overflow:auto
I did it for you here and it works.
http://jsfiddle.net/alaingoldman/FAPCW/5/
#content {
...
overflow:auto;
}
enjoy and +1 me :)

Not the most elegant fix, but I added a <br style="clear:both"> below the second .module in you container and that seems to do the trick, though a violation of semantic markup.
http://jsfiddle.net/FAPCW/1/
This is a common issue and is generally fixed with a "clearfix".
Lots of versions exist. Here's one with some more details on the general issue: http://perishablepress.com/lessons-learned-concerning-the-clearfix-css-hack/
Here's even more info: https://stackoverflow.com/a/10184992/363701
heres one I use:
.cf:before, .cf:after { content: " "; display: table; }
.cf:after { clear: both; }
.cf { *zoom: 1; }
you would just put the cf class on your container, and floated children will be properly cleared.

Typical newbie stuff!
Use a div with clear both style at the end of the 'float' divs.
<div class="module">
<a class="modlink" href=" ../csc/index.php">
<img class="modimg" src="./images/csc.png" alt="csc"/>
<br/>Client Support Center
</a>
<br/>
</div>
<div class="module">
<a class="modlink" href=" ../icm/index.php">
<img class="modimg" src="./images/icm.png" alt="icm"/>
<br/>Inventory Control Management
</a>
<br/>
</div>
*<div style="clear:both"></div>*
</div>
</div>

Related

Clearfix is not working showing profile at right

I have a simple web page there I am using clearfix fix as below
.clearfix:after{
content: "";
display: :table;
clear:both;
}
I have create code https://jsfiddle.net/xrcwrn/7b26pwsd/1/
I want to show profile below but it is showing at right
You can try to wrap all of the items which have float property with a div.clearfix. Like this:
*{
margin:0;
padding:0;
box-sizing: border-box;
}
body{
font-family: halvitica ,Arial;
font-size: 18px;
}
.container{
width:1140px;
margin-left: auto;
margin-right: auto;
margin-top:20px;
}
h1,h2{
color:green;
}
h1{
font-size: 40px;
}
h2{
font-size: 35px;
}
p{
text-align: justify
}
.blog-post{
width: 75%;
float: left;
padding-right: 30px;
}
.other-post{
width: 25%;
float:left;
}
.author-box{
padding-top: 20px;
border-top: 1px solid green;
}
.author-box img{
height: 100px;
width: 100px;
border-radius: 50%;
}
.clearfix:after{
content: "";
display: :table;
clear:both;
}
.other {
margin-bottom: 40px;
}
.author-text {
float: left;
margin-left: 25px;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" />
<div class="container">
<div class="clearfix">
<div class="blog-post">
<h2>He share of first to worse</h2>
<p>
Conveying or northward offending admitting perfectly my. Colonel gravity get thought fat smiling add but. Wonder twenty hunted and put income set desire expect. Am cottage calling my is mistake cousins talking up. Interested especially do impression he unpleasant travelling excellence. All few our knew time done draw ask.
</p>
</div>
<div class="other-post">
<div class="other">Post 1</div>
<div class="other">Post 2</div>
<div class="other">Post 3</div>
</div>
</div>
<div class="author-box">
<image src="https://randomuser.me/api/portraits/men/68.jpg" alt="author"/>
<p class="author-text">Neeta Rai</p>
</div>
</div>

Why isn't the text inside the div?

I just began to play around with HTML/CSS and I'm already stuck.
I tried to google my problem but I think I'm missing some keywords to find a solution. Why isn't the Link and Text inside <div id="NavContent>?
DEMO
body {
margin:0;
background-color: #ffffff;
}
nav {
background-color: #2a9dfc;
padding-left: 20px;
padding-right: 20px;
padding-top: 13px;
padding-bottom: 13px;
}
#NavContent {
border: 2px solid black;
max-width: 900px;
width: 100%;
margin: 0 auto;
}
#Link {
float:left;
}
#Text {
float:right;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>scrare</title>
<link rel="stylesheet" href="stylesheet.css">
</head>
<body>
<nav>
<div id="NavContent">
<a id="Link" href="/">Link</a>
<div id="Text">Text</div>
</div>
</nav>
</body>
</html>
Once you set elements inside a div as float, they lost their influence on height attribute on parent element.
That said, you can:
Set a height for the div; or
Add a empty <div> after <div id="text"> but not inside, with style='clear: both;'
Easy fix is to add overflow: hidden; to #NavContent.
Or you can add the clearfix solution -
#NavContent:after {
content: "";
display: block;
clear: both;
}
body {
margin:0;
background-color: #ffffff;
}
nav {
background-color: #2a9dfc;
padding-left: 20px;
padding-right: 20px;
padding-top: 13px;
padding-bottom: 13px;
}
#NavContent {
border: 2px solid black;
max-width: 900px;
width: 100%;
margin: 0 auto;
}
#Link {
float:left;
}
#Text {
float:right;
}
#NavContent:after {
content: "";
display: block;
clear: both;
}
<nav>
<div id="NavContent">
<a id="Link" href="/">Link
</a>
<div id="Text">
Text
</div>
</div>
</nav>
<main>
</main>
<footer>
</footer>
There are few ways to solve your problem.
Add a suitable height to #NavContent element (like height:200px)
Or
set overflow property of #NavContent to auto

Image over flow fix?

I have two columns; first column goes for image and the second holds detail.
My problem is the image over flows to the next line
Adding overflow:auto; or inline-block; to div.portfolioitems_wrap didn't help me
list http://img577.imageshack.us/img577/7002/screenshot20121204at135.png
Maker
<div class="portfolioitems_wrap">
<div class="portfolioitems_column1">first image</div>
</div>
<div class="portfolioitems_column2">information of the institute</div>
<div class="portfolioitems_wrap">
<div class="portfolioitems_column1">first image</div>
</div>
<div class="portfolioitems_column2">information of the institute</div>
<div class="portfolioitems_wrap">
<div class="portfolioitems_column1"><img src="/image/nature.jpg" class="thumbnail" alt="nature" />
</div>
</div>
<div class="portfolioitems_column2">information of the institute
</div>
<div class="portfolioitems_wrap">
<div class="portfolioitems_column1">first image</div>
</div>
<div class="portfolioitems_column2">information of the institute</div>
<div class="clear"></div>
CSS
div.portfolioitems_wrap{
float: left;
width:100%;
color:#555555;
border-bottom: 1px solid #eee;
height: 1.5em;
margin-bottom: 1em;
}
div.portfolioitems_column1{
margin-right: 10px;
}
div.portfolioitems_column2{
float: left;
color:#555555;
width: 300px;
margin-left: -300px;
font-size: 80%;
}
div.portfolioitems_column1 .thumbnail
{
float:left;
margin-right:20px;
border:1px solid #979390;
width:80px;
margin-bottom: 5px;
}
div.clear{
clear: both;
}
Further to my comment above: http://jsfiddle.net/hp7dY/
Just the min-height seems to be enough to fix this
It looks like your DIV organization is a little confused, which is adding to your problem. I'm assuming that the portfolioitems_wrap DIV is supposed to enclose both columns. That said, the problem is more that you're fixing the height of each table row, instead of allowing it to be flexible based on the content.
Removing the height:1.5em; entry from allows your elements to fit in the DIV. You might also consider displaying the column elements as inline-block.
div.portfolioitems_wrap{
float: left;
width:100%;
color:#555555;
border-bottom: 1px solid #eee;
// height: 1.5em;
margin-bottom: 1em;
}
div.portfolioitems_column1{
margin-right: 10px;
display:inline-block;
width:100px;
float:left;
}
div.portfolioitems_column2{
color:#555555;
font-size: 80%;
display:inline-block;
width:300px;
float:left;
}
div.portfolioitems_column1 .thumbnail {
float:left;
border:1px solid #979390;
width:80px;
margin: 0px 10px 5px 10px;
}
div.clear{
clear: both;
}
Here's a working fiddle with some other minor adjustments to make it pretty:
http://jsfiddle.net/72HML/
Hope that helps.

HTML/CSS float left issue

I have been recently designing some content which needs to be side by side and have the height automatically resize, but the height doesn't resize. The div doesn't expand to the size of the items inside of it. Is there a way to allow the div to expand to the size of the elements inside of it?
CSS
* {
padding: 0px;
margin: 0px;
}
body {
font-family: 'Metrophobic', sans-serif;
background-color: #c5c5c5;
background-image: url('../images/noise.png');
}
#container {
width:900px;
background-color: #dbdbdb;
margin-top: 20px;
margin-left: auto;
margin-right: auto;
margin-bottom: 20px;
box-shadow: 0px 0px 5px black;
}
.center_align {
display: inline-block;
margin-left: auto;
margin-right: auto;
}
#header {
height:80px;
font-size: 60px;
padding: 10px;
text-align: center;
}
#menu {
width:900px;
height:50px;
margin-top: 10px;
margin-bottom: 10px;
background-color: #cacaca;
}
.menu_link {
width:224px;
height:50px;
text-align: center;
font-size: 35px;
float: left;
opacity: 0.3;
background-color: #cacaca;
}
.menu_divider {
width: 1px;
height: 50px;
background-color: #dbdbdb;
float:left;
}
#content {
width: 900px;
height: auto;
padding: 10px;
font-size: 20px;
height: auto;
}
.line_container {
margin-top:5px;
margin-bottom:5px;
}
#footer {
width:900px;
height:22px;
padding-top:2px;
text-align: center;
font-size: 14px;
color:black;
}
a:link {
color:black;
text-decoration: none;
}
a:visited {
color:black;
text-decoration: none;
}
a:hover {
color:black;
text-decoration: none;
}
a:active {
color:black;
text-decoration: none;
}
a.link:link {
color:#21525e;
}
a.link:visited {
color:#21525e;
}
a.link:hover {
color:#307f91;
text-decoration: underline;
}
a.link:active {
color:#307f91;
text-decoration: underline;
}
HTML
<html>
<head>
<title>Home</title>
<link rel="shortcut icon" href="../images/favicon.ico" />
<link href="http://fonts.googleapis.com/css?family=Metrophobic" rel="stylesheet" type="text/css" />
<link href="../css/style.css" rel="stylesheet" type="text/css" />
<style type="text/css">
.icon {
width:100px;
height:100px;
border: 3px solid white;
border-radius:25px;
margin-left:10px;
margin-right:10px;
background-position: center center;
background-size: 100px 100px;
}
</style>
</head>
<body>
<div id="container">
<div id="header">
<div class="center_align">
<img src="../images/header_icon.png" alt="header_icon" width="80" height="80" style="margin-right:20px;float:left;" />
<div style="height:80px;float:left;">Title</div>
</div>
</div>
<div id="menu">
Home
<div class="menu_divider"></div>
Tutorials
<div class="menu_divider"></div>
About
<div class="menu_divider"></div>
Contact
</div>
<div id="content">
<div style="width:900px;">
<div class="icon" style="background-image:url('image.jpg');float:left;"></div><div style="float:left;margin-top:20px;">I'm a freelance Web, Iphone, and Game developer.</div>
</div>
</div>
<div id="footer">
© Cameron
</div>
</div>
</body>
</html>
Looks like the problem is that the #footer element isn't properly cleared. Add clear: both; to #footer. This pushes the cleared element below the floated elements, and should functionally result in the same visual fix.
The "container div" basically "forgets" that it is the container for them, so simply add an overflow:auto; to make it remember.
I also tend to add zoom:1 for IE.
The problem is that you are floating elements, and that causes problems with wrapping divs per default (pretty much...).
Here is a working solution, where overflow:hidden is added to the wrapping div: http://jsfiddle.net/s2dxw/2/
The float issue is pretty confusing, and has had a couple of solutions in the past. Here's a good read regarding floats in HTML: http://css-tricks.com/all-about-floats/
Alternatively, you can put some element with the rule clear: both; inside and at the end of the wrapping div.

Expand an <a> tag to fill the space

How can I make the anchor tag expand to the bottom of the list item?
I know I could put the anchor round the list item tag, but that breaks XHTML 1.0 Strict compliance, so I cannot do it.
<html>
<head>
<style>
#listWrapper { text-align:center;}
#list { margin-left: 0px auto; margin-right: 0px auto; width: 100%; min-height: 100%; height:100%; margin-bottom: 10px; margin-top: 0px;}
#list ul { padding: 5px 10px 10px 10px; margin: 0; min-height: 100%;}
#list li { clear:both; font-weight:bolder; height:auto; border-bottom: 1px solid Silver; border-left: 1px solid Silver; font-size:x-small; border-right: 1px solid Silver; list-style-type: none;}
#list a:hover { background-color: red;}
#list a { display:block; cursor:pointer; text-decoration: none; text-align:left; vertical-align:top; }
#list h3 { background-color:Silver; vertical-align:top; font-size:larger; }
#list img { height:auto; margin: 8px; float:left; vertical-align:top; border:solid 1px Silver;}
</style>
</head>
<body>
<div id="listWrapper">
<div id="list">
<ul>
<li>
<h3>title</h3>
<a href="#">
<img src="/images/x.jpg" alt="" />
Lorem ipsun........
</a>
<div style="clear:both;" />
</li>
<li>
<h3>title</h3>
<a href="#">
<img src="/images/x.jpg" alt="" />
Lorem ipsun........
</a>
<div style="clear:both;" />
</li>
</ul>
</div>
</div>
</body>
</html>
A combination of your answers fixed it. Many thank....
#list ul { display: block; }
#list li { display: block;}
#list a { display:block; height:100%; }
use this css:
#list ul li a { display: block }
Put the
<br style="clear: both;"/>
inside the Anchor tag.
EDIT: changed div to br
To fill the bottom, you need to fix the image margins - right now the image is taking up too much space with it's 8px margin. To fill the top, you need to remove the bottom margin of h3.
#list h3 { margin-bottom: 0; }
#list img { margin: 5px 8px; }
Try set height on the #list to a fixed size, and height on #list ato 100%.
Differences to your existing code:
#list
{
min-height: 100px;
height: 100px;
}
#list a
{
height:100%;
}
Here's what I did:
<!-- teh codes -->
<style type="text/css">
.nav-cell
{
height: 35px;
padding: 0px; /* just to make sure the link will fill the entire cell */
text-align: center;
width: 92px;
}
.nav-cell-link
{
display: block;
width: 100%;
height: 100%;
}
.nav-cell-link-text
{
display: block;
padding-top: 11px;
}
</style>
<!-- teh codes -->
<table cellpadding="0" cellspacing="0" style="height: 35px;">
<tr>
<td class="nav-cell">
<a href="#" class="nav-cell-link">
<span class="nav-cell-link-text">Link Text</span>
</a>
</td>
</tr>
</table>
<!-- teh codes -->