div alignment based on the content - html

I want to design the layout like below screenshot.
I tried to do this by using following code.
<div class="salesDiv">
<div>
Quarter To Date
</div>
<div>
830
</div>
<div>
<img src="~/Images/navigation-unit-actionplan.png" />
</div>
<div class="offtier">
<span>OFF TIER2</span>
</div>
<br />
</div>
<br />
<br />
<div class="salesDiv">
<div>
Rolling 3 Month
</div>
<div>
835
</div>
<div>
<img src="~/Images/navigation-unit-actionplan.png" />
</div>
<div class="offtier">
<span>National 852</span>
</div>
<br />
</div>
css :
.salesDiv {
width: 313px;
margin-left: 10px;
border: solid 1px gray;
border-radius: 4px;
height: 20px;
display: inline-block;
}
.salesDiv > div {
float:left;
margin-left:20px;
}
.offtier {
border-left-style: dotted;
background-color: green;
height: 20px;
width: 88px;
}
but it didn't give the same layout as like above screenshot. I want to do like above screenshot. What's going wrong? Please anyone look into this.
http://jsfiddle.net/zHLMS/
spacing also not good. I need equal spacing for all the content inside the border.
I need to maintain the same width for both the element.
Thanks,
Siva

You need to apply
display: inline-block;
float:right;
to the sales > divs and float: right to the offtier divs
Here's the modified code

Try this....Updated Link
.salesDiv {
width: 313px;
margin-left: 10px;
border: solid 1px gray;
-webkit-border-radius:5px;
border-radius:5px;
height: 20px;
display: inline-block;
position:relative;
}
.salesDiv > div {
float:left;
margin-left:20px;
}
.offtier {
-webkit-border-radius: 0 5px 5px 0;
border-radius: 0 5px 5px 0;
background-color: green;
height: 20px;
width: 88px;
right:0;
position:absolute;
}
Good Luck..Enjoy

Related

Managing and positioning CSS <divs>

