I'm trying to make a floating menu for one of my projects but I just can't get it to work.
My aim is to be able to have a horizontal menu floating in in the middle of the screen with a content div underneath. The content div (#preferencescontent), should never be wider than the content insider it, but no wider than 90% of the screen.
Now to the problem. It seems to work, sometimes, and for unknown reasons. Some tables shrink the div to the size of the menu while others expands a lot. I've added an example which for some reason expands the div way more than I expect it to.
Here's the code (codepen below):
<div class="lightbox" id="preferencesdiv">
<div id="preferencesholder">
<div class="sidemenu">
<div id="deviceoverviewbutton" class="menuitem">Device overview</div>
<div id="irulesbutton" class="menuitem">Defined iRules</div>
<div id="certificatebutton" class="menuitem">Certificates</div>
<div id="logsbutton" class="menuitem">Logs</div>
<div id="preferencesbutton" class="menuitem">Preferences</div>
<div id="helpbutton" class="menuitem">Help</div>
</div>
<div id="preferencescontent">
<div id="helpcontent">
<h2>Tips and tricks</h2>
<h3>Filtering for pool members being down</h3>
<p>This one is a bit of a hidden feature. In the Pool/Members column you can filter on "DOWN", "UP" and "DISABLED".</p>
<p>It's not perfect though since pools or members with any of these words in the name will also end up as results.</p>
</div>
</div>
</div>
https://codepen.io/anon/pen/vdOXWj
Grateful for any help. Thank you!
You can try removing float from your elements.
Also, you are adding positioning coordinates to elements which have not been given an explicit position, so you can remove them.
codepen
:root {
--alternatetablecolor: #f9f9f9;
--headerbackgroundcolor: #efefef;
--headerfontcolor: #333;
--bordercolor: #dddddd;
--defaultfontcolor: #222;
}
.lightbox {
position: fixed;
left: 0;
top: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.8);
text-align: center;
}
div#preferencesholder {
background: #fff;
display: inline-block;
text-align: left;
max-height: 75%;
max-width: 90%;
overflow: hidden;
padding: 0px;
border: 1px #000 solid;
-webkit-box-shadow: 7px 7px 5px 0px rgba(50, 50, 50, 0.75);
-moz-box-shadow: 7px 7px 5px 0px rgba(50, 50, 50, 0.75);
box-shadow: 7px 7px 5px 0px rgba(50, 50, 50, 0.75);
margin-top: 100px;
}
div#preferencescontent {
overflow-y: scroll;
max-height: 80%;
margin: 10px;
width: 100%;
}
div.sidemenu {
background-color: var(--headerbackgroundcolor);
width: 100%;
text-align: center;
}
div.sidemenu div.menuitem {
padding: 10px;
font-family: "Source Sans Pro", "Helvetica Neue", Helvetica, Arial, sans-serif;
display: inline-block;
margin: 0px -2px 0px -2px;
}
div.sidemenu div.menuitem img {
max-height: 30px;
vertical-align: middle;
}
div.menuitem:hover {
background-color: #d0d0d0;
cursor: pointer;
}
div#helpcontent {
max-width: 550px;
margin: 0 auto;
}
<div class="lightbox" id="preferencesdiv">
<div id="preferencesholder">
<div class="sidemenu">
<div id="deviceoverviewbutton" class="menuitem">Device overview</div>
<div id="irulesbutton" class="menuitem">Defined iRules</div>
<div id="certificatebutton" class="menuitem">Certificates</div>
<div id="logsbutton" class="menuitem">Logs</div>
<div id="preferencesbutton" class="menuitem">Preferences</div>
<div id="helpbutton" class="menuitem">Help</div>
</div>
<div id="preferencescontent">
<div id="helpcontent">
<div id="helpcontent">
<h2>Tips and tricks</h2>
<h3>Filtering for pool members being down</h3>
<p>This one is a bit of a hidden feature. In the Pool/Members column you can filter on "DOWN", "UP" and "DISABLED".</p>
<p>It's not perfect though since pools or members with any of these words in the name will also end up as results.</p>
</div>
</div>
</div>
</div>
If you remove "float:left;"
from "div.sidemenu"
Do you get your desired result? I'm not sure I understand what you are trying to achieve here.
Related
For some reason when I am using margin auto on each side to centre the element it's not working. I am assuming it's because I am using percentages and whatnot.
I tried to use calc() a bit more, but since the contents of the element I want to centre may vary over time, I want to try and make it always be centred.
I am doing this with the following: margin: 0px calc(50% - 554px / 2) 0px calc(50% - 554px / 2);
The current width of the element is 554px. So dividing it by 2 and removing that from 50% of the parent element will give it the margin on each side that it needs to be centred.
The problem is, the size may vary in the future so I want to replace 554 with an automatic width if that makes sense. So basically I want to haveit like this: margin: 0px calc(50% - width / 2) 0px calc(50% - width / 2); with width being the current element width of course. How can I do this?
I have tried looking this up online, sorry for wasting your time with may seem like a simple question.
div#game {
margin-top: 50px;
width: 80%;
display: inline-block;
float: left;
}
div#gameselect {
margin: 0px calc(50% - 554px / 2) 0px calc(50% - 554px / 2);
display: inline-block;
}
div.gameselect {
float: left;
display: inline-block;
position: relative;
}
p.lefttri {
width: 0;
height: 0;
border-bottom: 30px solid #FF4444;
border-left: 20px solid transparent;
float: left;
}
p#test {
font-family: title;
font-size: 30px;
line-height: 24px;
height: 24px;
color: white;
padding: 3px 11px 3px 0px;
background-color: #FF4444;
display: inline-block;
float: left;
}
p.righttri {
width: 0;
height: 0;
border-top: 30px solid #FF4444;
border-right: 20px solid transparent;
float: left;
z-index: 0;
position: relative;
}
<div id="gameselect">
<a href="https://www.google.com"><div class="gameselect">
<p class="lefttri"></p>
<p id="test">
ONE
</p>
<p class="righttri"></p>
</div></a>
<div class="gameselect gs2">
<p class="lefttri"></p>
<p id="test">
TWO
</p>
<p class="righttri"></p>
</div>
<div class="gameselect gs3">
<p class="lefttri"></p>
<p id="test">
THREE
</p>
<p class="righttri"></p>
</div>
</div>
If you're going to hard code 554px in when calculating those margins, you could just apply width: 554px to #gameselect, then your margin: auto; would work. But it isn't 554px on my side - that width is going to vary depending on the user's browser, and as you can see it doesn't truly center the element. http://codepen.io/anon/pen/wJpNLK Or who knows, maybe this will be centered on your side now.
But there are a number of other ways you could center this content. display: flex; justify-content: center on #gameselect does it fluidly without having to specify fixed widths like that, which you want to avoid.
div#game {
margin-top: 50px;
width: 80%;
display: inline-block;
float: left;
}
div#gameselect {
display: flex;
justify-content: center;
}
div.gameselect {
float: left;
display: inline-block;
position: relative;
}
p.lefttri {
width: 0;
height: 0;
border-bottom: 30px solid #FF4444;
border-left: 20px solid transparent;
float: left;
}
p#test {
font-family: title;
font-size: 30px;
line-height: 24px;
height: 24px;
color: white;
padding: 3px 11px 3px 0px;
background-color: #FF4444;
display: inline-block;
float: left;
}
p.righttri {
width: 0;
height: 0;
border-top: 30px solid #FF4444;
border-right: 20px solid transparent;
float: left;
z-index: 0;
position: relative;
}
<div id="gameselect">
<a href="https://www.google.com">
<div class="gameselect">
<p class="lefttri"></p>
<p id="test">
ONE
</p>
<p class="righttri"></p>
</div>
</a>
<div class="gameselect gs2">
<p class="lefttri"></p>
<p id="test">
TWO
</p>
<p class="righttri"></p>
</div>
<div class="gameselect gs3">
<p class="lefttri"></p>
<p id="test">
THREE
</p>
<p class="righttri"></p>
</div>
</div>
My sidepanel doesn't float right properly. It acts (for some reason) as if there's a top margin, it refuses to align next to the page title.
I'm also attempting to make it responsive using <aside>
It should be here:
My main content sits in a max-width:1050px, the rowSidepanel should make a column of width:60%, I assumed the sidebar would too make a column of width:27%; float:right; all within that pageArea.
I've inspected element and tried to force top:0; etc but it is still not behaving itself.
Does anyone know what I am doing wrong? .
HTML
<div id="pageArea">
<div class="colPad">
<div class="rowSidepanel">
<!-- InstanceBeginEditable name="main content" -->
<div class="breadCrumb"> Home <span style="font: Georgia;"> > </span> Repertoire</div>
<h1>Repertoire</h1>
<p class="introPara">Intro</p>
<p>Main content....</p>
<!-- InstanceEndEditable -->
</div>
<aside id="sidebar">
<div class="sidepanelArea"> Sidepanel </div>
</aside>
</div>
</div>
<div class="clearBoth"></div>
CSS
#pageArea {
max-width: 1050px;
margin: 0px auto 0px auto;
padding: 134px 0px 0px 0px;
display: block;
background-image:url("/images/common/centered-page-bg.jpg");
background-repeat: no-repeat;
background-position: 0% 12%;
min-height: 667px;
z-index: 1;
overflow: hidden;
position: relative;
}
.colPad {
padding: 0px 15px 0px 15px;
}
.rowSidepanel {
width: 60%;
}
aside {
float: right;
padding: 1%;
width: 27%;
margin: 0% 0px 20px 0px;
background-color:#000;
color: white;
opacity: 0.7;
filter: alpha(opacity=70); /* For IE8 and earlier */
}
#media all and (max-width : 799px) {
#sidebar {
width: 99%;
padding: 1% 0px 0px 0px;
margin: 0px 0px 0px 0px;
border-top: 3px solid #dc1b20;
background-color: #FFF;
color: black;
}
}
Your .rowSidepanel is displayed block and no matter of his width he is assigned to be across all screen. Just make him float: left;
.rowSidepanel {
width: 60%;
float: left;
}
Your #breadcrumb, repertoire header, and paragraph element are all block elements and are thus taking up the entire width of the browser (and pushing down your sidebar).
You should group those other elements into a container div of their own and flow that left. Apply background colors to both divs (the one floated left and the one floated right) to visualize what you're doing.
Try changing the div order, #rowSidepanel before #sidebar.
http://codebins.com/bin/4ldqosu
I am working for this website's responsiveness,
I want to stick the ratings image left to with a bit margin, when the width of the window is 335 it is working on left: 50% but when i increase the width of the window, it doesn't remain stick to what i want, Please suggest me, what should i do ??
Here is my code
<div id="filteredRestBody" class="row filteredRestBody">
<div id="row1" class="row">
<div id="yochina" class="col-sm-4 filterThumbnails" style="background: url('images/yochinathumbbck.jpg')">
<img src="images/bestoffers.png">
<div id="discountImg">
<img src="images/discountimg.png" style="">
<div class="discountNum" title="Discount">15%</div>
</div>
<div id="ratings" title="6/10">
<img src="images/ratingy.png">
<img src="images/ratingy.png">
<img src="images/ratingy.png">
<img src="images/ratingy.png">
<img src="images/ratingy.png">
<img src="images/ratingw.png">
<img src="images/ratingw.png">
<img src="images/ratingw.png">
<img src="images/ratingw.png">
<img src="images/ratingw.png">
</div>
<div id="ratingNum">5</div>
<div id="restaurantThumbnailsTitle" class="restaurantThumbnailsTitle">
<span>Yo! China</span>
<br>
<span class="restaurantThumbnailsTitleText">chilled out chinese</span>
</div>
CSS
.filteredRestBody {
background: none repeat scroll 0 0 rgba(0, 0, 0, 0);
border: medium none;
border-top-left-radius: 23px;
box-shadow: 0 0 0 grey;
height: auto;
margin-left: -4%;
padding: 0 0 47px 8px;
position: relative;
top: 30px;
width: 111%;
}
.filterThumbnails {
background-position: 2px -19px;
background-repeat: repeat;
border-top-left-radius: 10%;
border-top-right-radius: 10%;
height: 200px;
margin-left: 5.3%;
margin-top: 50px;
position: relative;
top: -36px;
width: auto;
}
#ratings {
background: none repeat scroll 0 0 rgba(0, 0, 0, 1);
border-radius: 8px;
left: 50%;
padding: 0 7px 4px;
position: absolute;
top: 49%;
}
#ratingsNum {
background: none repeat scroll 0 0 rgba(0, 193, 0, 0.9);
border-bottom-right-radius: 9px;
border-top-left-radius: 9px;
font-family: Times New Roman;
font-size: 1.6em;
font-weight: bolder;
left: 89%;
padding: 0 8px;
position: absolute;
top: 45.5%;
width: auto;
}
This is the first screenshot when the width is 335
This is what happens when i increase the window's width
Instead of using left, you can use right property in your CSS. This will stick ratingsNum and ratings divs to the right border of container div.
CSS
#ratings {
right:50px;
}
#ratingsNum {
right:10px;
}
jsFiddle Example
Hope it helps.
As a side note, I've noticed that your snippet contains some elements (i.e. #discountImg div) without the closing tag (in this example </div>). Pay attention because this can lead your layout to unpredictable results.
First of, I know there are many similar questions to this, but none of the articles I have read has helped me. Somehow this won't work..
I want to make the area inside the class="downloadBoks" to be clickable, and not just the text within <a></a>. Not using JavaScript.
HTML:
<div class="sideboks">
<div class="downloadBoks">
Prosjektbeskrivelse
</div>
<div class="downloadBoks">
Statusrapport
</div>
</div>
CSS:
.downloadBoks {
height: 23px;
width: 150px;
font-size: 14px;
border-style: solid;
border-color: #000000;
border-width: 0px 0px 2px 0px;
margin-top: 0px;
margin-bottom:0px;
line-height: 25px;
vertical-align:middle;
box-shadow: inset 0px 0 2px 2px #777777;
}
div.sideboks{
width: 150px;
height: 50px;
margin-top: 150px;
margin-left: 54px;
position: fixed;
background-color: #B7AFA3;
border:solid;
border-width: 5px 0px 5px 5px;
border-top-left-radius: 10px;
border-bottom-left-radius: 10px;
box-shadow: inset 1px 0 0px 0px #777777;
}
This is the code I have so far. Right now the "downloadBoks" is purely looks.
edit: So I realised that having the div, within another div might have something to do with it? So updated with that code as well. Thanks for all the responses so far!
.downloadBoks a {
display: block;
height: 100%;
}
This will make the entire square clickable. DEMO
With HTML5, you can put blocks in a tags:
<a href="Prosjektplan.pdf">
<p class="downloadBoks">
Prosjektbeskrivelse
</p>
</a>
You need to make the <a> inside of the div's have 100% height and width. This way they take all the interior of the div and thus the div is "clickable":
.downloadBoks a
{
display:inline-block;
height:100%;
width:100%;
}
Hi all and good morning!
The issue I'm having today is with IE7's rendering (shock, horror) of my work in progress website. Below is some code that is intended to create a page wide <div> that has an image on the left hand side (an arrow) and then 2 lines of text to the right of the image, then a progress bar holder <div> with another <div> inside that will be widened and narrowed to fill the progress bar.
<div class="courseItem">
<img src="images/courses-arrow.jpg" width="41" height="41" alt="->" />
<p><span class="title">Intermediate Microsoft Excel 2010</span><br />
<strong>Last accessed:</strong> 21st September 2011</p>
<div class="courseProgress">
<div class="progressContainer">
<div class="progressFill" style="width: 60px">
</div>
</div>
<p>50%</p>
</div>
<div class="clearBoth"></div>
</div>
Now, what's the problem you ask? Well the issue is that for some reason, and this has really stumped me, the first of these bar divs (there are 4 in total, all exactly the same as the code above, no changes what so ever) has a massive white space between itself and its border which forces the other 3 bars below to be pushed away.
Here's the css;
.courseItem {
margin: 0px 0px 15px 0px;
border-bottom: 1px solid #b0dff7;}
.courseItem img {
float: left;
margin: 0px 20px 15px 0px;}
.courseItem p {
font-size: 11px;
color: #999999;
margin: 5px 0px 0px 0px;
padding: 0;
float: left;}
.courseItem p span.title {
margin: 0;
padding: 0;
font-weight: bold;
font-size: 12px;
color: #00154d}
.courseItem .courseProgress {
float: right;}
.courseItem .courseProgress p {
width: 50px;
font-size: 20px;
color: #52b9ed;
margin: 7px 0px 0px 10px;}
.courseItem .courseProgress .progressContainer {
margin: 15px 0px 0px 0px;
padding: 0;
width: 120px;
height: 12px;
background: url(../images/courses-empytprogress.jpg) no-repeat;
float: left;}
.courseItem .courseProgress .progressContainer .progressFill {
margin: 1px 0px 0px 0px;
height: 10px;
max-width: 120px;
background: url(../images/courses-fillprogress.jpg) repeat-x;
float: left;}
This is the visual representation
http://img1.uploadscreenshot.com/images/orig/10/29204251178-orig.jpg
Thanks in advance.
(Sorry for long windedness, just trying to paint a picture)
Remove the float:left property of .div p, and add display:inline-block;. Then, define the clear:both CSS property for the .clearBoth class.
Fiddle: http://jsfiddle.net/Jqhe8/
Fixed CSS:
.courseItem p {
font-size: 11px;
color: #999999;
margin: 5px 0px 0px 0px;
padding: 0;
display: inline-block; /*Removed float, added display*/
}
.clearBoth { /*Define clear:both!!!*/
clear: both;
}
In your code you didn't clear it's parent div & you .clear class is not working so; first clear the parent div because the child div's have float in it. Write like this
.courseItem {
border-bottom: 1px solid #B0DFF7;
margin: 0 0 15px;
overflow: hidden;
}