Full width block near floated one - css

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/

Related

Partitioned image in a table

I need to cut an image in Photoshop and to recompose it. I thought to create a table / div-table where put the pieces of the partitioned image.
I have done this:
<div id="Table">
<div id="row">
<div id="col">
<img src="01.png" alt="">
</div>
<div id="col">
<img src="02.png" alt="">
</div>
<div id="col">
<img src="03.png" alt="">
</div>
</div>
<div id="row">
<div id="col">
<img src="04.png" alt="">
</div>
<div id="col">
<img src="05.png" alt="">
</div>
<div id="col">
<img src="06.png" alt="">
</div>
</div>
<div id="row">
<div id="col">
<img src="07.png" alt="">
</div>
<div id="col">
<img src="08.png" alt="">
</div>
<div id="col">
<img src="09.png" alt="">
</div>
</div>
</div>
with Css:
<style type="text/css">
<!--
img {
width: 100%;
height: auto;
}
#Table {
display: table;
width: 50%;
}
#row {
display: table-row;
}
#col {
display:table-cell;
}
-->
</style>
UPDATE:
I have to add in the middle (img 5) a table with the items, the quantity and the price. I have updated the fiddle. There are some problems in the fiddle but here there are the link with the screenshot of my page.
https://www.dropbox.com/s/sxa2ug1vz5lcdml/schermata7.png?dl=0
JSFIDDLE:
http://jsfiddle.net/wdb5gq29/43/
I'm working on a similar project (responsive image map), and I found positioned divs placed over a single image to be much more stable.
It has the added advantage of being used as an image map, because you can put content in or add functionality to the 9 divs, use more or less divs, and there are no alignment issues because it uses one image versus multiple sliced images. An awesome example is the responsive image map at CSS Play: http://www.cssplay.co.uk/menu/cssplay-responsive-image-map.html
Here is the code for an example similar to yours.
JSFiddle
HTML
<div id="wrapper">
<div class="image-holder">
<img src="http://i.imgur.com/3bhQPx0.jpg" class="image-background" />
<div class="hotspot-container">
<div id="L01">1</div>
<div id="L02">2</div>
<div id="L03">3</div>
<div id="L04">4</div>
<div id="L05">5</div>
<div id="L06">6</div>
<div id="L07">7</div>
<div id="L08">8</div>
<div id="L09">9</div>
</div>
</div>
</div>
(Note: The CSS is written out in long form as an example for easier use. It would be shortened down on a live site by combining the similar styles.)
html{
height:100%;
width:100%;
margin:0;
padding:0;
border:none;
}
body {
height:100%;
width:100%;
margin:0;
padding:0;
border:none;
}
#wrapper {
height:100%;
width:100%;
}
.image-holder {
width:50%;
position:relative;
}
.image-background {
width:100%;
display:block;
}
.hotspot-container {
height:100%;
width:100%;
position:absolute;
top:0;
left:0;
}
#L01 {
width:33%;
height:33%;
position:absolute;
left:0%;
top:0%;
border:solid 1px #000000;
}
#L02 {
width:33%;
height:33%;
position:absolute;
left:33%;
top:0%;
border:solid 1px #000000;
}
#L03 {
width:33%;
height:33%;
position:absolute;
left:66%;
top:0%;
border:solid 1px #000000;
}
#L04 {
width:33%;
height:33%;
position:absolute;
left:0%;
top:33%;
border:solid 1px #000000;
}
#L05 {
width:33%;
height:33%;
position:absolute;
left:33%;
top:33%;
border:solid 1px #000000;
}
#L06 {
width:33%;
height:33%;
position:absolute;
left:66%;
top:33%;
border:solid 1px #000000;
}
#L07 {
width:33%;
height:33%;
position:absolute;
left:0%;
top:66%;
border:solid 1px #000000;
}
#L08 {
width:33%;
height:33%;
position:absolute;
left:33%;
top:66%;
border:solid 1px #000000;
}
#L09 {
width:33%;
height:33%;
position:absolute;
left:66%;
top:66%;
border:solid 1px #000000;
}
Remember to add !DOCTYPE html, or IE will have issues. Also, the div widths are set at 33% with a border to highlight the structure. On the live version, you'll delete the borders and try setting the horizontal divs to 33.333%, equaling to 100%. Or 33% 34% 33%.
For your original CSS table layout, you can add the following additional CSS to stabilize the table and remove the default bottom gap under the images, and it worked in Firefox and Explorer, but showed the odd gap or alignment issues in other browsers at various screen sizes.
.table {
display:table;
width:50%;
margin:0;
padding:0;
border-width:0;
border-style:none;
border-collapse:collapse;
}
.col {
display:table-cell;
border:none;
}
.image {
width:100%;
height:auto;
border:0px;
vertical-align:bottom;
}
Updated Redesign Using a Flexable Image Background
According to your latest Fiddle, it looks like you would like to display a data table, with the printer image as a background. The JSFiddle example below has a flexible container div set at the requested 50%. Within the container is the data table, and an absolutely positioned printer image that scales, and serves as the background.
JSFiddle
.price-container {
position:relative;
padding:0;
display:table;
width:50%;
}
.image-bg {
display:block;
position:absolute;
top:0;
left:0;
min-height:100%;
/* min-width:300px; - setting is helpful if the distortion at smaller sizes is bothesome, set here and on table-holder - width of the actual image */
width:100%;
height:auto;
margin:0;
padding:0;
z-index:-1;
}
.table-holder {
z-index:2;
padding:2em;
/* min-width:300px; */
}
.printer-display-table {
width:100%;
padding:0;
border-width:0;
border-style:none;
border-collapse:collapse;
font-family:verdana;
font-size:.6em;
}
.printer-display-table td {
border:solid 1px #000000;
padding:.5em;
}
HTML
<div class="price-container">
<img src="http://i.imgur.com/wurCt2y.jpg" class="image-bg" />
<div class="table-holder">
<table class="printer-display-table">
<tr><td>Item</td><td>Q</td><td>Price</td></tr>
<tr><td>BlaBlaBla</td><td>1</td><td>50</td></tr>
<tr><td>Eve</td><td>Jackson</td><td>94</td></tr>
<tr><td>Item</td><td>Q</td><td>Price</td></tr>
<tr><td>BlaBlaBla</td><td>1</td><td>50</td></tr>
<tr><td>Eve</td><td>Jackson</td><td>94</td></tr>
</table>
</div>
</div>
Add display: block and remove width from your img tag to get rid of the cellspacing:
img {
display: block;
height: auto;
}
updated fiddle: http://jsfiddle.net/wdb5gq29/42/