I am trying to achieve this:
...as a format for news articles on my site (runic-paradise.com). You can see I've achieved everything except the orange bits. I'm trying to make the orange bits their own divs so I can put them in colored square backgrounds - to resemble something like this:
...however, I can't seem to get the divs to do what I want. It ends up messing up the 2 lower divs holding the image and text content. Anyone have any quick tips on how to achieve this? :(
JSFiddle of what I have so far:
http://jsfiddle.net/HDbq6/1/
HTML:
<div class="articleshell">
<div class="articletitle">
<h4 class="newstitleh4">A shining beacon in the desert - November 5, 2013</h4>
</div>
<div class="articleauthor">
Author
</div>
<div class="articleimg">
<img src="images/thumbs/EukitoDesertTempleThumb.jpg" width="90" height="90" class="news_thumb" alt="Eukito's Desert Temple" />
</div>
<div class="articletext">
<p>Eukito has completed construction of his desert temple. Of course no temple is complete without a secret passage or two... Stop on by at night to see it shining in the desert!</p>
</div>
</div>
CSS
.articleshell {
width: 770px;
max-height: none;
min-height: 130px;
padding-top: 5.px;
padding-right: 5.px;
padding-bottom: 5.px;
padding-left: 5.px;
padding-top: 1px;
padding-right: 5px;
padding-bottom: 5px;
padding-left: 5px;
background-color: #564D4D;
}
.articletext {
padding-right: 10px;
padding-bottom: 10px;
padding-left: 10px;
clear: both;
}
.articleimg {
float: left;
margin-right: 15px;
margin-bottom: 5px;
width: 90px;
height: 90px;
margin-left: 5px;
clear: both;
}
.articletitle {
margin-bottom: 5px;
margin-left: 5px;
margin-right: 5px;
margin-top: 3px;
float: left;
}
.newstitleh4 {
margin-bottom: 2px;
margin-top: 2px;
}
.articleauthor {
float: left;
text-align: right;
}
.articlecontent {
clear: both;
}
Something like this ?
fiddle
.main{width:500px; height:200px; border:1px solid #ccc; background:#f3f3f3; padding:5px;}
#title{width:45%; background:#ccc; border:1px solid #333; display: inline-block;}
.buttons{width:15%; background:orange; display: inline-block; border:1px solid #333;}
.mainContent{ width:100%; color:#ccc; border:1px solid #333; margin-top:5px; height:170px;}
<div class="main">
<div id="title">Title</div>
<div class="buttons">Author</div>
<div class="buttons">Role</div>
<div class="buttons">Date</div>
<div class="mainContent"></div>
</div>
The title id have a display:inline-block and div to get the thumb and the text content, that way the "buttons" don't mess up with the content. (I think)

How to vertical align my images with Texts

I have a question regarding a vertical align of my image and text
I have someone like
<div id='div1'>
<div id='div2'>
text here, more and more and more and more texts…….
<img src='test.png' class='img'/>
</div>
</div>
#div2{
border-color: black;
border-style: solid;
border-width: 0 1px 1px 1px;
padding: 10px;
font-size: .8em;
}
#div1{
width: 250px;
}
.img{
float:right;
vertical-align:middle;
}
I want my result like
text here, more and more and more
and more and more and more and more img here
texts
Can anyone help me about it? Thanks a lot!
The image will be in vertical middle no matter how many line of texts I have.
You have to vertical align the text as well as the image
<div id='div1'>
<div id='div2'>
<span>text here, more and more and more and more texts…….</span>
<img src='http://www.designboom.com/cms/images/user_submit/2012/10/asdfg_osi_skystack_d2n_01_m2nl.jpg' class='img' width="100px" height="auto"/>
</div>
</div>
#div2 > * {
vertical-align: middle;
}
Check this
html :
<div id='div1'>
<div id='div2'>
<p> text here, more and more and more and more texts…….</p>
</div><div class="right"><img src='test.png' class='img'/></div>
</div>
css
#div2{padding: 10px;
font-size: .8em;
float:left;
border: 2px solid #ccc;
vertical-align:middle;}
#div1{
width: 350px;
border: 2px solid #000;
height:100px;
}
.right{
float:right;
}
I hope help you.
try this code, check JsFiddle : http://jsfiddle.net/nAHwn/2/
<div id='div1'>
<div id='div2'>
<div id ="div3">text here, more and more and more and more texts……. text here, more and more and more and more texts…….text here, more and more and more and more texts……. text here, more and more and more and more texts……. text here, more and more and more and more texts…….</div>
<img src='http://www.designboom.com/cms/images/user_submit/2012/10/asdfg_osi_skystack_d2n_01_m2nl.jpg' class='img' width="100px" height="auto"/>
</div>
</div>
#div2{
border-color: black;
border-style: solid;
border-width: 0 1px 1px 1px;
padding: 10px;
font-size: .8em;
position:relative;
}
#div1{
width: 250px;
}
.img{
float:right;
vertical-align:middle;
position:absolute;
top:40%;
right:0px;
}
#div3 {width: 100px;
word-wrap:break-word;
}

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.

How do I get my tabs to line up properly using CSS?

