CSS drop down menu is not working as expected - css

when I make the div's(that contains the drop down menu)positioning to relative and the drop down menu div's positioning to absolute,it shows me only the last item on the drop down menu.if I set drop down menu container div to relative and leave the drop down menu div positioning,then it works.But that affects the rest of the page.So,how to set the positioning that would make the drop down works without affecting any other parts of the page.
HTML
<div id="top_head">
My Online Shop
<div id="nav">
<div class="test">Home</div>
<div class="test" id="product">Products
<div class="test1">shirt</div>
<div class="test1">Pant</div>
<div class="test1">inner</div>
<div class="test1">cap</div>
</div>
<div class="test">About</div>
<div class="test">contact Us</div>
</div>
</div>
CSS
body{
color:green;
}
#top_head{
width:100%;
height:100px;
font:48px Arial green;
border:1px dotted red;
}
#nav{
background-color:gray;
width:57%;
border-radius:5px;
font:28px Arial orange;
margin:0px -49px 5px 15px;
}
#nav a{
color:red;
text-decoration:none;
margin:0px 50px;
}
.test{
float:left;
}
.test:hover{
background-color:orange;
}
#product{
position:relative;
}
.test1{
position:absolute;
border:1px solid red;
visibility:hidden;
}
#product:hover .test1{
visibility:visible;
background-color:yellow;
}
I've tried with display property too. Same results.
If you have any idea where the problem lies, please help.

It looks like the issue here is that you're using position:absolute on all of the sub menu divs. This is essentially making them lay on top of each other (leaving the last one on top).
One solution for this is to wrap all of these elements in a container div and make that the thing that is hidden or shown:
Working Fiddle Demo
Your sub-menu becomes:
<div class="test1">
<div>shirt</div>
<div>Pant</div>
<div>inner</div>
<div>cap</div>
</div>
And the CSS is altered slightly:
.test1{
display:none;
}
.test1 div{
border:1px solid red;
}
#product:hover .test1{
position:absolute;
display: block;
background-color:yellow;
}

Related

vertical align middle not working

I want the text in front of the image to be in the middle of it!
My problem is the vertical align middle is not working...
what is wrong?
<div class="comments">
<div class="pull-left lh-fix">
<img class=foto src="/$foto" class="imgborder">
</div>
<div class="comment-text pull-left">
<span class="pull-left color strong">anna:</span> dododod
</div>
</div>
.pull-left { float: left; }
.lh-fix { line-height: 0 !important; }
.comments {
position:relative;
display:block;
overflow:auto;
padding-left:15px;
padding-top:8px;
padding-bottom:8px;
border:1px solid #000;
}
.comment-text {
margin-left: 8px;
color: #333;
vertical-align:middle; //not working?
line-height:normal;
width: 85%;
text-align:left;
}
.foto{
width:50px;
height:50px;
float:left;
}
https://jsfiddle.net/a0bhv4n1/
Vertical-align works on inline elements. You are applying it to the class .comment-text which is for a div element. A div is a block style element which of course means that it will take up the entire space that it is allowed to, thus you cannot center something that already takes up the whole space. Inline elements only take up the space they need to based on the content in them and you can simply add display:inline-block to .comment-text to allow vertical-align:middle to work. More information can be found at MDN's article on vertical-align

Bootstrap button not displaying inline with container element

I'm creating a simple banner for a website using Bootstrap CSS and after centering text within the banner, I would like a button to be displayed inline with it. However, after I create the button, it does not display inline with the centered text within the button.
HTML:
<div id="idea_banner">
<div class="container">
<b>Got an idea? Tell us about it!</b>
Give us an idea
</div>
</div>
CSS:
#idea_banner {
background: #4B91FB;
overflow:hidden;
width:100%;
height:90px;
}
.container {
position:relative;
}
.container b {
display:block;
text-align:center;
margin-right:100px;
margin-top:35px;
color:#FFF;
font-size:22px;
white-space:nowrap;
}
.container a {
display:inline-block;
float:left;
}
I'm not really sure if this is a Bootstrap issue or not. Any help is greatly appreciated!
It was happening because you had displayed b as block in your CSS. Change it to inline to get it into a single line.
Also, remove float: left for .container a and add text-align: center for .container.
By the way, <b> tag is not recommended. If you need an element to wrap the text, use <p> instead.
Working Code Snippet:
#idea_banner {
background: #4B91FB;
overflow:hidden;
width:100%;
height:90px;
}
.container {
position:relative;
text-align: center;
}
.container b {
display: inline;
text-align:center;
margin-right:10px;
margin-top:35px;
color:#FFF;
font-size:22px;
white-space:nowrap;
}
.container a {
display:inline;
/*float:left;*/
}
<link rel="stylesheet" type="text/css" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
<div id="idea_banner">
<div class="container">
<b>Got an idea? Tell us about it!</b>
Give us an idea
</div>
</div>