IE8: getting DIVs to float left

In IE8, I am trying to display 4 child div's side by side withing a parent div. I would like the parent div to overflow and scroll horizontally and for the child div's to be next to each other horizontally as well. Thanks
HTML:
<div id="a">
<div class="b">One</div>
<div class="b">Two</div>
<div class="b">Three</div>
<div class="b">Four</div>
</div>
and CSS:
#a{
position:relative;
height:130px;
width:800px;
background:purple;
overflow:auto;
}
.b{
position:relative;
display:inline-block;
height:100px;
width:400px;
background:red;
border:1px solid #000000;
float:left;
}
Here are my suggestions:
Use classes for repeated elements. ids are unique, but classes can be used multiple times.
Use inline-block instead of float, not in addition.
Set white-space:nowrap on the container to prevent the children
from wrapping.
<div id="a">
<div class="b">One</div>
<div class="b">Two</div>
<div class="b">Three</div>
<div class="b">Four</div>
</div>
#a{
height:130px;
width:800px;
background:purple;
overflow:auto;
white-space:nowrap;
}
.b{
height:100px;
width:400px;
background:red;
border:1px solid #000000;
display:inline-block;
}
http://jsfiddle.net/X2Rjn/2/
http://cssdesk.com/exMH4 (for those who cannot see jsfiddle)
Here's a floated variant:
<div class="a">
<div class="wrapper">
<div class="b">One</div>
<div class="b">Two</div>
<div class="b">Three</div>
<div class="b">Four</div>
</div>
.a{
height: 130px;
width: 800px;
overflow: scroll;
background: purple;
}
.wrapper{
width: 1608px;
}
.b{
height: 100px;
width: 400px;
background: red;
border: 1px solid #000000;
float: left;
}
http://jsfiddle.net/BYLFn/3/

Center two containers with absolute position within a div