This should be an easy one for someone. I am creating tabs with CSS (please, I don't need suggestions for how to make them look better, this is what my customer wants). As you can see in the image below, my tabs and my "tab bar" don't line up. I do not know why.
The HTML:
<html>
<head>
<link rel="stylesheet" href="prototype.css" type="text/css" />
</head>
<body>
<div id="container">
<div id="content">
<div id="tabs">
<span id="tab0" class="tab">
No Circuit
</span>
<span id="tab1" class="tab">
Digital Inputs
</span>
</div>
</div>
</div>
</body>
<html>
The CSS:
#container {
margin-left: auto;
margin-right: auto;
margin-top: 15px;
position: float;
width: 900px;
}
#content {
border: 1px solid black;
margin-top: 15px;
padding: 15px;
position: relative;
width: 868px;
}
#tabs {
border-top: 1px solid black;
width: 100%;
}
.tab {
border: 1px solid black;
margin-left: 5px;
margin-top: 2px;
padding: 3px;
}
I appreciate any help.
Try: http://jsfiddle.net/dYz9k/1/
.tab {
border: 1px solid black;
border-top: 0;
margin-left: 5px;
padding: 3px;
display: inline-block
}
I set display: inline-block, and removed the margin-top and border-top.
display: inline-block allows the padding to work as you're expecting.
Hm..not 100% certain if that'a what you're asking, but try setting padding:0 on .tab class
Have you considered using a list, better for Accessibility
Example here http://jsfiddle.net/hdhkn/
HTML
<html>
<head>
</head>
<body>
<div id="container">
<div id="content">
<ul id="tabs">
<li id="tab0" class="tab">
No Circuit
</li>
<li id="tab1" class="tab">
Digital Inputs
</li>
</ul>
</div>
</div>
</body>
<html>
CSS
#container {
margin-left: auto;
margin-right: auto;
margin-top: 15px;
position: float;
width: 900px;
}
#content {
border: 1px solid black;
margin-top: 15px;
padding: 15px;
position: relative;
width: 868px;
}
#tabs {
border-top: 1px solid black;
width: 100%;
list-style:none;
height:40px;
}
.tab {
border: 1px solid black;
border-top:none;
margin-left: 5px;
padding: 3px;
float:left;
display:block;
}
Is this what you want to accomplish? Or do you want your tabs(.tab) to be on top of #tabs?
I've added overflow: hidden to #tabs and changed the margin-left to margin-right.
You're putting padding on inline elements (the tabs), that always causes unexpected results.
Cleaned it up a bit for you.
<html>
<head>
<style type="text/css">
#container {
margin-left: auto;
margin-right: auto;
margin-top: 15px;
width: 900px;
}
#content {
border: 1px solid black;
margin-top: 15px;
padding: 15px;
width: 868px;
}
#tabs {
border-bottom: 1px solid black;
width: 100%;
}
.tab {
border: 1px solid black;
border-bottom:0px solid black;
margin-left: 5px;
margin-top: 2px;
padding: 3px;
float:left;
}
.clear {
display:block;
clear:both;
}
</style>
</head>
<body>
<div id="container">
<div id="content">
<div id="tabs">
<span id="tab0" class="tab">
No Circuit
</span>
<span id="tab1" class="tab">
Digital Inputs
</span>
<span class="clear"></span>
</div>
</div>
</div>
</body>
<html>

Sidebar and Container width CSS problem

I have a simple page for a chat system.
Test page can be found here: http://komasurfer.com/chat-test/
Here's the code:
<html>
<head>
<style type="text/css">
#page-wrap {
margin-top: 10px;
margin-bottom: 10px;
width: 100%;
/*for sidebar*/
margin-right: -110px;
background-color: #AAAAFF;
}
#chat-wrap {
border: 1px solid #eee;
margin: 0 5px 10px 0;
float: left;
/*margin for sidebar*/
margin-right:115px;
border: 1px solid red;
background-color: #600000; }
#chat-area {
width:100%;
height: 400px;
border: 1px solid #666;
float: left;
}
#sidebar {
border: 1px solid green;
float: right;
width: 110px;
padding: 0px 0px 0px 5px;
}
#entry {
background-color: #ffffff;
padding: 5px;
font-size: 1em;
clear: both;
border: 3px solid #999;
height: 40px;
width: 97%; }
#entry-btn {
padding: 18px;
float: right; }
.left {float: left; }
.right {float: right; }
.c {clear: both; }
</style>
</head>
<body>
<div id="page-wrap">
<div id="sidebar">
SIDEBAR
</div>
<div id="chat-wrap">
<div id="chat-area">
<div id="loading">connecting to server...</div>
</div>
</div>
<div class="c"></div>
<form id="send-message-area">
<div>
<table border="0" width="100%" cellpadding="0" cellspacing="0">
<tbody><tr><td align="left" width="98%" style="padding-right:5px;">
<textarea tabindex="1" maxlength="2000" id="entry"></textarea>
</td><td align="right">
<input id="entry-btn" type="button" value="Send">
</td></tr></tbody></table>
</div>
</form>
</div>
</body>
</html>
I've been trying for a very long time now to get the red box (with the contents of the chat) to expand to the sidebar.
If I add a width of 100% to that box, it always disregards the margin that I set for the sidebar and expands to the width of the container box.
How can I make the red chat area expand to the sidebar (minus a safety margin of 5 pixels)?
The layout is a floating one, so I cannot work with absolute measurements. And the sidebar should be 110 pixels.
Remove float:left from chat-wrap and increase the right margin like this:
#chat-wrap {
background-color: #600000;
border: 1px solid red;
margin: 0 136px 10px 0;
}