CSS float issues across several browsers

I have the following CSS setup for use on two different pages;
#content{
width:960px;
margin-top:0px;
height:auto;
font-family:arial;
font-size:1.em;
background-color:#f2f2f2;
}
#left-div {
width:600px;
padding-top:20px;
text-align:center;
line-height:.5em;
display:inline-block;
float:left;
}
#right-div {
width:300px;
margin-top:40px;
margin-right:20px;
display:inline-block;
text-align:center;
float:right;
background-color:#e0e0e0;
}
#isa-left {
width:440px;
margin-top:40px;
margin-left:30px;
margin-right:10px;
display:inline-block;
text-align:justify;
float:left;
}
#isa-right {
width:440px;
margin-top:40px;
margin-left:10px;
margin-right:30px;
display:inline-block;
text-align:center;
float:right;
}
On the page where I use left-div and right div like this;
<div id="content">
<div id="left-div"> Content </div>
<div id="right-div"> Content </div>
</div>
here is what happens. In FF, IE, Safari, and Chrome it looks just I expect with the two divs next to each other with a background color of #f2f2f2 from the content div.
On the second page where I use the isa-left and isa-right with the same setup as above what happens is that the inner divs are still showing where I expect them but now the background color from the content div is not showing.
After finding a post on here with the same problem I added this line overflow:auto; to the content div.
Now both pages in FF the content appears outside of the content div, 960 pixels to the right, with the background color showing. In IE, Safari, and Chrome both pages appear perfectly.
My question is what is causing the two inner divs to escape the content div in FF once I added overflow:auto;? Or is there a way to fix it so that the background color shows through on the second page without using overflow:auto;?
Any suggestion is appreciated.
Try this. I think it might be the solution to your problem.
http://jsfiddle.net/6dBdx/
-Code Reference -
CSS:
.wrapper {
width:400px;
margin-top:0px;
height:auto;
font-family:arial;
font-size:1.em;
background-color:#f2f2f2;
margin-bottom:15px;
}
.wrapper > div.box {
padding-top:20px;
text-align:center;
line-height:.5em;
border:thin solid #999;
/* Adding this for example purposes */
height:150px;
width:150px;
}
.pull-right {
float:right;
}
.pull-left {
float:left;
}
.clear-fix {
clear:both;
}
HTML
<label>Float Left Only</label>
<div class="wrapper">
<div class="pull-left box">One</div>
<div class="pull-left box">Two</div>
<div class="clear-fix"></div>
</div>
<label>Float Left & Right</label>
<div class="wrapper">
<div class="pull-left box">One</div>
<div class="pull-right box">Two</div>
<div class="clear-fix"></div>
</div>
Quick notes, don't forget to add a clear div after a float, so that elements show up correctly after floating an element. Also, if you want an element to line up next to each other, try using float:left as a rule of thumb, unless you want the elements to line up on the right in which case... float:right

How to keep divs from changing position

