Multiple FLOAT DIV and BORDER - html

I've got an issue when i try to put 2 divs, both them them floating to the left side, one with width 80% and the other the 20%. Then i'd like to draw a border on the right side of the first div and a box-shadow of 5px, because each div has a different color.
So I've just searched on this site and i've found this solution:
Border issue in Floating div
But it's bad idea IMHO.... i've a resolution of 1920px width and i can't put 48% for the width of a DIV.... for 4px border i'll got a white space in the webpage for the 2% - 2px.
You could say, just add the background color to the body: i could because each DIV has already it's own, but it's also a problem OF SPACE, PROPORTIONS!!!
Another problem i'm experiencing with: i've set the height 100% (on the second div, 20% width)and it works in the example; but in the real website, which is the height also set to 100% the DIV doesn't occupy the whole height of the column but just until the margin limit of the last image.
The last problem: box-shadow with floating div it's bad idea...
should i put the box-shadow on the last div, just for the left side, instead of the right side for the previous div?
Look at my code here http://jsfiddle.net/9gp6J/
div#contenuto_body{
margin: 0 0;
padding: 0 0;
float: left;
width: 80%;
height: 100%;
background-color: #C90;
-moz-box-shadow: 0 0 5px 1px #333;
-webkit-box-shadow: 0 0 5px 1px #333;
-ms-box-shadow: 0 0 5px 1px #333;
box-shadow: 0 0 5px 1px #333;
border-right: 4px solid #E6B800;
}
body{
margin: 0 0;
padding: 0 0;
}
div#ads{
margin: 0 0;
padding: 0 0;
width: 20%;
float: left;
height: 100%;
background-color: #CCC;
}
div#ads img{
width: 70%;
max-width: 200px;
display: block;
margin: 25% auto;
}

You could use the css3 feature calc(...) available in css3 depending on which browsers you are supporting this may suitable. Anything below IE9 doesn't support this so keep that in mind. Here's a fiddle:
http://jsfiddle.net/9gp6J/9/
Any other solution would have to involve negative margins such as:
div#contenuto_body{
...
margin-right: -4;
}
That should work anything IE7 and up.

for the border issue add a div inside the left div and give a right border to that inner div. This way the outer left div can remain 80% without the added 4px border problem.
HTML:
<div id="container">
<div id="left">
<div id="inner_left">
content left
</div>
</div>
<div id="right">
content right
</div>
</div>
CSS:
div#container {
height:200px;
}
div#left {
float:left;
width:80%;
height:100%;
background:red;
}
div#inner_left {
border-right:4px solid black;
height:100%;
}
div#right {
float:left;
width:20%;
height:100%;
background:green;
}
Check this jsfiddle

Related

box shadow at top and bottom

