When you uncomment the unordered list tag the second container div falls a bit down. If you actually could explain me why this is happening and told me how to remove this behavior I would be thankful.
html,
body {
margin: 0;
padding: 0;
}
.container {
position: relative;
margin-right: 50px;
margin-left: 50px;
margin-top: 100px;
display: inline-block;
width: 300px;
height: 300px;
background-color: rgb(255, 255, 255);
box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.2), 0 5px 5px 0 rgba(0, 0, 0, 0.24);
text-align: center;
color: rgb(38, 48, 90);
}
ul {
list-style-position: inside;
display: block;
}
<div class="container">
<h1> Depr </h1>
<!--<ul>
<li>Derping</li>
<li>Derping</li>
</ul>-->
</div>
<div class="container">
<h1> Derpina</h1>
</div>
The main reason behind why this occurs is, when you make any element to be inline-block, it aligns to baseline by default. So, when the heights of all elements are not same, it gets scrambled and aligned to their baseline. This is the main problem with all the inline-block and we should correct it by giving the right vertical alignment. To do that, please follow the below snippet:
I found your issue to be vertical alignment. Just give:
.container {
vertical-align: middle; /* This */
position: relative;
margin-right: 50px;
margin-left: 50px;
margin-top: 100px;
display: inline-block;
width: 300px;
height: 300px;
background-color: rgb(255,255,255);
box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.2), 0 5px 5px 0 rgba(0, 0, 0,
0.24);
text-align: center;
color: rgb(38, 48, 90);
}
Preview
Without the <ul> and with it:
JSBin: http://jsbin.com/zalagixovu/edit?output
Related
So I guess the main question here is can I keep everything under my header nav bar that's in a fixed position but if I need to scroll it goes under my header? Here is a fiddle of me just setting the margin-top of the hr tag but after trying it on different screen sizes it just doesn't work and over laps on smaller screens.
https://jsfiddle.net/RVKuzmik/se0etqew/3/
Code here
html,
body {
padding: 0;
margin: 0 auto;
text-align: center;
background-color: #ffffff;
width: 100%;
}
header {
top:0;
position: fixed;
width: 100%;
padding-bottom: 1%;
padding-top: 1%;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
z-index: 1;
}
hr {
margin-top: 10%;
}
<header>
<nav>
<ul>
<li>Campus</li>
</ul>
</nav>
</header>
<hr>
try to add position fixed to your form this will work
You are setting a percentage value as the margin-top on the hr element. The thing with percentage values is that it changes as the viewport changes, so on a smaller device the 10% value may not be the same as it is on a large computer screen.
Since your navbar is going to stay the same height (with fixed elements on top it is always a good idea to know beforehand what's the maximum height the element will be at any given point).
Instead of giving hr tag a margin-top value, I would suggest you setting a margin/padding-top value on the top container of the elements that are in a scroll-able view and not fixed.
By default it will be the body element where your elements positioned normally and the fixed header / navbar is, so let's do it on it.
html,
body {
padding: 0;
margin: 0 auto;
text-align: center;
background-color: #ffffff;
width: 100%;
}
body {
/* The height of the header is around 70px (give or take) at most of the screens, since you are using percentage value for the padding-top and bottom of it */
margin-top: 70px;
}
header {
top:0;
position: fixed;
width: 100%;
padding-bottom: 1%;
padding-top: 1%;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
z-index: 1;
}
https://jsfiddle.net/00w0cng6/
Or even better, to make sure things look right on every device, you either use responsive media queries to set different values for certain screen sizes or just one fixed height for your fixed element.
html,
body {
padding: 0;
margin: 0 auto;
text-align: center;
background-color: #ffffff;
width: 100%;
}
body {
/* 70px because that's the max our fixed element is going to be */
margin-top: 70px;
}
header {
top:0;
position: fixed;
width: 100%;
/* Padding top, bottom and the height of the header sums up to 70px */
padding-top: 10px;
padding-bottom: 10px;
height: 50px;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
z-index: 1;
}
https://jsfiddle.net/RVKuzmik/se0etqew/3/
**CSS**
html,
body {
padding: 0;
margin: 0 auto;
text-align: center;
background-color: #ffffff;
width: 100%;
padding-top: 60px;
}
header {
top:0;
position: fixed;
width: 100%;
padding-bottom: 20px;
padding-top: 20px;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
z-index: 1;
height:80px;
}
**HTML**
<header>
<nav>
<ul>
<li>TEST</li>
</ul>
</nav>
</header>
<hr>
Just give the header a background:color:white;position:sticky And it will work fine..
What is happening is that the header has a background color which is transparent and position is fixed....This will work fine..
You can make use of position: fixed
for example:
Here's the code
Normally the elements of an HTML markup appear in the order they are written in the markup file, and the inline elements appear from left to right.
But I want the children of a certain div (only, NOT all the elements of the entire page) to appear from right to left.
In case you wonder why it is needed, I want to do this to solve the following problem:
PROBLEM:
JSFiddle here.
.wrapper {
height: 100%;
width: 826px;
margin: 50px auto;
display: table;
background-color: #003b80;
}
.cell {
display: table-cell;
vertical-align: top;
}
.left-cell {
width: 50%;
background-color: chocolate;
}
.right-cell {
background-color: darkslategrey
}
.step-container {
max-height: 200px;
font-size: 0;
}
.right-cell .step-container {
margin-top: 125px;
}
.content-box {
display: inline-block;
width: 350px;
height: 200px;
/*border: 5px solid blue;*/
font-size: 0;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.69);
-moz-box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.69);
-webkit-box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.69);
background-color: dodgerblue
}
.right-cell .content-box {
background-color: darkturquoise
}
.middle-cell {
height: 100%;
background-color: white;
width: 1.5px;
font-size: 0;
box-shadow: 0px 0px 10px black;
-moz-box-shadow: 0px 0px 10px black;
-webkit-box-shadow: 0px 0px 10px black;
}
.number-outer-container {
display: inline-block;
position: absolute;
}
.left-cell .number-outer-container {
/*margin-left:39px;*/
}
.number-inner-container {
height: 200px;
display: flex;
flex-direction: column;
justify-content: center;
}
.number-banner {
width: 50px;
height: 50px;
background-color: crimson;
-moz-border-radius: 25px;
-webkit-border-radius: 25px;
border-radius: 25px;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.5);
-moz-box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.5);
-webkit-box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.5);
}
.notch-outer-container {
display: inline-block;
}
.left-cell .notch-outer-container {
margin-right: 24px;
}
.right-cell .notch-outer-container {
margin-left: 10px;
}
.notch-inner-container {
height: 200px;
display: flex;
flex-direction: column;
justify-content: center;
}
.notch {
width: 0;
height: 0;
border-top: 15px solid transparent;
border-bottom: 15px solid transparent;
}
.left-face-notch {
border-right: 15px solid #520f23;
}
.right-face-notch {
border-left: 15px solid #571780;
}
<div class="wrapper">
<div class="cell left-cell" align="left">
<div class="step-container">
<div class="content-box"></div>
<div class="notch-outer-container">
<div class="notch-inner-container">
<div class="right-face-notch notch"></div>
</div>
</div>
<div class="number-outer-container">
<div class="number-inner-container">
<div class="number-banner"></div>
</div>
</div>
</div>
</div>
<div class="cell middle-cell"></div>
<div class="cell right-cell" align="right">
<div class="step-container">
<div class="number-outer-container">
<div class="number-inner-container">
<div class="number-banner"></div>
</div>
</div>
<div class="notch-outer-container">
<div class="notch-inner-container">
<div class="left-face-notch notch"></div>
</div>
</div>
<div class="content-box"></div>
</div>
</div>
</div>
In this SSCCE, inside .left-cell .step-container, I have three elements appearing on the same line: .content-box, .notch-outer-container, and .number-outer-container; and to make the .notch appear to be overlapping the right-cell by 50% of its width, I gave .number-outer-container a position:absolute; and .notch-outer-container a margin-right which pushes the number-outer-container to right side to an extent that it appears to be overlapping the (.middle-cell and) right-cell by 50% of it's width.
The problem is that in the .right-cell, this strategy is NOT working. First the .number-right-container appears and still it is absolute, I can not give it a left property with value relative to its parent (otherwise I would try a left:-25px to make it appear 25px behind the left edge of its parent, because it has width:50px;). Then the .notch is hidden below it...
So I am thinking about finding a way through which I can get the elements render from RTL (Right To Left) rather than LTR only inside .right-cell on the page. So that I can follow the same strategy I have used for the .left-cell, in the .right-cell.
There's numerous ways to achieve what you want using either flexing, floats or other options, but I'd say one of the easiest ways, if the rest of the layout works as you want it to, is to use the direction attribute.
div {
direction: rtl;
}
div div {
display: inline-block;
direction: ltr;
}
<div>
<div>first</div>
<div>second</div>
<div>last</div>
</div>
I'm making a title bar, links on the left, center, and the right. Each separated by divs.
Floating left is no problem, centering the second div is no problem. But when I try to float the last div to the right it is clearing the other divs and is not inside my header. Why is this? It has to be something simple I am missing? Thank you very much
http://jsfiddle.net/GX9xn/
HTML
<div class="header-fixed">
<div class="header-container">
<div class="nav-float-left">
<div id="search">
<span>search</span>
</div>
</div>
<div class="nav-center">
title
</div>
<div class="nav-float-right">
<a>
<span>more</span>
</a>
<div>
</div>
</div>
CSS
.header-fixed {
height:56px;
border-top: 1px solid #222;
width: 100%;
background: green;
position: fixed;
}
.header-container {
width: 700px;
margin: 0 auto;
height: 56px;
}
.nav-float-left {
float:left;
height: 56px;
color: rgba(255, 255, 255, .55);
font-family:'Museo Sans W01 300',san-serif;
font-size: 13px;
text-shadow: 0px 1px 1px rgba(0, 0, 0, .95);
filter: dropshadow(color= rgba(0, 0, 0, .95), offx=0, offy=1);
}
.nav-center {
letter-spacing: 0.05em;
margin: 0 auto;
height: 43px;
width: 100px;
padding-top: 13px;
background: black;
color: #d4d2d2;
font-size: 29px;
font-family: “Lucida Grande”, sans-serif;
text-align: center;
box-shadow: inset 0px 0px 3px 0px rgba(0, 0, 0, .57);
-webkit-box-shadow:inset 0px 0px 3px 0px rgba(0, 0, 0, .57);
-o-box-shadow: inset 0px 0px 3px 0px rgba(0, 0, 0, .57);
-moz-box-shadow: inset 0px 0px 3px 0px rgba(0, 0, 0, .57);
cursor: pointer;
}
.nav-center .ss-pika {
font-size: 17px;
margin-left: 1px;
margin-right: 0px;
}
.nav-center a {
display:block;
}
.nav-float-right {
position:relative;
float:right;
height: 55px;
width: 205px;
}
The center div will be above the float right div because it is a block element and block elements are not placed inline.
A walk around is to add the float-right element first.
<div class="nav-float-left">
<div id="search">
<span>search</span>
</div>
</div>
<div class="nav-float-right">
<a><span>more</span></a>
<div>
<div class="nav-center">
title
</div>
If you use float you also need to set the display property in order to do as you want.
I changed your fiddle by adding display:inline-block.
As you may notice you need to set the dimensions width for your divs (height optional).
Here : Fiddle
You can use display:table; , display:table-cell; instead of floats to arrange elements in single line:
Fiddle
Try this
.nav-float-right {
position:relative;
float:right;
height: 55px;
width: 205px;
bottom: 57px;
left: 12px;
}
You can adjust the right div by set the bottom and left attributes.
Fiddel: http://jsfiddle.net/GX9xn/6/
Please try this FIDDLE
There is slight change in your CSS file
.nav-float-right {
position:absolute;
float:right;
height: 55px;
width: 205px;
right:0;
top:0;
background: #fff;
}
I have one article tag, inside a php code that generate articles from wordpress. They are not all the same height ofc, it depends on the content. They are organised in two columns by float.
If a article in the first line is not the same height as the other one in the same row, the second row is aligned to the bottom of the biger div. Now I want to align them without any spacing.
Here is some css:
#container {
width: 1000px;
margin: 0px auto;
}
article {
position: relative;
width: 435px;
margin: 10px 10px;
background-color: rgba(0, 0, 0, 0.5);
padding: 20px;
float: left;
}
Edit jsFiddle (now with content to demonstrate the problem): http://jsfiddle.net/4PMj5/6/
You can use even and odd chilren pseudo selection in your CSS.
article:nth-child(even) {
position: relative;
width: 435px;
margin: 10px 10px;
background-color: rgba(0, 0, 0, 0.5);
padding: 20px;
float: right;
}
article:nth-child(odd) {
position: relative;
width: 435px;
margin: 10px 10px;
background-color: rgba(0, 0, 0, 0.5);
padding: 20px;
float: left;
}
The result will be like: this updated fiddle.
This is demo: http://jsfiddle.net/KS4eS/
Please take a look at demo first.
I'd like To set their alignment the same.
Something like this. How can I?
center
------------------------------------------------------
A2345343
B435234
C4364353
D3426432632
E46324362
F235235
GGGGG
------------------------------------------------------
HTML
<div class='general'>
<div class='list'>
<div class="top_page_function">A2345343</div>
<div class="top_page_function">B435234</div>
<div class="top_page_function">C4364353</div>
<div class="top_page_function">D3426432632</div>
<div class="top_page_function">E46324362</div>
<div class="top_page_function">F235235</div>
<div class="top_page_function">GGGGG</div>
</div>
</div>
CSS
.general {
background-color: rgb(255, 255, 255);
border-radius: 8px 8px 8px 8px;
box-shadow: 0px 0px 4px rgba(0, 0, 0, 0.3);
margin-bottom: 30px;
text-align: center;
padding: 10px;
}
.list{
width: 400px;
min-width: 250px;
margin-bottom: 20px;
}
This will get what you want:
.general {
background-color: rgb(255, 255, 255);
border-radius: 8px 8px 8px 8px;
box-shadow: 0px 0px 4px rgba(0, 0, 0, 0.3);
margin-bottom: 30px;
padding: 10px;
text-align:center;
}
.list{
margin-bottom: 20px;
text-align: left;
margin: 0 auto;
display: inline-block;
}
It will also work with any width. See here: http://jsfiddle.net/KS4eS/8/
Another trick is to add a wrap to .List div.
HTML:
<div class='general'>
<div class='list_wrap'>
<div class='list'>
<div class="top_page_function">A2345343</div>
<div class="top_page_function">B435234</div>
<div class="top_page_function">C4364353</div>
<div class="top_page_function">D3426432632</div>
<div class="top_page_function">E46324362</div>
<div class="top_page_function">F235235</div>
<div class="top_page_function">GGGGG</div>
</div>
</div>
</div>
CSS
.general {
background-color: rgb(255, 255, 255);
border-radius: 8px 8px 8px 8px;
box-shadow: 0px 0px 4px rgba(0, 0, 0, 0.3);
margin-bottom: 30px;
text-align: center;
padding: 10px;
}
.list_wrap{
margin:0 auto;
width: 250px;
}
.list{
width: 100%;
text-align:left;
margin-bottom: 20px;
}
JSFiddle
You can align your column like this:
.list div {
text-align:left;
margin-left:200px;
}
Maybe setting a container around the top_page_function class divs and setting its position to absolute with left as 50%,will do.
Other solutions work too, prefer them, but just because i have made the fiddle, I'm posting it.
And yes, you have to set the height of list clss on your own too.That's one con of this method.
JSFiddle