As seen in the picture, I practically have a div of defined width 100% but no defined height, but rather the height is defined to match the contents with a percentage of top and bottom padding.
The problem is I want to have some kind of navigation buttons on the right side, and they must be aligned perfectly in the vertical middle.
I have included a Fiddle of what I did, but it doesn't show in the middle in all cases.
What can be an optimal solution.
HTML
<div class="title">Title
<ul id="bullets">
<li></li>
<li></li>
<ul>
</div>
CSS
.title {
width:100%;
background:#365F95;
background-size: contain;
font-size:130%;
color:#FFF;
padding:5% 0;
text-align:center;
position:relative;
}
.title ul {
position:absolute;
right: 0;
top: 0%;
}
.title ul li {
display: inline-block;
width: 10px;
height: 10px;
border-radius: 10px;
background: #FFF;
box-shadow: inset 0 1px 3px black, 0 0 1px 1px #202020;
margin: 0 2px;
}
http://jsfiddle.net/HJLEe/2/
take a look at this fiddle The idea is vertically align list
position: absolute;
top: 50%;
margin-top: - half-height;
Not the best solution, but it works.
HTML:
<div class="title">Title
<ul id="bullets">
<li></li>
<li></li>
<ul>
</div>
CSS:
.title {
width:100%;
background:#365F95;
background-size; cover;
font-size:130%;
color:#FFF;
padding:5% 0;
text-align:center;
}
.title ul {
position:relative;
float: right;
margin-top: 0px;
}
.title ul li {
display: inline-block;
width: 10px;
height: 10px;
border-radius: 10px;
background: #FFF;
box-shadow: inset 0 1px 3px black, 0 0 1px 1px #202020;
margin: 0 2px;
}
JSFIDDLE
try use position relative in your ul class
.title ul {
position: relative;
}
jsfiddle.net
try this css
.title ul {
position: absolute;
right: 0;
top: 0%;
padding-top: inherit;
margin: 0;
}
Try setting a margin in percentage. Like this...
.title ul {
position:absolute;
right: 0;
top: 0%;
vertical-align :middle;
margin-top : 5%;
}
Another option using vertical-align:middle and the helper pseudo element to hold the height.
Demo: http://jsfiddle.net/HJLEe/13/
Essential additions to the code:
.title ul {
position:absolute;
right: 0;
top: 0;
bottom: 0;
}
/* style of LIs not changed */
.title ul:before {
content: '';
display: inline-block;
height: 100%; /* makes the effective line height equal to the height of the container */
vertical-align: middle; /* align the vertical center with the vertical middle of the text, including our bullets */
}
Related
Let's say I have this code:
<div id="block">asd</div>
And I want to make it move from the top left corner to the bottom right when I hover (or when I click it, it doesn't matter)
#block{ border: 1px solid black;
margin-top: 10px;
margin-left: 10px;}
#block:hover{
margin-right:10px;
margin-bottom:10px;
}
But it doesn't work. Somehow I have to remove the margin-top and margin-left attributes when hovering but I don't know how.
Please do it in css if it can be done!
#block:hover{
margin-top: 0px;
margin-left: 0px;
margin-right:10px;
margin-bottom:10px;
}
if you wanna do it in don't repeat yourself philosophy
#block:hover{
margin-top: 0px;
margin-left: 0px;
}
I guess it's easy
You have the:
#block{ border: 1px solid black;
margin-top: 10px;
margin-left: 10px;}
So, in the hover, you have to cancel the margin-top and margin-left (change it to zero), and then apply the margin you want!
#block:hover{
margin-right:10px;
margin-bottom:10px;
margin-top: 0;
margin-left: 0;
}
Like that, the margin you had will disappear on hover!
in the #block:hover css, just put this code there down, and everything should work fine.
#block:hover{
margin-right:10px;
margin-bottom:10px;
margin-top: 0;
margin-left: 0;
}
Just put the margin "all in one".
So it will be:
margin: [top right bottom left]
In your case:
#block{
margin: 10px 0px 0px 10px;
}
#block:hover{
margin: 0px 10px 10px 0px;
}
You can also combine margin like:
margin: [top+bottom] [left+right];
Instead of using margin, use the transform property.
To achieve this you would require another element that serves as a wrapper.
When hovering the wrapper do the following:
Move the wrapper iteself to the right bottom corner using:
transform: translate(calc(100% - [<blockWidth>]), calc(100% - [<blockHeight>]));
Then move the .block element in the opposite direction with:
transform: translate(calc(-100% - [<blockWidth>]), calc(-100% - [<blockHeight>]));
Code Snippet:
body {
margin: 0;
overflow: hidden;
}
.block-container {
box-sizing: border-box;
position: absolute;
width: 100%;
height: 100%;
transition: transform 3s;
}
.block-container:hover {
transform: translate(calc(100% - 2em), calc(100% - 2em));
}
.block {
position: absolute;
width: 2em;
height: 2em;
background-color: darkorange;
transition: inherit;
}
.block-container:hover #block {
transform: translate(calc(-100% - 2em), calc(-100% - 2em));
}
<div class="block-container">
<div class="block"></div>
</div>
maybe something like this:
Css:
#block {
border: 1px solid black;
width: 100px;
height: 100px;
position: absolute;
top: 0;
left: 0;
}
#block:hover {top: 90vh; left: 90vw;}
Html:
<div>try to catch me</div>
I have a unordered list where the bullets are created with FontAwesome, a bit of background and a border radius.
I want the second line of text be be alined below the first one and not under the bullet.
li::before {
display: table-cell;
padding-right: .3em;
content: "\f00c";
float: left;
margin: 0 9px 0 0;
font: 10px 'FontAwesome';
width: 20px;
height: 20px;
position: relative;
background: #3498db;
-webkit-border-radius: 50%;
-moz-border-radius: 50%;
border-radius: 50%;
text-align: center;
line-height: 20px;
color: #FFF;
}
Somehow float: left seems to "conflict" with display: table-cell.
Any ideas on how to get this to work? -> jsfiddle
Use position:absolute for :before and padding-left for <li>
li {
position:relative;
padding-left:32px;
}
li::before{
position:absolute;
top:0;
left:0;
}
DEMO
Use position:absolute for :before and padding-left for <li>, but do not use left or top. Use margins instead.
http://jsfiddle.net/semencov/vvLtj43g/
You can visit the site I am working on here. Currently, I am working on making the site relative. I am adjusting the CSS for a resolution with a width less than 820px. This involves adjusting the menu from this
to this . As you can see, I have outlined my divs with a red border to demonstrate the problem. I want to the menu bar to sink to the bottom of its parent div. However, setting it to bottom: 0 nothing changes. How can I get the div class="nav" to sink to the bottom of div class="header" at a resolution of less than 820px?
Here is my HTML
<div class="header">
<div id="narrow-logo"><img src="Images/pantry logo.png" width="536" height="348"></div>
<div class="nav">
<ul>
<li class="link">HOME</li>
<li class="link">MENU</li>
<li id="logo"><img src="Images/pantry logo.png" width="536" height="348"></li>
<li class="link">CONTACT</li>
<li class="link">ABOUT</li>
</ul>
</div>
</div>
And my CSS
.header {
width: 960px;
height: 150px;
margin: 0 auto;
text-align: center;
position: relative;
padding: 100px 0px 0px 0px;
}
.header div#narrow-logo {
display: none;
}
.nav ul li {
display: inline-block;
vertical-align: middle;
margin-right: 70px;
}
#logo a img {
max-width: 250px;
height: auto;
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%,-50%);
transform: translate(-50%,-50%);
}
#logo {
width: 250px;
position: relative;
}
#media screen and (max-width: 1080px) {
.header {
width: 700px;
height: 125px;
padding: 75px 0px 0px 0px;
}
#logo a img {
max-width: 180px;
}
#logo {
width: 180px;
}
#media screen and (max-width: 820px) {
.header {
border: 2px solid red;
width: 475px;
padding: 0;
margin-top: 40px;
height: 200px;
}
.header div#narrow-logo {
border: 2px solid red;
display: inherit;
position: absolute;
left: 50%;
-webkit-transform: translate(-50%);
transform: translate(-50%);
}
.header div#narrow-logo a img {
width: 200px;
height: auto;
}
.nav {
border: 2px solid red;
bottom: 0px;
}
.nav ul li {
margin-right: 25px;
}
.nav ul li:nth-child(3) {
display: none;
}
#logo a img {
display: none;
}
#logo {
width: 0;
}
I know that is a lot of code and I apologize. I just wanted to make sure I included all positioning attributes that could be causing my issue. Let me know if I can clarify anything, and I appreciate your time and advice.
For bottom:0 to work, you need the element that it's being applied to to be absolutely positioned. You also need, in this case, to have it's parent relatively positioned. Try this:
.nav ul li {
display: inline-block;
margin-right: 70px;
position:absolute;
bottom:0;
}
Adding position value will resolve your issue.Please update your css in the following section.
#media screen and (max-width: 820px) {
.nav {
border: 2px solid red;
bottom: 0px;
position:absolute;
left:16%;
}
}
For bottom:0; to work, your class="nav" has to have absolute positioning.
CSS:
.nav {
position: absolute;
bottom: 0;
I have been stuck on a problem here. This is what I designed my app in html and css. The problem is indicated with red circle in lower left corner i.e. the space before the left tab. I am unable to remove this space. This is neither padding nor margin but I don't know what it is.
The code for tab is:
html
<ul id="bottomTabs">
<li>Player</li>
<li>Reciters</li>
</ul>
css
ul {
margin: 0 ;
bottom: 0 ;
left: 0 ;
padding: 0;
}
li {
list-style-type: none;
bottom: 0 ;
left: 0 ;
margin-left:1em ;
}
#bottomTabs {
width: 100%;
bottom: 0px;
display: table;
position: fixed;
table-layout: fixed;
text-align: center;
}
#bottomTabs li {
width: 47.5%;
height: auto;
align : center;
display: table-cell;
padding-left: 1.5%;
vertical-align: bottom;
}
#bottomTabs a {
display: block;
color: #ffffff;
min-height: 100%;
padding: 4px 10px;
background-color: #222;
border-radius: 0 0 0 0;
}
You have padding-left: 1.5% on both of your li elements. You only need it for the second one. You can create a new class/id just for the second list item. Have your HTML as:
<ul id="bottomTabs">
<li>Player</li>
<li id="padded">Reciters</li>
</ul>
And CSS:
#bottomTabs li {
width: 47.5%;
height: auto;
align : center;
display: table-cell;
vertical-align: bottom;
}
#padded{
padding-left: 1.5%;
}
DEMO: http://jsfiddle.net/cuzZC/1/
Give a class for the first li and give padding 0..
.padd
{
padding:0 !important;
}
<ul id="bottomTabs">
<li class="padd" >Player</li>
<li>Reciters</li>
</ul>
try this one,
#bottomTabs li:first-child {
width: 47.5%;
height: auto;
align : center;
display: table-cell;
padding-left: 0;
vertical-align: bottom;
}
http://jsfiddle.net/K9jq7/
padding-left: 1.5% is causing this effect.
The first li doesn't need any padding, just add
#bottomTabs li:first-child {
padding-left: 0;
}
or you could remove the padding-left from #bottomTabs li and add
#bottomTabs li:last-child {
padding-left: 1.5%;
}
I would suggest using the first-child pseudo class since it's better supported.
http://www.quirksmode.org/css/selectors/
I would like to know if (and maybe how) some text-shadow like shown in following image is possible:
The shadow is decreasing over several list-elements. I was thinking to give each element different hover-classes depending on what element is being hovered on, but I am not even sure how to get such decreasing shadows with CSS. Would be really cool if someone would be able to teach me how to do that. If you want you can use my jsfiddle code.
You could try something like this
demo
(click a tab to select it and see the shadows)
and get the effect using box-shadow on pseudo-elements of the selected tab.
Should look like this
HTML:
<ul class='tabs'>
<li><a href='#' tabindex='1'>1st tab</a></li>
<!-- as many tabs as you would like -->
<li><a href='#' tabindex='1'>aaand another tab</a></li>
</ul>
Relevant CSS:
.tabs { overflow: hidden; margin-top: 7em; list-style: none; }
.tabs li { float: left; border-right: 1px dotted #222; }
.tabs a {
display: block;
position: relative;
padding: 1em .66em;
font: .66em/1.1 sans-serif;
text-transform: uppercase;
text-decoration: none;
}
.tabs a:focus {
z-index: 3;
outline: none;
box-shadow: 0 -.5em 1.5em black;
background: lemonchiffon;
}
.tabs a:focus:before, .tabs a:focus:after {
position: absolute;
bottom: -1px;
width: 30em; height: 1px;
box-shadow: 0 0 20px 1px black;
content: '';
}
.tabs a:before {
left: -30.5em;
transform: rotate(-3deg);
transform-origin: 100% 100%;
}
.tabs a:after {
right: -30.5em;
transform: rotate(3deg);
transform-origin: 0 100%;
}
You could augment an <li> to sit within the whole width of the <ul>, rotate it and give it a shadow..
HTML:
...
</li>
<li class="shadow">1</li>
</ul>
CSS:
ul
{
overflow: hidden;
height: 50px;
}
li.shadow
{
width: 100%;
height: 100%;
position: relative;
top: 15px;
box-shadow: 0px 0px 45px #000;
-webkit-transform:rotate(-1deg);
}
http://jsfiddle.net/Kyle_Sevenoaks/4Luet/1/