DIVs inside another DIV inside another DIV with CSS - css

Here's what I'm trying to achieve:
This is the HTML code I wrote:
<div id="wrapper"> <!--This is the Div 1 in the picture-->
<div id="topBar"> <!--This is the Div 2 in the picture-->
<div id="logo"></div> <!--This is the Div 4 in the picture-->
<div id="menu"></div> <!--This is the Div 5 in the picture-->
<div id="login"><!--This is the Div 6 in the picture-->
<div class="loginElement"><input type="text" id="txtUsername" class="loginElementBox" size="29" value="User name" onClick="usernameFocus()" onBlur="usernameBlur()" /></div>
<div class="loginElement">
<input type="text" name="txtFakePassword" id="txtFakePassword" class="loginElementBox" value="Password" onfocus="passwordFocus()" /><input style="display:none;" type="password" id="txtPassword" class="loginElementBoxFocus" onBlur="passwordBlur()" />
</div>
<input type="button" id="btnLogin" value="" onclick="login()"><br />
<span id="lblError"></span>
</div><!--Closing "login"-->
</div><!--Closing "topBar"-->
<div id="central"> <!--This is the Div 3 in the picture-->
<div id="top3"> <!--This is the Div 7 in the picture-->
</div>
</div><!--Closing "central"-->
</div><!--Closing "wrapper"-->
and this is the CSS:
#wrapper
{
width:800px;
background-color:#f2f2e8;
position:relative;
left:50%;
margin-left:-400px;
border-radius: 10px;
-moz-border-radius: 10px;
padding:5px;
}
#topBar
{
width:780px;
border: 1px solid;
border-color: #dbd9ca;
border-radius: 10px;
-moz-border-radius: 10px;
margin:5px;
padding:5px;
}
#logo
{
width:153px;
height:66px;
background-image:url(../images_ui/logo2.png);
background-repeat:no-repeat;
background-position:left center;
margin:5px;
padding:5px;
float:left;
}
#menu
{
float:left;
width:400px;
position:relative;
}
#login
{
float:right;
width:80px;
}
#central
{
width:780px;
border: 1px solid;
border-color: #dbd9ca;
border-radius: 10px;
-moz-border-radius: 10px;
margin:5px;
margin-top:20px;
padding:5px;
}
Inside Div 6 I have a few more Divs
It all just comes out scrambled. Div 2 and Div 3 look OK inside Div 1, and Div 7 looks nice inside Div 3, but once I add Divs 3, 4, 5... I tried several things, with float, position etc - nothing worked, I can't arrange it as I want it. Any ideas how to make it work?

#Div1
{
width:800px;
margin:0 auto;
overflow:hidden;
float:left;
}
#Div2
{
width:100%;
float:left;
}
#Div3
{
width:100%;
clear:both;
}
#Div4, #Div6
{
float:left;
width:30%;
}
#Div5
{
float:left;
width:40%;
}
#Div7
{
width:70%;
margin:50px auto;
}
If I haven't forgotten something that should be round about it

Related

Full width block near floated one

I have two rows like this
<div class="container me">
<div class="message">
</div>
<div class="time">
</div>
</div>
<br />
<div class="container he">
<div class="message">
</div>
<div class="time">
</div>
</div>
with css like this
* {
padding:0;
margin:0;
}
.container {
width:500px;
height:50px;
outline:1px solid green;
}
.message {
width:250px;
height:50px;
border:1px solid red;
display:inline-block;
border-radius:5px;
position: relative;
}
.time {
width:50px;
height:50px;
background:orange;
}
.container.me .time {
float:right;
}
.container.he .time {
float:left;
}
and i am trying to make message block full possible width (100% minus time block), is it possible?
jsfiddle https://jsfiddle.net/Nerfair/t0t0q632/5/
You can set width for .message to width: calc(100% - 52px); - this 52px is a width of your .time div (50px) + 2px for borders of .message (left and right)
Edit: For IE8 support you cannot use that, so you can try the tricky thing like this: https://jsfiddle.net/L2pqhnsq/

Div not aligning properly

