On a site I'm building I want to have a 3 coloured border example here for the body.
What is the easiest way to create this?
I tried the following but it didn't work out how I expected it to:
<div id="red">
<div id="white">
<div id="blue">
<!--SITE GOES HERE-->
</div>
</div>
</div>
#red {
width: 100%;
height: 100%;
padding: 16px;
background: #CC092F;
}
#white {
width: 100%;
height: 100%;
padding: 16px;
background: white;
position: absolute;
z-index: 2;
}
#blue{
width: 100%;
height: 100%;
padding: 16px;
background: #0C144E;
position: absolute;
z-index: 3;
}
The problem with that is the padding pushes the divs offscreen, I realise I'm going about it the wrong way… (If i use percentages i.e. 98% it obviously scales, which I do not want) but I can't think of an alternative. Thanks in advance.
try this (SEE FIDDLE):
<div id="red" class="site-border">
<div id="white" class="site-border">
<div id="blue" class="site-border">
<div id="content"></div>
</div>
</div>
</div>
* {
margin: 0;
padding: 0;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
#content {
height: 500px;
background: #e3e3e3;
padding: 16px;
}
.site-border {
width:100%;
}
#red {
border: 16px solid #CC092F;
}
#white {
border: 16px solid #fff;
}
#blue {
border: 16px solid #0C144E;
}
Instead of scaling, you should use the below properties in your CSS, this way, the borders and paddings will be counted inside the element instead of outside as normal box model does.
* {
margin: 0;
padding: 0;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
Also, you shouldn't use position: absolute; cuz I don't see any reason of using that over here.
You could try this css:
div {
width: 100px;
height: 200px;
border: 3px solid navy;
outline: 3px solid #fff;
box-shadow: 0 0 0px 6px darkred;
}
Fiddle: http://jsfiddle.net/BXFUk/2/
Related
I have a usual search as most websites do. The results are shown below on the div that is visually connected to the search input.
It looks like this:
I need to have one solid shadow for the div parent but can't figure out or find online the way to do this.
I thought that I could either make 2 separate shadows, but that will look inconsistent and just terrible. Or I could make a div below with the same height and width that will act as a shadow but that's a non-necessary complication + the .search-results div's height will change dynamically.
This is an example:
body {
background-color: gray;
}
.search-wrapper {
position: relative;
margin: 100px 100px 0px 100px;
width: 200px;
overflow: initial;
box-shadow: 0px 0px 10px 10px rgba(0,0,0,0.3);
}
.search {
width: 200px;
height: 30px;
color: white;
border-radius: 4px;
} .search input {
padding: 0;
background-color: #022222;
border: none;
height: 100%;
width: 100%;
color: white;
}
.search-results {
position: absolute;
height: 150px;
width: 200px;
background-color: black;
}
<div class="search-wrapper">
<div class="search">
<input placeholder="air max . . .">
</div>
<div class="search-results">
</div>
</div>
I am sure there must be a clever and simple way to do this.
Please help,
Thank you
You don't need to use positions here and you can use FlexBox instead. It's the best way and a lot easier. Also, you can ignore all of them, they will place on top of each other because they are block-level tags/elements. (divs)
You don't need to put the input in another div parent, use it as I did.
Sorry, I couldn't understand your code, so I must write the whole code from the beginning.
EDIT
I removed display flex, cause it's not necessary.
* {
padding: 0;
margin: 0;
box-sizing: border-box;
font-family: Arial;
border-radius: 10px;
background-color: #fff
}
body {
height: 100vh;
background-color: gray;
padding: 30px
}
.search-wrapper {
/* EDITED HERE ADDED HEIGHT */
position: relative;
z-index: 999;
width: 200px;
height: 160px;
box-shadow: 0 0 2px 5px rgba(232, 232, 232, .2)
}
.search-input {
width: 100%;
position: absolute;
padding-block: 5px;
border: none;
outline: none;
padding: 15px
}
.search-result {
/* EDITED HERE */
position: absolute;
z-index: 999;
bottom: 0;
width: 100%;
padding: .5px
}
p {
padding: 10px 0 10px 10px;
}
p:hover {
background-color: #e8e8e8;
cursor: pointer
}
<div class='search-wrapper'>
<input class='search-input' placeholder='Search...'>
<div class='search-result'>
<p>Nike Airforce</p>
<p>Nike Airforce</p>
<p>Nike Airforce</p>
</div>
</div>
I've got the following code:
.wrapper {
display: flex;
height: 25px;
}
.myInput {
width: 50px;
height: 100%;
border: 1px solid grey;
border-right: none;
}
.myInputAddon {
width: 25px;
height: 100%;
background-color: green;
border: 1px solid green;
}
<div class="wrapper">
<input class="myInput">
<div class="myInputAddon" type="number"></div>
</div>
I thought, when I give a hardcoded height to my wrapper div (in the example 25px) and then height: 100%; to his child-elements, they would flex correctly and have the same height.
But in my snippet, my input is higher than my div.
If I remove the height from the wrapper div and give the input a height 23px and to the child-div 25px, it works. But I would like to set it a little bit dynamically.
It should look like this:
How can I do this?
Thanks and cheers.
The problem is default padding of input element so you can just add box-sizing: border-box and keep padding inside height of element.
.wrapper {
display: flex;
height: 25px;
}
.wrapper * {
box-sizing: border-box;
}
.myInput {
width: 50px;
height: 100%;
border: 1px solid grey;
border-right: none;
}
.myInputAddon {
width: 25px;
height: 100%;
background-color: green;
border: 1px solid green;
}
<div class="wrapper">
<input class="myInput">
<div class="myInputAddon" type="number"></div>
</div>
The input element has default styling from the browser:
Make the following adjustments:
.wrapper {
display: flex;
height: 25px;
}
.myInput {
width: 50px;
height: 100%;
border: 1px solid grey;
border-right: none;
box-sizing: border-box; /* NEW; padding and border now absorbed into height:100% */
}
.myInputAddon {
width: 25px;
height: 100%;
background-color: green;
border: 1px solid green;
box-sizing: border-box; /* NEW */
}
<div class="wrapper">
<input class="myInput">
<div class="myInputAddon" type="number"></div>
</div>
Best way to demonstrate what I want is to show it:
I want the left and right div to expand to the left and right edge of the container div automatically.
It can be done with Javascript and with flex but I'm wondering is there is another way that supports IE9+ (flex is IE11+)
I created this live demo (click "Run with JS") with a dynamically changing center div (since the "real life" problem doesn't have a static size)
Using a display: table-cell would make it easy for you.
Demo: http://jsfiddle.net/abhitalks/VytTX/1/
HTML:
<div class="outer">
<div id="left" class="inner"></div>
<div id="center" class="inner">...</div>
<div id="right" class="inner"></div>
</div>
CSS:
body { width: 100%; }
div.outer {
width: 90%;
border: 1px solid gray;
background-color: rgb(12, 34, 43);
text-align: center;
display: table;
border-spacing: 10px;
}
div.inner {
border: 1px solid gray;
height: 200px;
display: table-cell;
min-width: 20px; width: 20px;
padding: 4px;
background-color: rgb(212, 234, 143);
}
You could achieve that like this :
An example: http://codepen.io/srekoble/pen/rugxh (change the variable of the center width $width)
It's a sass file for a variable usage:
* {
box-sizing: border-box;
-webkit-box-sizing: border-box;
}
div.outer {
width: 100%;
border: 1px solid gray;
background-color: rgb(12,34,43);
text-align: center;
margin: 0 auto;
font-size: 0;
}
div.inner {
border: 1px solid gray;
height: 200px;
display:inline-block;
min-width: 20px;
}
$width: 50%;
#center {
width: $width;
background: red;
}
#left,
#right {
width: ( 100% - $width ) / 2;
background: yellow;
}
<style>
body
{
background: #0B222A;
}
.outer
{
width: 400px;
height: 300px;
background: #D3EA8F;
margin: auto;
}
.inner
{
width: 60%;
height: 300px;
background: #D3EA8F;
border-left: solid 10px #0B222A;
border-right: solid 10px #0B222A;
margin: auto;
}
</style>
<div class="outer">
<div class="inner"></div>
</div>
I am making a simple slideshow and I have got the javascript working very easily. However the layout is not going as well. The current image is display in big with a fixed width of 80% and the height can change to keep its aspect ratio.
The problem with this is that I want the the current image to be displayed in its correct aspect ratio (which it is) and I want the thumbnail bar on the right to have a scrollbar if it overflows this height.
Here is a demo on jsfiddle: http://jsfiddle.net/ZTBNR/1/
Here is the code:
CSS
div.slideshow{
width: 100%;
background: #B8B8B8;
display: inline-block;
box-sizing: border-box;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
border: 1px solid #000;
overflow: hidden;
}
div.slideshow > div.current-slide_wrapper{
padding: 10px;
float: left;
width: 80%;
display: inline-block;
box-sizing: border-box;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
overflow: hidden;
border-right: 1px solid #000;
}
div.slideshow > div.current-slide_wrapper img{
width: 100%;
vertical-align: bottom;
cursor: pointer;
}
div.slideshow > div.other-slides_wrapper{
padding: 10px 15px;
float: right;
width: 20%;
height: 100%;
display: block;
box-sizing: border-box;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
overflow-y: auto;
overflow-x: hidden;
}
div.slideshow > div.other-slides_wrapper img{
border: 5px solid #FFF;
width: 100%;
cursor: pointer;
margin-left: -5px;
}
div.slideshow > div.other-slides_wrapper img:hover{
border: 5px solid #EAEAEA;
}
div.slideshow > div.other-slides_wrapper img.current{
border: 5px solid #000;
}
HTML
<h3>Screenshots</h3>
<div id="slideshow-1" class="slideshow_wrapper">
<div class="slideshow">
<div class="current-slide_wrapper">
<img class="current-slide" data-slide="1" src="/path/to/image/website-screenshot1.jpg"/>
</div>
<div class="other-slides_wrapper">
<img class="other-slide current" data-slide="1" src="/path/to/image/website-screenshot1.jpg"/>
<img class="other-slide" data-slide="2" src="/path/to/image/website-screenshot2.jpg"/>
<img class="other-slide" data-slide="3" src="/path/to/image/website-screenshot3.jpg"/>
<img class="other-slide" data-slide="4" src="/path/to/image/website-screenshot4.jpg"/>
<img class="other-slide" data-slide="5" src="/path/to/image/website-screenshot5.jpg"/>
</div>
</div>
</div>
I solved it! I set div.slideshow to display: block; position: relative; and div.current-slide_wrapper is no longer floated.
I then set div.other-slides_wrapper to position: absolute; top: 0; right: 0; height: 100%;. This worked perfectly!
I have a layout defined through CSS that has three columns. It displays correctly through Chrome, but in Firefox, the third (right) column wraps around to the bottom. Am I defining the layout incorrectly?
<style type="text/css">
.content {
position: relative;
border-top-width: 1px;
width: 100%;
min-width: 960px;
margin-top: -1px;
}
.content-container {
border: 0;
position: relative;
width: 960px;
border-radius: 0 0 0 0;
margin: auto;
}
.left-menu-container {
width: 188px;
padding: 0 20px 0 0;
border: 0;
box-sizing: border-box;
vertical-align: top;
position: relative;
display: inline-block;
}
.center-content-container {
vertical-align: top;
display: inline-block;
min-height: 900px;
width: 500px;
border-left: 1px solid #EBEBEB;
border-right: 1px solid #EBEBEB;
height: 100%;
position: relative;
padding: 15px 0 0 0;
}
.center-content-subcontainer {
padding: 0 0 0 5px;
}
.right-menu-container {
vertical-align: top;
display: inline-block;
width: 260px;
border: solid;
position: relative;
}
.right-menu-subcontainer {
margin: 16px 0 0 0;
}
#slideshow {
position:relative;
height:250px;
width: 250px;
overflow: hidden;
background-color: #ffffff;
}
</style>
How can I get this to display correctly across browsers?
<body>
<div class="content">
<div class="content-container">
<div class="left-menu-container"></div>
<div class="center-content-container">
<div class="center-content-subcontainer"></div>
</div>
<div class="right-menu-container">
<div class="right-menu-subcontainer">
<div id="slideshow" align="center">
<img src="" alt="Slideshow" title="Slideshow" width="250" height="100">
</div>
</div>
</div>
</div>
</div>
</body>
In FF 5.x the box widths are this:
Left: 188 + 20 (width+ padding)
Center: 500 + 1 + 1 (width + L & R borders)
Right: 260 + 3 + 3 (width + L & R borders)
Total: 976
Firebug's Layout Inspector is your friend here.
I think the problem is with this line of CSS:
box-sizing: border-box;
What version of Firefox are you using? Because even as late as version 4 (possibly later, I'm not sure), Firefox only supports -moz-box-sizing. And if Firefox isn't changing its box-sizing, then that means it thinks you're trying to stick 968px worth of content into 960px worth of space.
Try this on your left-container:
.left-menu-container {
width: 188px;
padding: 0 20px 0 0;
border: 0;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
vertical-align: top;
position: relative;
display: inline-block;
}
Probably worth a read:
https://developer.mozilla.org/en/CSS/box-sizing