I have the following box shadow with the effect attached. Right now the top of the element has the box shadow effect (see attached), but the bottom does not have the same effect.
How can I make it so that the bottom of the element looks exactly like the top of the element. (see attached for an image)
box-shadow: 0px 0px 60px -18px #CACACA;
Here is your shadow setting applied to a DIV that's 500px x 200px:
http://codepen.io/anon/pen/aNxWgE
If (in that codepen) you change margin: 100px auto; to margin: 0 auto;, you won't see the top shadow anymore. If you erase the width (thereby making the DIV 100% wide), you won't see the side shadows anymore. So probably something similar happens with your bottom shadow.
To avoid that, use margins which are at least as wide as the shadow.
We have not enough infos to tell you where you really go wrong but:
if shadow is too light and spread, you may not see it
when you downscale a shadow, you need enough height and width so it can be produced
body * {
box-shadow: 0px 0px 60px -18px #000;
background:white;
margin: 2em;
}
.minH {
min-height: 38px;
box-shadow: 0 0 60px -18px #000;/* black to make see it better */
}
.show {
float:left;
margin-left:2em;
height:60px;
width:60px;
/* even then , black blured on 60px doesn't show much;*/
}
.show + .show {
height:120px;
width:120px;
/* even then , black blured on 60px doesn't show much;
}
<hr/>
<p>hello</p>
<div></div>
<p class="minH">min-height is necessary to give room to draw box-shadow: here - 18px on each sides makes a min width and height of 18x2 =36px <b>But it will start to show at 37px if your eye can see it </b></p>
<p class="show">make bigger to show</p><p class="show">make twice bigger to show</p>
To understand through example what happens :
offset shadow far enough and without blur to see if it is there or not and how big it is (using black again)
hover the snippet to activate the blur effect and see what becomes the 60px - 18px black shadow.
body {
display: flex;
justify-content: space-around;
background: gold;
}
div {
box-sizing: border-box;
height: 20px;
width: 20px;
background: gray;
box-shadow: 0 65px 0 -18px;
}
div:nth-child(2) {
height: 36px;
width: 36px;
}
div:nth-child(3) {
height: 38px;
width: 38px;
}
div:nth-child(4) {
height: 60px;
width: 60px;
}
/* add blur on hover */
html:hover div {
box-shadow: 0 65px 60px -18px;
}
<div>20px</div>
<div>36px</div>
<div>38px</div>
<div>60px</div>

Why are my margins so messed up?

There is an odd problem here that I don't really understand.
I'm trying to just make the middle of the 3 vertical divs have another div inside it which has a black border and 10px of margin on all sides.
However, on the right side there is no visible margin, and on the bottom the div flows right out of the parent div and out of site into the footer.
What am I doing wrong? CSS for the middle div pair...
#mainContent {
height: 100%;
width: 100%;
}
#platter {
border: 1px solid black;
margin: 10px;
height: 100%;
width: 100%;
}
http://jsfiddle.net/Lf7wuty0/1/
Solution: http://jsfiddle.net/efordek0/1/
Borders are applied outside of the element, therefore if your element is width:100%; with a border: 1px solid black;, the border will fall outside of your desired constraint.
Instead of applying a margin to the inner-div #platter, apply a padding to the outer div #mainContent. This way the 100% values will still apply but be subtracted by the 10px padding of the #mainContent and your borders remain inside the desired area.
Here's the correct solution : http://jsfiddle.net/5L4tnwtg/
The changes:
Add:
*{
box-sizing:border-box;
-webkit-box-sizing:border-box;
-moz-box-sizing:border-box;
}
Modify:
#mainContent {
height: 100%;
width:100%;
padding: 10px;
}
#platter {
border: 1px solid black;
height: 100%;
width: 100%;
}

Images within divs are being cut off due to height differences, how to display them entirely?