Using CSS, I want to horizontally center two "boxes" I have within a div. The boxes are absolutely positioned.
Here is the JSFiddle: http://jsfiddle.net/p4sA3/8/
How would I achieve this without using specific widths?
HTML:
<button id="change">Change</button>
<div id="total-wrap">
<div id="hello-wrap" class="bunch">
<div id="box">
<p> Hello, this is text1 </p>
</div>
<div id="box">
<p> Hello, this is text2 </p>
</div>
</div>
<div id="goodbye-wrap" class="bunch">
<div id="box">
<p> Goodbye, this is text1 </p>
</div>
<div id="box">
<p> Goodbye, this is text2 </p>
</div>
</div>
</div>
CSS:
#total-wrap {
border:1px solid #000;
height:500px;
}
#box {
position:relative;
display:inline-block;
width:300px;
height:100px;
background-color:yellow;
margin:10px;
}
.bunch {
position: absolute;
text-align:center;
}
I would do it with left:0; and right:0 as they are absolutely positioned.
DEMO http://jsfiddle.net/kevinPHPkevin/p4sA3/19/
.bunch {
position: absolute;
text-align:center;
left:0;
right:0;
}
Solution:
#total-wrap {
border:1px solid #000;
height:500px;
}
#box {
display:inline-block;
width:300px;
height:100px;
background-color:yellow;
margin:10px;
text-align:center;
}
.bunch {
text-align:center;
}
<div id="wrap">
<div id="left">Box1</div>
<div id="right">Box2</div>
</div>
#wrap {
background: #e7e7e7;
padding: 40px;
text-align: center;
width: auto;
}
#left, #right {
background: yellow;
display: inline-block;
padding: 20px;
}
Is this what you want?
#box {
position:relative;
display:inline-block;
width:100px;
height:100px;
background-color:yellow;
margin:10px;
}
DEMO: http://jsfiddle.net/p4sA3/11/
The thing is that as long the sum of the widths exceeds the container, the second div will be positioned beneath the first one
In this other demo I didn't use width: http://jsfiddle.net/p4sA3/13/
If you want to use jQuery:
Demo
keepCentered = function() {
$('#hello-wrap').css({'margin-left':($('#total-wrap').width()-$('#hello-wrap').width())/2});
$('#goodbye-wrap').css({'margin-left':($('#total-wrap').width()-$('#goodbye-wrap').width())/2});
}
$(document).ready(keepCentered);
$(window).bind('resize', keepCentered);

how to arrange 3 divs(left/bottomcenetr/topright) inside div in html?

