I'm trying to place submenu right below its's choosing option like this but when I set left and right attributes on 0
.sidebar_wrapper
{
position:absolute;
background-color:lightgray;
left:0;
right:0;
}
it has whole site's width. When I set them on auto it looks like this.
How do I place my submenu exactly below this div or, what would look even cooler, on it's right?
Code (whole JSFiddle in comments):
HTML:
<div id="sidebar">
<div class="sidebar_option">Strona główna</div>
<div class="sidebar_option">Galeria</div>
<div class="sidebar_option">Reżyserzy
<div class="sidebar_wrapper">
<div class="submenu" style="margin-top:10px">Quentin Tarantino</div>
<div class="submenu">Bracia Coen</div>
<div class="submenu">Wes Anderson</div>
</div>
</div>
<div class="sidebar_option">Ulubione filmy</div>
<div class="sidebar_option">Seriale</div>
<div class="sidebar_option">Kontakt</div>
</div>
CSS:
.submenu
{
text-align:center;
border-bottom:dotted 2px black;
padding-top:10px;
padding-bottom:10px;
display:none;
font-size:13px;
}
.sidebar_wrapper
{
position:absolute;
background-color:lightgray;
left:auto;
right:auto;
}
.sidebar_option:hover div
{
display:block;
}
.sidebar_option:hover
{
background-color:lightgray;
cursor:pointer;
}
.sidebar_option
{
text-align:center;
margin:10px;
padding:10px;
border-bottom:dotted 2px black;
}
I think the key is you need to set the position of the sidebar_option to relative so that the submenu_wrapper will be position in relation to the sidebar instead of the window. Then some value for left and right for the submenu. It can be anything, but if you want it centered they need to be the same.
.sidebar_option {
position: relative;
}
.sidebar_wrapper {
position: absolute;
background-color:lightgray;
left: 5%;
right: 5%;
z-index: 2;
}
Here's the updated jfiddle: https://jsfiddle.net/8d3p50hy/13/
Related
I have a div containing position absolute and float left and right. Now i want to place an image below the first div.
Now the problem is the image overlapping below the first div. I want the image to display below first div without overlapping.
https://jsfiddle.net/jv7afgn1/
<div class="top">
<div class="left" align="center">
<p>Sell</p>
<p>Download App</p>
<p>24x7 Customer Care</p>
</div>
<div class="right" align="center">
<p>Track Order</p>
<p>Help</p>
<p>About</p>
<p>Contact</p>
</div>
</div>
<div class="clearfix"></div>
<div class="logo_menu">
<p><img src="assets/images/logo.png" alt="" title="" /></p>
</div>
.clearfix {
clear:both;
}
/* Top */
.top {
width:100%;
height:auto;
background:#E9E9E9;
position:absolute;
padding:10px;
}
.top .left {
float:left;
}
.top .left p {
display:inline-block;
margin:0 10px 0 10px;
font-size:12px;
}
.top .left p a {
text-decoration:none;
color:#B5B5B5;
}
.top .left p a:hover {
text-decoration:underline;
color:#FD6123;
}
.top .right {
float:right;
}
.top .right p {
display:inline-block;
margin:0 10px 0 10px;
font-size:12px;
}
.top .right p a {
text-decoration:none;
color:#B5B5B5;
}
.top .right p a:hover {
text-decoration:underline;
color:#FD6123;
}
/* Menu and Logo */
.logo_menu {
width:100%;
height:auto;
}
Do you even have to absolute position the logo?
An absolute positioned element is on "it's own layer" of the homepage,
so trying to clear floats wont work.
My clearfix usually looks like this:
.clearfix:after {
clear:both;
display:block;
content: "";
}
Fiddle: https://jsfiddle.net/jv7afgn1/4/
Add padding top value equal to height of your navigation bar fixed at the top
Demo
.logo_menu {
width:100%;
height:auto;
padding-top:30px;
}
I'm trying to make a title bar with a nice centered title and a toolbar next to it. The issue I'm having is that as the toolbar grows, the title move further and further off center (and is never really centered to begin with). I've been monkeying with this for a while, tried a few searches, but can't seem to find an answer. Can someone with a bit more css experience throw me a bone please?
HTML
<div>
<span>
Section Title
</span>
<div class="toolbar">
<button>Add</button>
<button>Remove</button>
</div>
CSS
div { background:red;overflow:hidden; text-align: center; }
span a {
background:#222;
color:#fff;
display:inline-block;
margin:10px 10px 0 0;
padding:5px 10px
}
.toolbar {
float: right;
}
Here's a fiddle:
http://jsfiddle.net/scottvossen/cePe3/124/
You're going to want to use position: relative on the outer div and position: absolute on the inner div. You can learn more about positioning divs here.
FIDDLE. I also centered the text vertically.
HTML
<div id="background">
<div id="centeroutline">
<div id="centertext">
Section Title
</div>
</div>
<div class="toolbar">
<div id="buttons">
<button>Add</button>
<button>Remove</button>
</div>
</div>
</div>
CSS
#background {
position:relative;
background:red;
overflow:hidden;
text-align: center;
height:26px;
width:auto;
}
#buttons{
position:relative;
}
#centeroutline {
color:#fff;
display: table;
width:100%;
}
#centertext{
margin:10px 10px 0 0;
padding:5px 10px;
display: table-cell;
vertical-align: middle;
width:100%;
text-align:center;
}
.toolbar {
right:0;
top:0;
position:absolute;
}
You can add position: relative to the containing div. Then absolute position the toolbar in the corner.
div{
position: relative
}
.toolbar{
position: absolute;
top: 0;
right: 0;
}
FIDDLE
Is there a way to hide the overflow of a div "at the top" rather than "at the bottom"?
This jsFiddle illustrates what I mean. The enclosing div has overflow-y:hidden, but this hides the lower part of its content. I want to hide the upper part of it.
The obligatory source code (verbatim from the jsFiddle):
*{
-webkit-box-sizing:border-box;
-moz-box-sizing:border-box;
box-sizing:border-box;
}
*{margin:0;padding:0;border:0;}
#centered{
margin:20px auto 0;
overflow-y:hidden;
height:150px;
outline:5px solid green;
}
#centered,
#top,
#bottom{width:150px;}
#top {height:120px;background-color:red;}
#bottom{height:150px;background-color:#555;}
#top,#bottom{
color:white;
text-align:center;
padding:0 10px;
}
#top{padding-top:50px;}
#bottom{padding-top:60px;}
<div id="centered">
<div id="top">
this div should be "overflowed away"
<em>at the top!</em>
</div>
<div id="bottom">
this content should show
</div>
</div>
See this FIDDLE, you need to wrap the content in an absolute positioned DIV with bottom set to 0, whilst the parent container is given a position of relative
HTML
<div id="centered">
<div id='content'>
<div id="top">this div should be "overflowed away" <em>at the top!</em>
</div>
<div id="bottom">this content should show</div>
</div>
</div>
CSS
*{
box-sizing:border-box;
margin:0;
padding:0;
}
#centered {
margin:20px auto;
overflow-y:hidden;
height:150px;
border:5px solid green;
width:150px;
position:relative;
}
#content {
bottom:0px;
position:absolute;
}
#top {
min-height:120px;
background-color:red;
padding-top:50px;
}
#bottom {
background-color:#555;
padding:60px 10px 0 0;
}
#top, #bottom {
color:white;
text-align:center;
}
I have a problem with CSS
<div id="all-letter2" style="margin-left:40px; margin-right:57px;">
<div class="inhalt" style="font-size:17px;">
<div class="line1" style="position: absolute; margin-left:-80px; width:30px; color:gray; height:10px; font-size:22px; font-weight:470; margin-top:-590px;z-index:10;">_
</div>
</div>
</div>
How can I set class="line1"> on class="inhalt"? z-index?
If you are trying to mimic http://cdn.onextrapixel.com/wp-content/uploads/2009/05/zindex.jpg with the nested elements you have in your example, then you need to set the parent container to have a position relative. That ensures that the child elements will use it's top and left edges for determining their positions. This list a part article does an excellent job about describing why.
So the html is:
<div id="all-letter2">
<div class="inhalt">
<div class='line1'></div>
</div>
</div>
And your css would be:
#all-letter2
{
height:30px;
width:30px;
background:orange;
position:relative;
top:10px;
left:10px;
}
.inhalt
{
height:30px;
width:30px;
background:blue;
position:absolute;
top: 10px;
left:10px;
}
.line1
{
height:30px;
width:30px;
background:green;
position:absolute;
top:10px;
left:10px;
}
A visual example is here in this fiddle: http://jsfiddle.net/7CL54/
If I understand correctly, you want to place .line1 inside .inhalt?
If so, position .inhalt relatively, than you can absolute position (which you already have) the .line1 div.
<div class="inhalt" style="font-size:17px; position: relative;">
If your trying to set it on top of it just use like you said in the title:
CSS
.inhalt {
position: relative;
z-index: 1000;
}
.line1 {
position: relative;
z-index: 2000;
}
HTML
<div class="inhalt" style="font-size:17px;"></div>
<div class="line1" style="font-size:17px;">
If you want .line1 under inhalt then you can position them absolute to all-letter2.
CSS
#all-letter2 {
position:relative;
margin: 0 57px 0 40px;
}
.inhalt {
position:absolute;
top:0;
left:0;
z-index:2;
}
.line {
position:absolute;
top:0;
left:0;
z-index:1;
}
I've tried numerous of things to fix this. I cannot seem to get the nested div inside the parent div without having to use margin. I'm trying to get it in the regular way which is position:relative on parent and position:absolute on nested. It's not working though, anybody know why?
HTML
<div class="header">
<div class="logo">
<img src="/images/logo.png" width="96" height="82">
</div>
<div id="nav">
Portfolio
About
Contact
</div>
<div id="headerPro">
</div>
</div>
CSS
.header {
position:relative;
background-color: #2C2E31;
border-bottom: #242426 2px solid;
height: 182px;
}
.logo {
text-align: center;
padding-top: 35px;
}
#nav {
position:absolute;
bottom: 0;
width: 100%;
text-align:center;
text-decoration:none;
font-size:20px;
font-family:raleway-regular;
}
#nav a {
border-bottom:#FFFFFF 2px solid;
color:#FFFFFF;
text-decoration:none;
margin-left: 8px;
margin-right:8px;
}
#headerPro {
position:absolute;
float:right;
width:100px;
height:100px;
background-color:red;
}
It's hard to tell what exactly you want it to look like, but maybe I got you right:
I revised your HTML code to use ul for the nav which is best practice:
<div class="header">
<div class="logo">
<img src="/images/logo.png" alt="logo"/>
</div>
<ul id="nav">
<li>Portfolio</li>
<li>About</li>
<li>Contact</li>
</ul>
<div id="headerPro">
</div>
</div>
With that your css code could look like that:
.logo > img {
display: inline-block;
width: 96px;
height: 82px;
}
#nav {
position:absolute;
list-style-type: none;
bottom: 0;
width: 100%;
text-align:center;
text-decoration:none;
font-size:20px;
font-family:raleway-regular;
}
#nav > li {
display: inline;
}
#headerPro {
position:absolute;
top: 35px; /* assuming you want this to line up with the logo */
right: 0;
width:100px;
height:100px;
background-color:red;
}
Here is a demo.
See this fiddle
Example
I have made two changes added a float:left to the logo css:
.logo {
float:left;
}
and removed the position:absolute from the header pro css
Your div is flowing outside the header block because of the logo div, if you make that float left (as I have done in the fiddle) the Red Div will move up.
It would help if you could explain exactly where you want the #HeaderPro div..
Apparently the browser positions your div#headerPro just below the previous(sibling) div. If you want it to be part of the parent div, add top:2% to position the red div in the top right corner of the black div.
#headerPro {
position:absolute;
float:right;
width:100px;
height:100px;
background-color:red;
top: 1%;
}