I am trying to keep my ul and li elements that are inside of a div to respect the div's width with margin-left: auto. I am also not wanting ul/li to extend out of the div. I want the ul and li elements to stay inside the div container. From what I have read, this code is correct because I have the child elements contain a width which should be according to div's width.
#phonequeue {
display: block;
width: 400px;
height: 800px;
border-width: 5px;
border-color: white;
border-style: solid;
float: right;
margin-top: -650px;
}
li {
display: block;
padding: 15px;
text-align: left;
height: 1.2 em
padding-left: 15px;
padding-right: 15px;
margin: 0px 0px 4px 0px;
background-color #555
-webkit-border-radius: 15px;
border-radius: 40px;
background: -webkit-gradient(linear, 0% 0%, 0% 30%, from(#444), to(#111));
font-family: verdana, arial, helvetica, sans-serif;
font-size: 22px;
width: 100%;
margin: auto;
}
ul {
list-style-type: none;
width: 100%;
margin: auto;
}
index.html:
<div id="phonequeue">
<ul>
<li class="avail">
<span class="pname">John Doe</span>
<span class="ptime">03:00</span>
</li>
</ul>
</div>
UPDATE: Here is a working example. The element width is 430px; when the parent div is 400px;. I would the child elements to center themselves in div and have their width respecting the parents width. http://jsfiddle.net/FBvQJ/4/
I believe the problem was with the use of width: 100%
Check this jsFiddle and let me know if this answers your question.
This is the updated CSS to solve the overlapping width:
phonequeue {
display: block;
width: 200px;
border: 1pt solid green;
}
ul{
border: 1pt solid red;
list-style-type: none;
margin: auto;
padding: 0;
}
li {
display: block;
padding: 15px;
text-align: left;
height: 1.2em;
margin: 0px 0px 4px 0px;
-webkit-border-radius: 15px;
font-size: 22px;
margin: auto;
border: 1pt solid #ccc;
}
I don't think you need to define the full width for each element.
If you'd like the text centered in the DIV, remove the width on the LI tag and make the margin:
margin: 0px auto 4px auto;
That will center the text within the div.
If I'm understanding your question correctly (which is dubious) I believe you can achieve the centering you require by removing the 100% widths and using text-align:center:
li {
display: block;
padding: 15px;
text-align: left;
height: 1.2 em;
padding-left: 15px;
padding-right: 15px;
margin: 0px auto 4px auto;
background-color #555;
-webkit-border-radius: 15px;
border-radius: 40px;
background: -webkit-gradient(linear, 0% 0%, 0% 30%, from(#444), to(#111));
font-family: verdana, arial, helvetica, sans-serif;
font-size: 22px;
text-align:center; /* < this (or not, if you don't actually want it centred after all) */
}
ul {
list-style-type: none;
padding:0; /* < and this */
margin: 0;
}
Demo fiddle
And later, when you decide that you want the time on the right use
.ptime {float:right;}
example
Related
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)
This question already has answers here:
How do I combine a background-image and CSS3 gradient on the same element?
(20 answers)
Closed 5 years ago.
I would like to display image to the left (border same as left border of white section to the left of blue box). Now Image will be visible only when remove background-image: linear-gradient(#a4c2e8,#e2eaf2);
But I want to preserve the gradient effect. How to do that ?
.quate_sidebar {
list-style: outside none none;
margin: -6px;
margin-top: 5px;
padding: 30px;
padding-right: 126px;
padding-bottom: 5px;
}
.quate_sidebar li {
position: relative;
display: inline-block;
padding: 15px 25px;
padding-bottom: 0px;
margin-bottom: 10px;
margin-left: 14px;
background-image: linear-gradient(#a4c2e8, #e2eaf2);
/* text styles */
text-decoration: none;
color: #4174c5;
font-size: 13px;
font-family: initial;
font-weight: 100;
border-radius: 3px;
box-shadow: 0px 1px 4px -2px #333;
display: block;
margin: 5.5px 0;
padding: 10px 10px 10px 50px;
}
.quate_icon_1 {
background: url(img/get_quate/get_quate_icon_1.png)no-repeat scroll 15px center;
}
<ul class="quate_sidebar">
<li class="quate_icon_1">Csab </li>
<li class="quate_icon_1">Maryy</li>
</ul>
Please refer the code here:
https://jsfiddle.net/edp5o27u/
Use the following in .quate_sidebar li:
background-image: url('http:/placehold.it/30'), linear-gradient(#a4c2e8, #e2eaf2); background-repeat: no-repeat, repeat;
See also this fiddle
If you add the icon background image to the <a> element, then you can keep the gradient background image on the <li> element.
.quate_sidebar li {
position: relative;
display: inline-block;
padding: 15px 25px;
padding-bottom: 0px;
margin-bottom: 10px;
margin-left: 14px;
background-image: linear-gradient(#a4c2e8, #e2eaf2);
/* text styles */
text-decoration: none;
color: #4174c5;
font-size: 13px;
font-family: initial;
font-weight: 100;
border-radius: 3px;
box-shadow: 0px 1px 4px -2px #333;
display: block;
margin: 5.5px 0;
padding: 10px 10px 10px 50px;
}
a.quate_icon_1 {
background: url(img/get_quate/get_quate_icon_1.png)no-repeat scroll 15px center;
}
I want to make a menu to the left and to the right of a list. The menu's have to be fixed, and I want them to always be 10 px of the list, even when I am resizing.
I made the list 'position: relative' and I would like the menu's to be placed relative to the list.
As you can see, I would like it so the orange buttons are the same distance from the list as the blue buttons, even when I resize it.
I tried to use margins, left, right, padding... but nothing seems to work.
Here is some css I used:
With this css, it looks like this:
.navblue {
float: left;
position: fixed;
}
.navorange {
float: right;
position: fixed;
}
.navblue ul {
list-style: none;
padding-left: 0;
}
.navorange ul {
list-style: none;
padding-left: 0;
}
#biglist {
background-color: #e3e3e3;
width: 80%;
padding: 20px;
border-radius: 5px;
color: #000;
border-color: transparent;
margin-left: auto;
margin-right: auto;
}
Thank you very much if you can help.
Maybe this is what you're looking for?
http://jsfiddle.net/myjruLvr/9/
I added an extra parent <div> outside the icons and the main content, and then gave it padding equal to the width of the icons + 10px margin. And instead of position: fixed;, I've used position: absolute;.
Alternatively, you can also use the float property for the icons.
http://jsfiddle.net/myjruLvr/11/
That's a rough example. The icons are floated on their respective sides and the centered <div> will have margins on either sides equal to the width of the icons + 10px.
EDIT:
It seems you're asking for something like a sticky menu, but made purely out of CSS. Sadly position:fixed positions an element relative to the browser viewport, regardless of how it's parent is positioned, and I guess that's pretty much the reason why we have several jquery alternatives for this.
You have to add the fixed position units. Update your CSS like below.
.navblue {
position: fixed;
left:0;
top:0;
}
.navorange {
position: fixed;
top:0;
right:0;
}
EDIT
Based on your comments below, Here is updated CSS.
#container {
width: 100%;
padding-left:70px;
padding-right:70px;
box-sizing:border-box;
}
.navblue {
position: fixed;
left:0px;
top:0;
}
.navorange {
position: fixed;
top:0;
right:0px;
}
.navblue ul {
list-style: none;
padding-left: 0;
}
.navblue a {
display: block;
font-family: Pictoss;
font-size: 20px;
padding: 2px 20px 38px 20px;
background:#017da1;
width: 20px;
text-decoration: none;
overflow: hidden;
text-shadow: 0 -1px 1px black;
border-radius: 50px;
color: white;
height: 20px;
margin-bottom: 10px;
border: 5px solid #017da1;
-webkit-transition: all ease-in-out .3s;
-webkit-background-clip: padding-box;
}
.navorange a {
display: block;
font-family: Pictoss;
font-size: 20px;
padding: 2px 20px 38px 20px;
background: #e9500c;
width: 20px;
text-decoration: none;
overflow: hidden;
text-shadow: 0 -1px 1px black;
border-radius:50px;
color: white;
height: 20px;
margin-bottom: 10px;
border: 5px solid #e9500c;
}
.navorange ul {
list-style: none;
padding-left: 0;
}
#biglist {
height: 500px;
background-color: #e3e3e3;
width:100%;
border-radius: 5px;
color: #000;
border-color: transparent;
box-sizing:border-box;
}
DEMO
I have the following site here that is using CSS for the Nav element. I have defined the class as the following but it is making the menu text flush left even though I specified !important?
#nav {
-moz-box-shadow: 0 1px 1px #000;
-webkit-box-shadow: 0 1px 1px #000;
box-shadow: 0 1px 1px #000;
clear: both;
color: #fff;
font-size: 13px;
margin: 0 auto;
overflow: hidden;
font-family: 'Droid Serif', arial, serif!important;
height: 30px;
width: 100%;
text-align:center;
padding-top: 3px;
border-bottom: 1px solid white;
position: relative;
background-color: #BD8D2B;
}
You don't need to float your UL element to the left, only the LI's. Floating the UL to the left is pushing that block of content to the left. Removing the float and applying a margin: auto to the left and right of your element will center it in modern browsers.
#nav ul {
padding: 0 0 0 10px;
width: 950px;
margin-left: auto;
margin-right: auto;
}
As j08691 suggested you should remove the float:left; from the ul element and adding margin:0 auto; to center the menu.
#nav ul {
float:none;
margin: 0 auto;
}
I've got a button posted here:
http://buttontest.raptorshop.com/
But for some reason, it isn't entirely lining up. What can cause this?
I tried changing line height, padding, etc.
Here's the CSS code I have:
a.gbutton {
background: transparent url('buttonside.png') no-repeat scroll top right;
color: #444;
display: block;
float: left;
font: normal 12px arial, sans-serif;
height: 82px;
margin-right: 6px;
padding-right: 46px; /* sliding doors padding */
text-decoration: none;
}
a.gbutton span {
background: transparent url('buttonmain.png') no-repeat;
display: block;
line-height: 68px;
padding: 5px 0 5px 18px;
}
I am modifying this from a tutorial I found online, and perfect CSS placement has always been a difficult item for me.
The sliding door technique works because extending a rectangle won't change its look. But extending a ellipse will, so your code won't work as you expect.
Here is the best I could get:
a.gbutton {
background: transparent url('buttonside.png') no-repeat scroll right top;
color: #444;
display: block;
float: left;
font: normal 12px arial, sans-serif;
height: 82px;
margin-right: 10px;
padding-right: 51px;
text-decoration: none;
}
a.gbutton span {
background: transparent url('buttonmain.png') no-repeat left top;
background-size: 100% auto;
display: block;
line-height: 68px;
padding: 5px 0 5px 18px;
height: 100%;
width: 100%;
}
Update
Just use a single image and specify the CSS:
background-size: 100% auto;