I am trying to create a sort of a window, formed by multiple divs. I'm basically putting div after div in my cshtml page, and trying to set their positions in the .css files.
After a considerable effort, I managed to set the divs in their beautiful positions. But as soon as I start to put text, or dom element or whatever inside one of those divs, it changes its position, and pushes other divs, creates a mess.
I somehow managed to keep some by using float, but it is really difficult. Isn't there an easy way to manage the inside elements of a div? Why does the inside elements cause the container div to travel to other places?
Here's the .html and .css code. The divs are empty and positioned correctly. You can simply write "qwe" inside div id="fiyat"> for example and see what I'm talking about.
.html code:
<div id="tablodetay">
<div id="secimler">
</div>
<div id="parcacerceve">
</div>
<div id="resim">
</div>
<div id="ebatsecimvefiyat">
<div id="ebatsecim">
</div>
<div id="fiyat">
</div>
</div>
<div id="urunozellik">
</div>
</div>
.css code:
div#tablodetay div#secimler
{
border:1px solid #000000;
margin:2px;
display:block;
width:706px;
height:100px;
display:block;
}
div#tablodetay div#parcacerceve
{
border:1px solid #000000;
margin:2px;
display:inline-block;
width:86px;
height:400px;
}
div#tablodetay div#resim
{
border:1px solid #000000;
margin:2px;
height:400px;
width:400px;
display:inline-block;
}
div#tablodetay div#ebatsecimvefiyat
{
margin:2px;
height:402px;
width:200px;
display:inline-block;
}
div#tablodetay div#ebatsecim
{
border:1px solid #000000;
height:248px;
width:200px;
margin-bottom:2px;
}
div#tablodetay div#ebatsecim form input
{
float:left;
border:1px solid #000000;
}
div#tablodetay div#fiyat
{
border:1px solid #000000;
height:148px;
width:200px;
}
div#tablodetay div#urunozellik
{
border:1px solid #000000;
height:120px;
width:706px;
margin-top:-2px;
margin-left:2px;
}
You need to define css attributes for each div. To prevent it from changing size or position you need
div ... {
position:absolute;
left: 50px;
top:50px;
width:100px;
height:50%;
}
position:absolute; ignores all other divs and puts your div on the spot you define.
width and height are overruled if the overflow isnt set to none or scroll
The browser will use your width and height as starting point, not end point.
You could also try to set max-width and max-height.

Float right element pushes down next element in IE7

I'm trying to create a simple markup with header+content+footer+sidebar. The sidebar must float above the header and content element, and if it's taller than the content, it must push the footer down (like this: http://jsfiddle.net/gWLFN/7/).
The HTML:
<div id="wrapper">
<div id="sidebar">sidebar</div>
<div id="header">header</div>
<div id="content">content</div>
<div style="clear:both"></div>
<div id="footer">footer</div>
</div>
The CSS:
#wrapper { width:500px }
#header { width:500px; height:100px; background-color:red }
#content { width:500px; height:300px; background-color:green }
#footer { width:500px; height:100px; background-color:blue }
#sidebar {
float:right;
margin-top:50px;
width:100px;
height:500px;
background-color: yellow;
border:1px solid white;
}
The problem is that in IE7, the sidebar pushes down the other elements. I think it's because the total widths of header+sidebar is greater than wrapper width. I have found a lot of posts about float:right problem in IE7, but all of them are for widths that doesn't exceede the wrapper.
I have choosen float:right instead of absolute positioning because the position of the footer must depend on sidebar height (if someone knows how to do this with absolute positioning, perfect!).
I would appreciate any idea to solve this.
You are almost there, the order of the HTML structure is slightly muddled and you are forcing CSS widths rather than letting the browser work out the best fit.
You can remove the width values from the nested CSS classes (except #sidebar) as, by default, they take up any remaining width unless they have one specified. Then you just need to swap #header and #sidebar round in the HTML structure and you are pretty much sorted.
Please note, since we have swapped round #header and #sidebar, the margin-top within #sidebar has been changed.
CSS
#wrapper {
width:500px;
}
#header {
height:100px;
background-color:red;
}
#content {
height:300px;
background-color:green;
}
#footer {
height:100px;
background-color:blue;
}
#sidebar {
float:right;
margin-top: -50px; /*changed this to -50px */
width:100px;
height:500px;
background-color: yellow;
border:1px solid white;
}
HTML
<div id="wrapper">
<div id="header">header</div>
<div id="sidebar">sidebar</div>
<div id="content">content</div>
<div style="clear:both"></div>
<div id="footer">footer</div>
</div>
Working example: http://jsfiddle.net/gnx2z/

Resources