I've an issue with my aside bar and the timestamp in my section.
<section>
<div class="thumbnail-title">
Sample
</div>
<div class="thumbnail-image"></div>
<div class="thumbnail-text">
<div class="thumbnail-timestamp">
02-11-2016 18:51 P.M.
</div>
Hello this is random text that I will test today to see if my sizing is correct.
ello this is random text that I will test today to see if my sizing is correct.
</div>
</section>
<aside>
Random Aside Text.
</aside>
If I add more sections, the aside bar sticks to the last section, where as I want it to stick from top downwards.
Also my timestamp is okay if one section exists but if more sections are added, timestamp get's pushed below the text.
Here is the CSS:
section,
aside
{
margin: 20px 20px 24px 0;
}
section
{
float: left;
width: 55%;
margin-left: 20px;
border: 3px solid black;
padding-bottom: 20px;
border-radius: 10px;
}
.thumbnail-title
{
border: 3px solid black;
border-top: none;
border-left: none;
border-right: none;
padding: 15px;
text-align: center;
font-size: 24px;
margin-bottom: 20px;
}
.thumbnail-image
{
float: left;
height: 200px;
width: 300px;
border: 3px solid black;
margin-left: 20px;
margin-right: 20px;
border-radius: 10px;
}
.thumbnail-text
{
font-size: 18px;
text-align: left;
padding: 20px;
padding-left: 20px;
margin-left: 20px;
margin-right: 20px;
border-radius: 10px;
}
.thumbnail-timestamp
{
border: 1px solid black;
text-align: right;
float: right;
width: 360px;
height: 10px;
padding: 2px;
font-size: 10px;
margin-bottom: 10px;
border-top: none;
border-left: none;
border-right: none;
}
aside
{
float: right;
width: 38%;
padding: 10px;
border: 3px solid black;
border-radius: 10px;
}
I want my page to look like this:
Idea
Be care with margin property. (I mean by that margin: 20px 20px 24px 0; is cool, but it's 'dangerous' when you want inline elements)
Set display: inline-block or play with flexbox (amazing things)
Set correct percentage for your width.
If you set a margin: 20px, it doesn't seem to be big, but in fact, it's huge (especially when you resizing, or when you want to set elements in same line.)
Is this something you want ? http://codepen.io/anon/pen/ZBrYde
Related
I'm trying to make a 'custom' progress bar with numbers at each end of the progress bar. Left hand number being the current value, and the right hand side being the max/target value. I've got it so that I'm showing the two numbers but I can't seem to position the right hand number correctly.
What I'm trying to achieve is...
and what I currently have is...
This is what I currently have code wise...
JSFiddle
.progress-outer {
width: 96%;
margin: 10px 2%;
padding: 3px;
text-align: center;
background-color: #f4f4f4;
border: 1px solid #dcdcdc;
color: #fff;
border-radius: 20px;
}
.progress-inner {
min-width: 15%;
white-space: nowrap;
overflow: hidden;
padding: 5px;
border-radius: 20px;
background-color: orange;
}
.progressBarCurrent {
color: black;
float: left;
}
.progressBarGoal {
color: black;
float: right;
}
<div class="progress-outer">
<div class="progress-inner" style="width:27%;">
<span class="progressBarCurrent">50g</span>
<span class="progressBarGoal">180g</span>
</div>
</div>
I've tried putting the the second span outside the the progress inner div but then moves the text outside the whole thing and I couldn't work out how to move it into the correct place.
Can anyone help?
I have an interesting solution using linear-gradients, its pretty close, try playing around with the margins and outline to get border right.
.progress-outer {
width: 96%;
display: flex;
height: 35px;
margin: 10px 2%;
text-align: center;
border: 1px solid #dcdcdc;
background-image: linear-gradient( 80deg, orange 37% , #f4f4f4 37% );
border-radius: 20px;
justify-content: center;
align-items: center;
}
.progressBarCurrent {
color: black;
text-align: left;
width: 50%;
position: relative;
margin: 0px;
margin-left: 20px;
}
.progressBarGoal {
color: black;
position: relative;
text-align: right;
width: 50%;
margin: 0px;
margin-right: 20px;
}
<div class="progress-outer">
<span class="progressBarCurrent">50g</span>
<span class="progressBarGoal">180g</span>
</div>
Instead of float:left you can use position:absolute
.progress-outer {
width: 96%;
margin: 10px 2%;
padding: 3px;
text-align: center;
background-color: #f4f4f4;
border: 1px solid #dcdcdc;
color: #fff;
border-radius: 20px;
position: relative;
}
.progress-inner {
min-width: 15%;
white-space: nowrap;
overflow: hidden;
padding: 5px;
border-radius: 20px;
background-color: orange;
}
.progressBarCurrent {
color: black;
float: left;
}
.progressBarGoal {
color: black;
position: absolute;
right: 5px;
}
<div class="progress-outer">
<div class="progress-inner" style="width:27%;">
<span class="progressBarCurrent">50g</span>
<span class="progressBarGoal">180g</span>
</div>
</div>
I am working on an internal program for work that is essentially built on PHP. My problem is that I have a a header, a side navigation, the main content (to the right of the nav) and a footer. Rough Layout Picture
My issue is that I have two DIV's within a container, the nav is set to a percentage with a minimum width, and the content section is set to take the remaining space. In total both the nav and content should take about 91% of the screen real estate. Whats Happening after shrinking the browser a bit
My CSS looks like this for the fields I think are relevant:
.container{
width: 100%;
float: inline-block;
}
.header{
float: left;
text-align: left;
background-color: lightblue;
width: 100%;
vertical-align: middle;
display: block;
border-radius: 15px;
}
.header h1{
font-weight: bold;
font-size: 40px;
text-indent: 50px;
}
.msg_alert{
background-color: green;
color: white;
width: 95%;
padding: 5px;
border-radius: 10px;
}
.err_msg_alert{
background-color: red;
color: white;
width: 95%;
padding: 5px;
border-radius: 10px;
}
.menu{
float: left;
width: 13%;
border: 3px solid grey;
padding: 5px;
background-color: lightgrey;
border-radius: 15px;
margin-top: 20px;
margin-right: 20px;
min-width: 200px;
}
.menu a{
float: left;
color: black;
text-align: left;
padding: 14px;
text-decoration: none;
box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
margin: 3px;
background-color: lightblue;
width: 40%;
min-width: 150px;
border-radius: 15px;
}
.menu a:hover{
background-color: grey;
color: black;
}
.menu ul{
list-style-type: none;
margin: 0;
padding: 0;
}
.menu li{
padding: 8px;
margin-bottom: 7px;
}
.content{
float: left;
width: 78%;
padding: 20px;
margin-top: 20px;
margin-left: 20px;
/*border: 3px solid red;*/
}
.footer{
display: inline-block;
width: 100%;
background-color: lightgrey;
border-radius: 15px;
font-size: 12px;
text-align: center;
margin-top: 5px;
padding-bottom: 10px;
}
I'm not sure what I've done wrong. Everything displays properly if the browser is in full screen but when I shrink it down to about 3/4's of the browser size the nav stays where it should be but the contents move below.
I have setup a mobile version which works perfectly but the desktop mode is what I am having issues with.
Thank you for the help in advance.
here is the solution-
<div class="header"></div>
<div class="menu_content">
<div class="menu"></div>
<div class="content"></div>
</div>
<div class="footer"></div>
.menu{
width: 13%;
border: 3px solid grey;
padding: 5px;
background-color: lightgrey;
border-radius: 15px;
margin-top: 20px;
margin-right: 20px;
min-width: 200px;
}
.content{
width: calc(100% - 21.7%);
padding: 20px;
margin-top: 20px;
margin-left: 20px;
border: 3px solid red;
}
.menu_content {
display: flex;
align-items: flex-start;
}
.menu_content::after {
content: '';
clear: both;
display: block;
}
Well, although the widths of .menu and .content might add up to 100% or less in a wider format, due to the min-width pixel setting of .menu, they will become wider than 100% when you decrease the window width, since the 200px of min-width: 200px; will become much more than the 13% width you define for it. So (since both are floats), .content will go below .menu, because there isn't enough space anymore for it next to .content.
To avoid that, you can wrap both of these in a div container and assign display: flex to that. Additionally, add flex-shrink: 0; (= allowed to get smaller) to .content. This should basically do the trick. (There are other details , but just check out some tutorial about flex - it's really not complicated at all.)
Another approach would be to define the menu width as 200px (fixed) and the width for .content as width: calc(100% -200px) - The full width of the parent minus 200px, whatever the width of the parent is.
(This doesn't calculate padding, margins etc. - you would have to consider that in the "real" values you use)
I've the following divs in my document:
<div class="bill-header">
<div class="bill-header-info"><span>Bill No</span></div>
<div class="vline"></div>
<div class="bill-header-info"><span>Table No</span></div>
<div class="vline"></div>
<div class="bill-header-info"><span>Room No</span></div>
<div class="vline"></div>
<div class="bill-header-info"><span>Amount</span></div>
</div>
I'm using the following CSS to make them sit on one line:
.bill-header {
height: 30px;
background-color: darkgrey;
padding-left: 10px;
}
.bill-header-info {
float: left;
padding-left: 4px;
padding-top: 5px;
padding-right: 3px;
}
.vline {
width: 2px;
height: 80%;
display: block;
float: left;
margin-top: 3px;
border-left: 1px solid gray;
}
How can I make them appear with same distance in between them?
Fiddle
Do you mean like this? http://jsfiddle.net/3Zv2y/2/
Make these changes:
.bill-header-info {
width:23%;
text-align:center;
}
Add margin: 0 5px in your .vline:
.vline {
width: 2px;
height: 80%;
display: block;
float: left;
margin-top: 3px;
border-left: 1px solid gray;
margin:0 5px;
}
This will give a margin of 5px in both left and right of your vline element.
JSFiddle
use width property in css for exapmle
.bill-header-info {width:22%;}
Updated Fiddle
As long as there are always four items in a row, you can use a "fixed" percentage value:
.bill-header {
height: 30px;
width: 100%;
background-color: darkgrey;
}
.bill-header-info {
float: left;
width: 24.6%;
text-align: center;
padding-top: 5px;
}
The important parts are the width and text-align properties in .bill-header-info
.bill-header-info {
text-align:center;
width:23%;
float: left;
padding-left: 4px;
padding-top: 5px;
padding-right: 3px;
}
.vline {
width: 2px;
height: 80%;
display: block;
float: left;
margin-top:3px;
margin: 0 5 3 3px;
border-left: 1px solid gray;
}
I'm building a fairly interestingly shaped navigation for a site at the moment. The shape each menu item needs to be is illustrated below:
The final nav will look like an extended version of this:
I thought it would be an interesting experiment to do these shapes in CSS. The CSS and HTML for one of the arrow shapes is here:
.arrowEndOn {
font-size: 10px; line-height: 0%; width: 0px;
border-top: 11px solid #FFFFFF;
border-bottom: 11px solid #FFFFFF;
border-left: 5px solid transparent;
border-right: 5px solid #FFFFFF;
float: left;
cursor: pointer;
}
.arrowBulkOn {
height: 20px;
background: #FFFFFF;
padding: 2px 5px 0px 0px;
float: left;
color: #000000;
line-height: 14pt;
cursor: pointer;
}
.arrowStartOn {
font-size: 0px; line-height: 0%; width: 0px;
border-top: 11px solid transparent;
border-bottom: 11px solid transparent;
border-left: 5px solid #FFFFFF;
border-right: 0px solid transparent;
float: left;
cursor: pointer;
}
<div id="nav" class="navArrow" style="position: relative;">
<div class="arrowEndOn" id="nav"> </div>
<div class="arrowBulkOn" id="nav">NAV</div>
<div class="arrowStartOn" id="nav"> </div>
</div>
Each nav item has a negative offset applied to it (which I've left out of the demo) as it's rendered to get them all flush with each other.
I'm handling the rollovers and on states with Javascript.
My problem is getting the nav to stretch all the way across the width of the page. At the moment I have to set the nav container to a much larger width to accommodate it all.
I've tried setting overflow to hidden but the last item is dropping down a level rather than carrying on and just having the end cut off.
I've set an example up here - http://jsfiddle.net/spacebeers/S7hzu/1/
The red border has overflow: hidden; and the blue doesn't.]
My question is: How can I get the boxes to all float in a line that fills the width of the containing div without them dropping down a level.
Thanks
Add a negative margin to each arrow:
.navArrow {
float: left;
margin-left: -8px;
}
Demo: http://jsfiddle.net/S7hzu/2/
Flexbox
You can use this example
https://codepen.io/WBear/pen/pPYrwo
it works on new browsers, to support old ones some changes needed.
HTML:
<div class="content">
<div class="as1">
NAV
</div>
<div class="as2">
NAV
</div>
<div class="as3">
NAV
</div>
</div>
CSS:
.content {
margin-top: 10px;
width: 100%;
display: inline-flex;
}
.as1, .as2, .as3 {
height: 70px;
min-width: 8%;
max-width: 100%;
background-color: black;
position: relative;
display: inline-flex;
text-align: center;
flex-wrap: wrap;
flex-grow: 1;
}
.as1 a, .as2 a, .as3 a {
text-decoration: none;
display: inline-flex;
color: white;
margin: auto;
font-size: 14pt;
}
.as1:after {
content: "";
position: absolute;
right: 4px;
border-top: 35px solid transparent;
border-left: 25px solid black;
border-bottom: 35px solid transparent;
z-index: 2;
}
.as2 {
background-color: grey;
margin-left: -29px;
}
.as2:after {
content: "";
position: absolute;
right: 4px;
border-top: 35px solid transparent;
border-left: 25px solid grey;
border-bottom: 35px solid transparent;
z-index: 3;
}
.as3 {
background-color: #A9A9A9;
margin-left: -29px;
}
I'm trying to get 2 divs to sit side by side, a div for an ad (skyscraper_ad), and a main black (smaller_main) but when I add a float the DIV will overlap another DIV, can somebody help?
My css:
#skyscraper_ad {
display: block;
width: 160px;
height: 600px;
padding: 5px;
margin-right: auto;
background-color: #CCCCCC;
border: 1px solid #AAAAAA;
position:relative;
margin-bottom: 4px;
}
#smaller_main {
display: block;
width: 605px;
height: auto;
background-color: #CCCCCC;
border: 1px solid #AAAAAA;
position:absolute;
padding: 5px;
float: right;
margin-bottom: 4px;
}
This should work:
#skyscraper_ad {
width: 160px;
height: 600px;
padding: 5px;
background-color: #CCCCCC;
border: 1px solid #AAAAAA;
margin-bottom: 4px;
float:left;
}
#smaller_main {
width: 605px;
background-color: #CCCCCC;
border: 1px solid #AAAAAA;
padding: 5px;
float: left;
margin-bottom: 4px;
}
I took out your references to margin, positioning, and display. (and a height:auto which was meaningless as far as i could see). The margin auto was meaningless, the positioning was probably causing overlap, and the display was redundant (divs are already block)