I have the following alignment problem: I want the "random" div to have a full width in the window, that's why I added the "width:100%" command. But for some reason, the maximum width it displays the random div on is the width of the "fixedwidth" div, but the two are not connected. Why does the browser keep matching the maximum width of the two divs? If i increase the width of the "fixedwitdth" div, then the width of the "random div" also increases. But that does not make any sense.
<html>
<head>
<title>Gliga's BBC</title>
<style type="text/css">
body {
margin:0px;
font-family: arial,helvetica;
}
#topbar {
background-color:#7A0000;
width:100%;
height:40px;
color:white;
}
.fixedwidth {
width:1200px;
background-color:green;
margin:0 auto;
}
#logodiv {
padding-top:7px;
padding-bottom:3px;
padding-left:50px;
float:left;
border-right: 2px solid #990000;
padding-right:30px;
}
#signindiv {
font-weight:bold;
padding:9px 80px 11px 20px;
font-size:0.9 em;
float:left;
border-right: 2px solid #990000;
}
#topmenudiv {
float:left;
}
#topmenudiv ul {
margin:0;
padding:0;
}
#topmenudiv li {
list-style:none;
font-weight:bold;
font-size:0.9 em;
border-right: 2px solid #990000;
height:100%;
padding:10px 20px 10px 20px;
float:left;
}
#searchdiv {
float:left;
padding:6px 10px 5px; 5px;
border-right: 2px solid #990000;
}
#searchdiv input{
height:20px;
}
.break {
clear: both;
}
.random {
background-color:blue;
margin-top:10px;
height:30px;
width:100%;
}
</style>
</head>
<body>
<div id="container">
<div id="topbar">
<div class="fixedwidth">
<div id="logodiv">
<img src="images/bbclogo.png"/>
</div>
<div id="signindiv">
Sign in
</div>
<div id="topmenudiv">
<ul>
<li>News</li>
<li>Sport</li>
<li>Weather</li>
<li>iPLayer</li>
<li>TV</li>
<li>Radio</li>
<li>More...</li>
</li>
</ul>
</div>
<div id="searchdiv">
<input type="text" placeholder="Search..." />
<div>
</div>
</div>
<div class="break" />
<div class="random">
</div>
</div>
</body>
</html>
.random is a child of .fixedwidth, so it's a totally normal behaviour happening there.
If you sort your code properly then you will get to see it clearly:

Fill out remaining height of dynamic div

How can I get the bottom box of the lefthand side to fill out the rest of the height of the div so the border goes down to the bottom of the box?
Right now the line stops where the content of the left box stops
HTML
<div id="container">
<div id="leftcolumn">
<div id="fixedbox">
Fixed size
</div>
<div id="restbox"><p>Fill out box</P></div>
</div>
<div id="rightcolumn">
<p>Dynamic content</p>
</div>
<br style="clear:both;" />
</div>
CSS
body {
background-color:#ccc;
}
#container {
margin:0 auto;
width:80%;
background-color: #fff;
}
#leftcolumn {
width:29%;
float:left;
border-right:1px solid #000;
}
#rightcolumn {
width:68%;
float:left;
margin-left: 2%
}
#fixedbox {
width:100%;
height:200px;
border-bottom: 1px solid #000;
}
#restbox {
width:100%;
}
http://jsfiddle.net/P6YQc/2/
Is there any reason why you don't have a left border on #rightcolumn instead of a right border on #leftcolumn ?
http://jsfiddle.net/P6YQc/7/
eg:
#leftcolumn {
width:29%;
float:left;
}
#rightcolumn {
width:68%;
float:left;
border-left:1px solid #000;
padding-left:10px;
box-sizing: border-box;
}

display image a text inline with each other

i have this CSS:
<style type="text/css">
#box {
width:100%;
height:80px;
background-color:#eeeeee;
}
.box-inner {
width:80%;
margin:0 auto 0 auto;
text-align:center;
}
#text, #text a {
font-size:16px;
color:#F36F25;
margin:10px;
}
#text:hover, #text a:hover {
color:#666666;
text-decoration:none;
}
#text img {
vertical-align: middle;
margin-right:20px;
}
</style>
its currently displaying the image and text inline but i have multiple images/text below each other. how can i make all the images align in the same position below each other?
here is a fiddle: http://jsfiddle.net/8dsTu/
http://jsfiddle.net/8dsTu/4/
<div id="text">
<img src="../images/icons/address.png" height="60" />
<div style="display:inline-block;">
Address 1,<br />
Address 2,<br />
County Post Code
</div>
</div>
Edit css:
.box-inner {
width:80%;
margin:0 auto 0 auto;
text-align:left;
margin-left:100px;
}
Your HTML is invalid, id property is meant to be unique and you have a few <div> elements with id="text". To get what you want you'll have to: (jsFiddle)
replace all id="text" with class="text" and add <div class="caption"> to wrap each of the captions:
<div id="box">
<div class="box-inner">
<div class="text">
<img src="../images/icons/telephone.png" height="60" />
<div class="caption">00000 00 00 00</div>
</div>
<div class="text">
<img src="../images/icons/email.png" height="60" />
<div class="caption">sales#domain.co.uk</div>
</div>
<div class="text">
<img src="../images/icons/address.png" height="60" />
<div class="caption">Address 1,<br />Address 2,<br />County Post Code</div>
</div>
</div>
</div>
Adjust the css:
#box {
width:100%;
height:80px;
background-color:#eeeeee;
}
.box-inner {
width:80%;
margin:0 auto 0 auto;
text-align:center;
}
.text, .text a {
font-size:16px;
color:#F36F25;
margin:10px;
}
.text:hover, .text a:hover {
color:#666666;
text-decoration:none;
}
.text img {
vertical-align: middle;
margin-right:20px;
}
.caption{ /* This is the new bit - display:inline-block does the trick. adjust margin-top to your needs */
display:inline-block;
vertical-align:top;
margin-top:15px;
}
#box {
width:100%;
background-color:#eeeeee;
}
.box-inner {
width:80%;
margin:0 auto 0 auto;
text-align:center;
}
.text, .text a {
font-size:16px;
color:#F36F25;
}
.text:hover, .text a:hover {
color:#666666;
text-decoration:none;
}
.text img {
vertical-align: middle;
margin-right:20px;
width: 60px;
background: black;
float: left;
}
.text {
overflow: hidden;
width: 250px;
margin: 10px auto;
}
Something like this? But you must replace your id's with classes.