i have trying to achieve this
| Div | |Div nav wrapper|
| logo |
|container|| Div banar container |
| || |
i hv tried this
<div class="grid_12">
<!--logo_container start here-->
<div id="logo_container">
</div>
<div style="margin-top: 57px" class="grid_13">
<div id="banar_container">
</div>
</div>
<!--logo_container end here-->
<div id="nav_wrapper">
<ul id="nav">
<li class="current_page_item">Home</li>
<li>My Profile</li>
<li>LogOut
</li>
</ul>
</div>
<!--#nav_wrapper-->
</div>
and the css are
.grid_12 {
width:940px;
}
.grid_13 {
width:851px;
}
#logo_container{
float:left;
margin-top:20px;}
#logo{
background:url(../images/bp.jpg) no-repeat left;
width:100px;
float:left;
height:100px;
}
#banar_container
{
float: left;
}
#banar
{
background:url(../images/Banner1.png) no-repeat left;
width: 851px;
float:left;
height: 71px;
}
#nav_wrapper {
position:relative;
display:inline;
float:right;
margin-right:25px;
margin-top:6px;
height:50px;
}
its not coming that way.. so what should i do?
this is my complete code ... this is what i am trying but failing to do it ... so guys pls take a look at this and tell me my fault
guys i am still struggling with this
I hope you'll find this example useful. Notice that, as you said, the size is fixed but still fluid relative to it's parent by using percentage.
HTML
<div id="example">
<div class="box01"></div>
<div class="box02"></div>
<div class="box03"></div>
</div>
​CSS
#example {
width: 400px;
height: 400px;
}
div.box01 {
float: left;
width: 20%;
height: 100%;
background-color: #eee;
}
div.box02 {
float: right;
min-width: 100px;
min-height: 100px;
background-color: #ccc;
}
div.box03 {
float: right;
width: 80%;
min-height: 100px;
background-color: #aaa;
}​
Code Example
The trick is to realize you need more divs than just those three. That is to say, divs 2 and 3 need to have a parent that is a sibling of div 1. Try something like this: http://codepen.io/anon/pen/rLDqc
HTML:
<div id="left">This is your div on the left</div>
<div id="center">
<div id="main">Hello, this is the third div</div>
<div id="right">This is the div in the top right</div>
</div>
<div class="clear"></div>
CSS:
#left{
width:30%;
background:red;
height:100px;
}
#center{
width:70%;
background:blue;
height:100px;
}
#left, #center{
float:left;
}
#right{
position:relative;
display:inline;
float:right;
}
#main{
margin-top: 57px;
float: left;
}
.clear{
clear:both;
}
You may do something like this:
<div class="wrapper">
<div class="div1"></div><div class="div2"></div>
<div class="div3"></div>
</div>​
and CSS:
div{border:solid 1px black;}
.div1 {
width:50px;
height:100px;
float:left;
}
.div2 {
width:50px;
height:18px;
float:right;
}
.div3 {
width:250px;
height:80px;
float:left;
}
.wrapper{
width:304px;
border:none;
}​
Demo
Or maybe even something like this: http://jsfiddle.net/4YX9H/1/ - width and height of div2 may be almost any (it just must be not wider than its parent)
#div1 {
width: 100%;
}
#div2, #div3, #div4 {
width: 33.3%;
float: left;
}
<div id="div1">
<div id="div2"></div><div id="div3"></div><div id="div4></div>
</div>
Change width of inside divs according to your needs.
Most confusing job in web designing for me is to align divs like these but if you understand every aspect of float, display and some other properties important for layout designing then you can easily create such layouts.
Check this fiddle for an example
http://jsfiddle.net/DeepakKamat/xQKXz/1/
The HTML :
<div class="container">
<div id="div1">Div 1</div>
<div id="div2">Div 2</div>
<div id="div3">Div 3</div>
</div>​
The CSS :
.container {backgroundcolor:yellow;display:block;width:400px;height:150px;padding:10px;}
.container div {margin:2px;color:white;}
#div1 {background-color:blue;width:20%;height:100%;border:2px dashed white;float:left;}
#div2 {background-color:green;display:inline-block;width:20%;height:70px;float:right;border:2px dashed white;}
#div3 {background-color:red;display:inline-block;width:76%;height:48%;border:2px dashed white;}​
I hope this helps you.
Not sure what is the values of your div width and height.
Check this DEMO
Updated DEMO

How to make a div align to the right side of the parent while maintaining its vertical position?

Please refer to this handy diagram I drew:
div1's height is unknown. div3's width is fluid; it should never overlap div2. Both div1 and div2 have the same width and are horizontally centered via margin: auto. How can I position div3 so that it aligns to the right side of body (no matter how wide body is) while sharing vertical position with div2? (Using CSS)
.div1{
margin:0 auto;
width:100px;
height:50px;
border:5px solid #995555;
}
.div2{
width:100px;
margin:0 auto;
border:5px solid #aaaa55;
height:200px;
}
.div3{
float:right;
width:50px;
height:100px;
border:5px solid cyan;
}
<div class="div1">div1</div>
<div class="div3">div3</div>
<div class="div2">div2</div>
Demo also at http://jsfiddle.net/XjC9z/1/
Like this?
HTML:
<div id='container'>
<div id='first'>1</div>
<div id='second'>2</div>
<div id='third'>3</div>
</div>​
CSS:
#container{
width: 100px;
margin:0 auto;
}
#first{
border: 1px solid #ff55ff;
}
#second{
border: 1px solid #55ff77;
}
#third{
border: 1px solid #448855;
}
#first,
#second{
width: 50px;
clear:both;
float:left;
}
#third{
clear:none;
float: left;
}
​
See this fiddle:
http://jsfiddle.net/zaNvR/1/
A simple div grid would do the trick:
http://jsfiddle.net/NUGPv/
<div class="con">
<div class="lft">div 1</div>
<div class="rgt"></div>
</div>
<div>
<div class="lft">div 2</div>
<div class="rgt">div 3</div>
</div>​
.con { overflow:hidden; }
.lft { width:100px; height:100px; float:left; }
.rgt { width:100px; height:100px; float:left; }
Simply leave the the top right cell empty.

Resources