I want to put 2 divs next to each other centered, like described here. The problem is that it seems that my right div is always a bit under the left one when I put a <span> and a heading into the right div. Why does this happen and how can I avoid this?
#right {
display: inline-block;
width: 100px;
height: 160px;
padding: 15px;
background: rgba(0, 0, 0, .4);
border-radius: 1px;
box-shadow: 0 1px 1px rgba(0, 0, 0, .4) inset, 0 1px 0 rgba(255, 255, 255, .2);
}
#wrapper {
text-align: center;
padding: 40px;
height: 160px;
max-height: 160px;
}
#left {
display: inline-block;
width: 100px;
height: 160px;
padding: 15px;
background: rgba(0, 0, 0, .4);
border-radius: 1px;
box-shadow: 0 1px 1px rgba(0, 0, 0, .4) inset, 0 1px 0 rgba(255, 255, 255, .2);
}
<div align="center" id="wrapper">
<div id="left"></div>
<div id="right">
<span style="text-decoration: underline;">Heading</span>
<div id="some-content"></div>
</div>
</div>
Use vertical-align:top; on the #right and #left divs to get the wanted result
#right {
display: inline-block;
width: 100px;
height: 160px;
vertical-align:top;
padding: 15px;
background: rgba(0, 0, 0, .4);
border-radius: 1px;
box-shadow: 0 1px 1px rgba(0, 0, 0, .4) inset, 0 1px 0 rgba(255, 255, 255, .2);
}
#wrapper {
text-align: center;
padding: 40px;
height: 160px;
max-height: 160px;
}
#left {
display: inline-block;
vertical-align:top;
width: 100px;
height: 160px;
padding: 15px;
background: rgba(0, 0, 0, .4);
border-radius: 1px;
box-shadow: 0 1px 1px rgba(0, 0, 0, .4) inset, 0 1px 0 rgba(255, 255, 255, .2);
}
<div align="center" id="wrapper">
<div id="left"></div>
<div id="right">
<span style="text-decoration: underline;">Heading</span>
<div id="some-content"></div>
</div>
</div>
inline-blockelements are aligned according to the baseline of the included text. If there is no text, the bottom border will act as the baseline. In you example, the bottom border of the left DIV is aligned with the baseline of the text in the right div. If you erase the text (independently from the span tag), they are aligned. If there is text in both boxes, they will be aligned by their lowest text lines (see here: http://codepen.io/anon/pen/YqpJRg)
To align both boxes, use display: block and float: lefton the two DIVs, and for the wrapper position: relative; and margin:auto PLUS a fixed width (the sum of both DIV widths) to center it.
Here's a codepen of the result: http://codepen.io/anon/pen/mPOzaZ
Related
I have a simple scrollbar stylesheet that changes the scrollbar's appearance in Webkit based browsers. Here's the code:
::-webkit-scrollbar {
width: 14px;
height: 14px;
background-color: white;
-webkit-box-shadow: -1px 0px 0px 0px rgba(0, 0, 0, 0.1);
-moz-box-shadow: -1px 0px 0px 0px rgba(0, 0, 0, 0.1);
box-shadow: -1px 0px 0px 0px rgba(0, 0, 0, 0.1);
}
::-webkit-scrollbar-button {
background-color: rgba(0, 0, 0, 0.25);
}
::-webkit-scrollbar-thumb {
height: 50px;
background-color: rgba(0, 0, 0, 0.25);
border: 4px solid white;
border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
background-color: rgba(0, 0, 0, 0.4);
}
::-webkit-resizer {
background-color: rgba(0, 0, 0, 0.25);
}
<div style="height: 5000px;">
<br /><br />
<div style="margin: auto; width: 100px; height: 500px; overflow-y: scroll; border: 1px solid black;">
<div style="height: 1000px; padding: 24px;">
<div>Some content</div>
</div>
</div>
</div>
As you can see, the scrollbar within the black box has the box shadow on the left side. However, the one on the body does not, even though it is the same styles being applied to both. Why does this happen?
Just use the inset option in box-shadow for scroll bar shadows
::-webkit-scrollbar {
width: 14px;
height: 14px;
background-color: white;
-webkit-box-shadow: inset 0 0 6px black
}
::-webkit-scrollbar-button {
background-color: rgba(0, 0, 0, 0.25);
}
::-webkit-scrollbar-thumb {
height: 50px;
background-color: rgba(0, 0, 0, 0.25);
border: 4px solid white;
border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
background-color: rgba(0, 0, 0, 0.4);
}
::-webkit-resizer {
background-color: rgba(0, 0, 0, 0.25);
}
html{
background-color:white;
height:100%;
}
<div style="height: 5000px;">
<br /><br />
<div style="margin: auto; width: 100px; height: 500px; overflow-y: scroll; border: 1px solid black;">
<div style="height: 1000px; padding: 24px;">
<div>Some content</div>
</div>
</div>
</div>
I want to have multiple linear gradients or opacity on the same image.
Here is what I have so far:
HTML:
<body>
<div class="container">
<div class="inner-container">
<div class="left-section"></div>
<div class="right-section"></div>
</div>
</div>
</body>
CSS:
*{
margin: 0;
padding: 0;
}
body{
background-color: #333;
}
.container{
width: 1050px;
height: 750px;
background-image:
linear-gradient(
rgba(0, 0, 0, 0.5),
rgba(0, 0, 0, 0.5)
),
url(http://www.newyorker.com/wp-content/uploads/2015/12/Veix-Goodbye-New-York-Color-1200.jpg)
;
margin: 0 auto;
-webkit-box-shadow: -2px 1px 37px 0px rgba(0,0,0,0.75);
-moz-box-shadow: -2px 1px 37px 0px rgba(0,0,0,0.75);
box-shadow: -2px 1px 37px 0px rgba(0,0,0,0.75);
margin-top: 50px;
}
.inner-container{
width: 75%;
height: 75%;
border: 1px solid white;
margin: 0 auto;
margin-bottom: 50px;
border-radius: 5px;
background-image:
linear-gradient(
rgba(0, 0, 0, 0),
rgba(0, 0, 0, 0)
),
url(http://www.newyorker.com/wp-content/uploads/2015/12/Veix-Goodbye-New-York-Color-1200.jpg);
}
From the CSS, I am calling the same image in both containers. However doing this makes the layout look weird because the image isn't consistent between the outside and inner containers. How can I use the same image to achieve the affect in the image?
Add background-position: center top to both your container and inner-container and they will line up.
i've been trying all night to center this elements without having them stacked on each other:
I've tried floating them to the left it works, but, they stick to the left side no matter what i did.
HTML:
<div class="center pages clearfix">
<buuton class="center page-number">1</buuton>
<buuton class="center page-number">2</buuton>
<buuton class="center page-number">3</buuton>
</div>
CSS:
.center {
margin-left: auto;
margin-right: auto;
}
.page-number {
display: block;
float: none;
width: 28px;
height: auto;
border-radius: 3px;
background-color: rgba(0, 0, 0, 0.47);
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.34);
text-shadow: 0 2px 5px rgba(0, 0, 0, .5);
font-weight: 400;
line-height: 1.5;
text-align: center;
color: rgba(255, 255, 255, 0.47);
}
just update "display:block" to "display:inline-block" like the below updated css
updated css
.center {
margin-left: auto;
margin-right: auto;
text-align:center;
}
.page-number {
display: inline-block;
float: none;
width: 28px;
height: auto;
border-radius: 3px;
background-color: rgba(0, 0, 0, 0.47);
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.34);
text-shadow: 0 2px 5px rgba(0, 0, 0, .5);
font-weight: 400;
line-height: 1.5;
text-align: center;
color: rgba(255, 255, 255, 0.47);
}
demo
Try this: https://jsfiddle.net/uo23L4n4/
use inline-block instead of block for the buttons.
use text-align:center
<button class=" page-number">1</button>
.center {
margin-left: auto;
margin-right: auto;
text-align: center;
}
.page-number {
display: inline-block;
float: none;
width: 28px;
height: auto;
border-radius: 3px;
background-color: rgba(0, 0, 0, 0.47);
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.34);
text-shadow: 0 2px 5px rgba(0, 0, 0, .5);
font-weight: 400;
line-height: 1.5;
text-align: center;
color: rgba(255, 255, 255, 0.47);
}
Change your mark up to a list, makes it very easy to do this.
<ul class="center pages clearfix">
<li><buuton class="center page-number">1</buuton></li>
<li><buuton class="center page-number">2</buuton></li>
<li><buuton class="center page-number">3</buuton></li>
</ul>
Use this css
ul{
list-style:none;
}
li{
display:inline-block;
}
Who could help me to vertically align 2 divs inside a button element with these properties :
height of button is known
height of orange div is unknown
one of the div contain text (orange div), with 1 or 2 lines (number of lines is unknown)
.
Here is html code :
<button style="width: calc(125px * 1); height: calc(30px + 24px); margin-top: 0;margin-bottom: 0;">
<div id='bt_icon'></div>
<div id='bt_text'>Fermer</div>
</button>
CSS :
button {
display: inline-block;
border: 1px solid rgba(0, 0, 0, 0.5);
border-radius: 3px;
padding-left: 5px;
padding-right: 5px;
color: black;
font-family:'Tahoma', 'Arial', 'Helvetica', sans-serif;
font-size: 13px;
cursor: pointer;
background: linear-gradient(to bottom right, #EDDDB5, #D5C59D);
box-shadow: 2px 2px 0 rgba(255, 255, 255, 0.3) inset, -1px -1px 0 rgba(0, 0, 0, 0.3) inset, 2px 2px 8px rgba(0, 0, 0, 0.3);
}
#bt_icon {
float: left;
width: 34px;
height: 34px;
background-color: green;
}
#bt_text {
float: right;
width: calc(100% - 10px - 34px);
background-color: orange;
}
And the fiddle :
https://jsfiddle.net/15xceg8p/1/
The green square will contain an icon and is well vertically centered. The orange rectangle will contain text and is not vertically centered :(
Please update code
button {
display: inline-block;
border: 1px solid rgba(0, 0, 0, 0.5);
border-radius: 3px;
padding-left: 5px;
padding-right: 5px;
color: black;
font-family:'Tahoma', 'Arial', 'Helvetica', sans-serif;
font-size: 13px;
cursor: pointer;
background: linear-gradient(to bottom right, #EDDDB5, #D5C59D);
box-shadow: 2px 2px 0 rgba(255, 255, 255, 0.3) inset, -1px -1px 0 rgba(0, 0, 0, 0.3) inset, 2px 2px 8px rgba(0, 0, 0, 0.3);
}
#bt_icon {
width: 34px;
height: 34px;
background-color: green;
display: inline-block;
vertical-align: middle;
}
#bt_text {
display: inline-block;
vertical-align: middle;
width: calc(100% - 10px - 34px);
background-color: orange;
}
<button style="width: calc(125px * 1); height: calc(30px + 24px); margin-top: 0;margin-bottom: 0;">
<div id='bt_icon'></div>
<div id='bt_text'>Fermer</div>
</button>
try below styles and remove all css style from button
button{display: table-cell;}
button>div{display: table-cell;vertical-align: middle;}
Also remove float from both div's.
https://jsfiddle.net/t698pL8j/
I'd like to know why my class .top does not work for my second DIV wrapper top? I would expect to have 200px between the bottom of the picture on the right and the top of the red DIV but it's not working. See JSFIddle
HTML
<div class="wrapper top">
<div class="block-1">
<p><span>ddfsfsdsfds</p>
<p>fdsfsdfs.</p>
<p>dfsdfdsfds.</p>
</div>
<div class="block-2"><img src="images/136147555-e1329752650296-287x300.jpg" alt="136147555-e1329752650296-287x300" width="287" height="300"></div>
</div><!-- End wrapper -->
<div class="wrapper top">
<div class="block-100pc">
block-100pc
</div>
</div>
CSS
body {
background: #F2F2F2;
}
.top {
margin-top: 200px;
}
.wrapper {
position: relative;
display: block;
margin-right: auto;
margin-left: auto;
width: 980px;
}
.block-1 {
float: left;
box-sizing: border-box;
padding: 20px;
width: 60%;
text-align: justify;
background-clip: border-box;
background: #fff;
-webkit-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
-moz-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}
.block-1 span {
color: #124191;
font-weight: bold;
}
.block-2 {
float: right;
overflow: hidden;
box-sizing: border-box;
width: 35%;
padding: 20px;
background-clip: border-box;
background: #fff;
-webkit-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
-moz-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
text-align: justify;
}
.block-100pc {
overflow: hidden;
box-sizing: border-box;
width: 100%;
padding: 20px;
background-clip: border-box;
background: #fff;
-webkit-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
-moz-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
text-align: justify;
clear: both;
background: red;
}
That is because of the floated elements. They do not "count into" the height of their container, unless they are cleared.
There are several clearing techniques you can use, for example setting overflow: hidden on the container:
.wrapper {
overflow: hidden;
}
jsFiddle Demo
.block-1 {
margin-top: 200px;
}
or
.top {
margin-bottom: 200px;
}
either one should work
The margin-top doesn't work in your case because the two block that are above it are floated. the margin-top property applies to the top of the parent.
In order to see a top margin, you will have to apply a margin-top= height of the hieghest floated div + the margin you want.
You have some broken code in your fiddle, I've updated it with some fixes. Another thing is that you are not taking into account your padding when you've set the width of block-1 and block-2, therefor they are overlapping. Fix your block-1 width down to a lower percent to allow for the padding on the blocks. Here is an updated fiddle: http://jsfiddle.net/pB5kq/5/
<div class="wrapper top">
<div class="block-1">
<p><span>ddfsfsdsfds</span></p>
<p>fdsfsdfs.</p>
<p>dfsdfdsfds.</p>
</div>
<div class="block-2">
<img src="images/136147555-e1329752650296-287x300.jpg" alt="136147555-e1329752650296-287x300" width="287" height="300"></img>
</div>
<div class="wrapper top">
<div class="block-100pc">
block-100pc
</div>
</div>
Along with the other answers regarding floating divs and clearing, this should help.