css two div floated left . Right div not covering the remaining space

I've two divs leftSide and rightSide whose parent is innerContainer. I've floated both the divs to left.They are appearing side by side but the right div is not covering the remaining space of the parent div.
I tried using overflow:hidden and also specified the width but still it is of the same width.
My Css:
#container {
overflow:auto;
margin:10px auto;
}
#innerContainer{
margin:10px auto;
width:1200px;
background:#FFFFFF;
border:2px solid #09F;
overflow:auto;
}
#leftSide{
overflow:auto;
float:left;
width:700px;
border:3px solid #F00;
}
#topheaderProfile{
margin:5px;
border:1px solid #F00;
}
#middleCompanyDescription{
margin:5px;
border:1px solid #333;
}
#Profile{
text-align:left;
}
.ProfileBox{
padding:10px;
cursor:pointer;
overflow:hidden;
text-align:left;
word-break:break-all;
word-wrap:break-word;
}
.CompanyLogo{
float:left;
padding:5px;
}
.rightCover{
overflow:auto;
padding:1px;
}
.companyTitle{
color:#36F;
font-size:24px;
overflow:hidden;
}
.companyTitle a{
text-decoration:none;
}
.CompanyRating{
float:left;
margin-top:3px;
}
.Companylikedicon{
overflow:hidden;
float:right;
margin-left:10px;
}
.Companycommenticon{
float:right;
margin-right:10px;
}
.CompanySlogan{
color:#999;
word-break:break-all;
word-wrap:break-word;
clear:both;
}
#rightSide{
width:100px;
border:1px solid #000;
}
My Html:
<div id="container">
<div id="innerContainer">
<div id="leftSide">
<div id="topheaderProfile">
<div id='Profile'>
<div class='ProfileBox'>
<div class='CompanyLogo'><img src='../Images/defaultPic.jpg' width='90' height='90'/></div>
<div class='rightCover'>
<div class='companyTitle'>My Company</div>
<div class='CompanyRating'>
Rating : <img src='../Images/FilledStar.png' width='20' height='20' id='Star1' />
<img src='../Images/EmptyStar.png' width='20' height='20' id='Star2' />
<img src='../Images/EmptyStar.png' width='20' height='20' id='Star3' />
<img src='../Images/EmptyStar.png' width='20' height='20' id='Star4' />
<img src='../Images/EmptyStar.png' width='20' height='20' id='Star5' />
</div>
<div class='Companylikedicon'><img src='../Images/LikedIcon.png' width='25' height='25' /> 100</div>
<div class='Companycommenticon' ><img src='../Images/comment.png' width='25' height='25' /> 100</div>
<div class='CompanySlogan'>This is the best offer you get 2Rs. off in the besaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaat underwear of the worldffer you get 2Rs. off in the besaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaat underwear of the world.</div>
</div>
</div> <!--ProfileBox-->
</div>
</div><!--TopHeeaderProfile-->
<div id="middleCompanyDescription">
sadasdsad
</div>
</div> <!--LeftSide-->
<div id="rightSide">
sadasdasdasd
</div>
</div>
</div>
Ok I've found the problem.There is another css file containing id names same as in this file.This is causing the problem.The properties of that file are being applied here.
Thanks everyone for your help.
I tried using overflow:hidden and also specified the width but still it is of the same width.
Use overflow: hidden but don't specify any width if you want #rightSide to fill the remaining space.
See: http://jsfiddle.net/thirtydot/Yuxzs/
#rightSide {
overflow: hidden;
border: 1px solid #000;
}​
Try this:
<style type="text/css">
#rightSide {
width:100px;
border:1px solid #000;
float:left;
}
</style>

Resources