My site consists of 3 divs (blueish boxes) lined in a row. Each div contains an image and either 3 or 4 lines of text (wrapped in p tags)
The problem is that the images are not being shown entirely within the divs. Instead the sides are being cut off and this obscures the image. In the following demo you can see the divs containing cut-off images, and then the full-size images below them for reference. Demo here
Please note that the source images are different heights, yet they do not disrupt the even alignment of the lines across each div as shown below. I'd like this feature to remain:
How do I make the images display entirely within the div (including feathering effect)? I've created a mockup below of the ideal solution:
The code for the first div is:
<a href="htada">
<p class="vignette" style="background-image:url(http://www.luminouseyegfx.com/prolookwp/wp-content/uploads/2013/12/jet_ski-320x212.jpg)"></p>
<p class="redbox"> </p>
<p class="titlebox">Demo</p>
<p class="locationbox">Demo</p>
<p class="pricebox">Demo</p>
<!-- END OF SINGLE LISTING -->
</a>
and it's CSS:
.mainbox a {
display: inline-block;
vertical-align: top;
margin: 0 0.5em 0;
width: 28%;
background: #E7E6F2;
box-shadow: 0 50px 0 #E7E6F2 , 0 100px #E7E6F2 , 0 150px #E7E6F2;
border-top: 1em solid white;
padding: 0.5em;
margin-top: 151px;
height: 700px;
}
You can see the image is produced using a div with style of background-image:url(http:// ... and that div's CSS is:
.vignette {
width: 90%;
margin-left:auto;
margin-right:auto;
margin-bottom:1%;
margin-top: 4%;
box-shadow: 15px 15px 40px #E7E6F2 inset,-15px -15px 40px #E7E6F2 inset;
height: 290px;
background-size: cover;
background-repeat: no-repeat;
}
Thanks for your help!
Rather than making the images the background, why not just add them as a sub-element of the <p>'s?
<p class="vignette">
<img src="..."/>
<p>
Then you can apply CSS to the image too, and make it the full width of the container.
.vignette img
{
width: 100%;
position: relative;
z-index: -1;
}
The z-index and position will place the image below the box-shadow of the parent.
An alternative would be to do this, but place the box-shadow on the img, as opposed to the p.
.vignette img
{
width: 100%;
box-shadow: inset 15px 15px 40px #e736f2, inset -15px -15px 40px #e7e6f2;
}

Reducing the width of div moves to left side in css

Here is the
http://jsfiddle.net/vicky081/jmGwX/5/ I want to change the width of the div which is now 100% when i change the width to 50% the div appear left side. How can i make that div as center by this when i reduce the size of the div it appear from the center is it possible?
I know the width of the div is 100% then it appear like from left 0 to right 100 if i change the width to 50 also it appear from left to 50% right Is there is a way to show it from center when i change the width it appear both for example: if i reduce the width of the div is 50% then it appear like 25% from center of left and 25% center of right
Here is the code CSS:
.notify {
background: #FFFFFF;
width:50%;
position: relative;
margin:-13px 0px 0px -5px;
padding: 2px 0px 0px 0px;
border-bottom:2px solid #CC0000;
box-shadow: 0px 4px 5px #AAAAAA;
font-size:14px;
font-family: 'Lato Regular', Arial;
text-transform:uppercase;
text-align:center;
}
Edit your CSS like here:
.notify {
....
margin: 0 auto 0 auto;
....
}
http://jsfiddle.net/wRM8j/
EDIT:
If position is fixed add
.notify {
....
position: fixed;
left: 0;
right: 0;
....
}
http://jsfiddle.net/vZexH/
The first Solution is perfect but in case you want to play with that using javascript.
Just include this line.
<script>
var decider=parseInt(document.defaultView.getComputedStyle(document.getElementsByTagName("div")[0]).width)/2;
document.getElementsByTagName("div")[0].style.left=(window.innerWidth/2)-decider;
</script>

Trouble aligning DIVs on horizontal plane

I'm on Win XP but this problem occurs on Firefox, IE, and Google Chrome. I want to align two DIVs on the same horizontal plane. I want the div on the left to occupy 24% of the screen and the div on the right to occupy the rest. Everything looks fine when my browser is maximized, but when I click the resize button to make the window smaller, the two DIVs are no longer on the same plane. The top of the right DIV appears beneath the bottom edge of the left DIV (the left boundary of the right DIV is still correctly aligned just after the right boundary of the left div).
How can I make both DIVs appear on the same horizontal plane, even when the window is not maximized? Here is the HTML I'm using ...
<div class="header">
<img src="logo.gif"/>
</div>
<div class="container">
<div id="contents">
<div class="categoryPanel"></div>
<div class="productDetailsPanel"></div>
</div>
</div>
and here is the CSS ...
.header {
width: 100%;
height: 63px;
background-color: #333366;
}
.container {
width: 100%;
}
.categoryPanel {
height: 600px;
width: 24%;
float: left;
margin: 10px 5px 0px 0px;
background-color: green;
}
.productDetailsPanel {
height: 600px;
border-color: #BBBBBB;
border-style: solid;
border-width: 1px;
float: right;
margin: 10px 10px 0 5px;
}
Thanks, - Dave
One way to kind of achieve the layout you want is to stop floating .productDetailsPanel, and give it a left margin of 25% (i.e. the width of .categoryPanel, plus spacing between them). (You’ll also want to remove the top margin on .categoryPanel.)
http://jsfiddle.net/uSbAs/
But that does mean the spacing between your columns will be defined as a percentage of the .container, rather than a fixed number of pixels.
On .productDetailsPanel, remove float: right and add overflow: hidden, job done; it's exactly what you asked for.
http://jsfiddle.net/thirtydot/KjZ8Q/
The reason overflow: hidden helps in this case is not obvious, read this.
In order for it to take up the entire space you would need to either fill it with something or provide a width. I've create a jsfiddle to show the results. Essentially I modified the .productsDetailsPanel by adding a width: 75%; removing the float:right; and modifying your margin: 10px 0 0 0;
Here is the new css for .productsDetailsPanel
.productDetailsPanel {
height: 600px;
width: 75%;
border-color: #BBBBBB;
border-style: solid;
border-width: 1px;
margin: 10px 0px 0 0px;
float: left;
background-color: red;
}
http://jsfiddle.net/rhoenig/qXvag/
This could work (float: left):
.productDetailsPanel {
height: 600px;
border-color: #BBBBBB;
border-style: solid;
border-width: 1px;
float: left;
margin: 10px 10px 0 5px;
}