I make a list that looks like the picture below. My problem is that not the whole link is clickable, only the text. I can't make a display: block on the anchor and give the link the full width because I already gave the anchor display: table-cell.
Here you can can see my problem and try out your code:
http://jsfiddle.net/kma_999/v0xkk587/
Thanks in advance!
HTML:
<div class="pane-content">
<ul>
<li>Kostenkontrolle (Mobile)</li>
<li>Sunrise Rechnung</li>
<li>Umzug</li>
<li>iPhone</li>
<li>Telefonieren im Ausland (Roaming)</li>
</ul>
</div>
CSS:
ul {
border: 1px solid lightgray;
padding-left: 0px;
}
ul li {
border-bottom: 1px solid lightgray;
list-style: none outside none;
margin-left: 20px;
margin-right: 20px;
vertical-align: middle;
}
ul li:last-child{
border-bottom: 0px solid black;
}
ul li a {
display: table-cell;
height: 75px;
vertical-align: middle;
padding-left: 20px;
color: black;
width: 100%;
}
ul li a:hover{
color: black;
text-decoration: none;
}
ul li a:after {
content: "\25b6";
font-size: 10px;
position: absolute;
right: 33px;
}
ul {
display: table;
border: 1px solid lightgray;
padding-left: 0px;
width: 100%;
}
ul li {
display: table-row;
list-style: none outside none;
margin-left: 20px;
margin-right: 20px;
vertical-align: middle;
}
ul li:last-child a {
border-bottom-width: 0;
}
ul li a {
display: table-cell;
height: 75px;
vertical-align: middle;
padding-left: 20px;
border-bottom: 1px solid lightgray;
color: black;
width: 100%;
}
You can see example
try this
ul li a {
display: inline-table;
height: 75px;
vertical-align:middle;
padding-left: 20px;
color: black;
width: 100%;
line-height:75px;
}
You can try below code:
ul li a {
display: block;
height: 50px;
padding: 25px 0px 0px 20px;
color: black;
width: 100%;
}
Try this:
ul li a {
color: black;
display: inline-block; // changed
height: 75px;
line-height: 75px; // added
padding-left: 20px;
vertical-align: middle;
width: 100%;
}
Try this
ul li a {
display: table-cell;
height: 75px;
vertical-align: middle;
padding-left: 20px;
color: black;
width: 500px;
}
I replace the width of a tag 100% to that of parent (li). Then it seems to work.
You can try this
ul li a {
height: 75px;
line-height: 75px;
padding-left: 20px;
color: black;
width: 100%;
display:block;
}
Instead giving it to vertical align middle you can also use line-height for make it middle.
Related
I'm sorry to ask this question because it has been largely posted, but I checked a lot of links and didn't solve it yet. I have a navbar with 2 elements and I cannot center it in the middle of the nav.
#menu {
background: #000000;
background: linear-gradient(to bottom, #973F8E, #DC4069);
color: #FFF;
height: 52px;
width: 500px;
padding-left: 18px;
border-radius: 50px;
border: 1px solid #000000;
margin: auto;
display:block;
text-align:center !important;
}
#menu ul, #menu li {
margin: 0 auto;
padding: 0;
list-style: none;
display: block;
text-align: center;
}
#menu ul {
width: 100%;
}
#menu li {
float: left;
display: inline;
position: relative;
}
#menu a {
display: block;
line-height: 50px;
padding: 0 14px;
text-decoration: none;
color: #FFFFFF;
font-size: 15px;
text-transform: uppercase;
}
#menu a.dropdown-arrow:after {
content: "\25BE";
margin-left: 5px;
}
#menu li a:hover {
color: #000000;
background: #FFA6AF;
}
#menu input {
display: none;
margin: 0;
padding: 0;
height: 52px;
width: 100%;
opacity: 0;
cursor: pointer
}
#menu label {
display: none;
line-height: 50px;
text-align: center;
position: absolute;
left: 35px
}
#menu label:before {
font-size: 1.6em;
content: "\2261";
margin-left: 20px;
}
#menu ul.sub-menus{
height: auto;
overflow: hidden;
width: 170px;
background: #444444;
position: absolute;
z-index: 99;
display: none;
}
#menu ul.sub-menus li {
display: block;
width: 100%;
}
#menu ul.sub-menus a {
color: #FFFFFF;
font-size: 16px;
}
#menu li:hover ul.sub-menus {
display: block
}
#menu ul.sub-menus a:hover{
background: #F2F2F2;
color: #444444;
}
<nav id="menu">
<input type='checkbox' id='responsive-menu' onclick='updatemenu()'><label></label>
<ul>
<li><a href='/'>DASHBOARD</a></li>
<li><a href='/model'>MODEL</a></li>
</ul>
</nav>
Probably in the large number of css elements I'm not able to see where the code is not working.
I posted the code here:
codepen
You should remove the left padding from the main #menu element, set the ul's display to inline-block and the width to auto (just remove the width property).
This will work because the #menu element has text-align: center. the ul will be centered since its width is not 100% (because width is set to auto and the display to inline-block).
#menu {
background: #000000;
background: linear-gradient(to bottom, #973F8E, #DC4069);
color: #FFF;
height: 52px;
width: 500px;
padding-left: 0; // remove this
border-radius: 50px;
border: 1px solid #000000;
margin: auto;
display:block;
text-align:center !important;
}
#menu ul, #menu li {
margin: 0 auto;
padding: 0;
list-style: none;
display: block;
text-align: center;
}
#menu ul {
display: inline-block; // and set this
}
#menu li {
float: left;
display: inline;
position: relative;
}
#menu a {
display: block;
line-height: 50px;
padding: 0 14px;
text-decoration: none;
color: #FFFFFF;
font-size: 15px;
text-transform: uppercase;
}
#menu a.dropdown-arrow:after {
content: "\25BE";
margin-left: 5px;
}
#menu li a:hover {
color: #000000;
background: #FFA6AF;
}
#menu input {
display: none;
margin: 0;
padding: 0;
height: 52px;
width: 100%;
opacity: 0;
cursor: pointer
}
#menu label {
display: none;
line-height: 50px;
text-align: center;
position: absolute;
left: 35px
}
#menu label:before {
font-size: 1.6em;
content: "\2261";
margin-left: 20px;
}
#menu ul.sub-menus{
height: auto;
overflow: hidden;
width: 170px;
background: #444444;
position: absolute;
z-index: 99;
display: none;
}
#menu ul.sub-menus li {
display: block;
width: 100%;
}
#menu ul.sub-menus a {
color: #FFFFFF;
font-size: 16px;
}
#menu li:hover ul.sub-menus {
display: block
}
#menu ul.sub-menus a:hover{
background: #F2F2F2;
color: #444444;
}
You can use flex positions.
Use property justify-content : center to center all children div inside a parent div. It's useful to distribute the space between or around the elements.
This will also make your CSS code lighter. The more CSS, the more difficult it is.
It's also good for responsive design.
I have also removed some CSS property. This code can be further improved and reduced. Good luck !
#menu {
background: #000000;
background: linear-gradient(to bottom, #973F8E, #DC4069);
color: #FFF;
height: 52px;
width: 500px;
// padding-left: 18px;
border-radius: 50px;
border: 1px solid #000000;
margin: auto;
// display:block;
// text-align:center !important;
}
#menu ul, #menu li {
margin: 0 auto;
padding: 0;
// list-style: none;
// display: block;
text-align: center;
}
#menu ul {
width: 100%;
display: flex;
justify-content: center;
}
#menu li {
// float: left;
margin : 0px;
display: inline;
// position: relative;
}
#menu a {
display: block;
line-height: 51px;
padding: 0 14px;
text-decoration: none;
color: #FFFFFF;
font-size: 15px;
text-transform: uppercase;
}
#menu a.dropdown-arrow:after {
content: "\25BE";
margin-left: 5px;
}
#menu li a:hover {
color: #000000;
background: #FFA6AF;
}
#menu input {
display: none;
margin: 0;
padding: 0;
height: 52px;
width: 100%;
opacity: 0;
cursor: pointer
}
#menu label {
display: none;
line-height: 50px;
text-align: center;
position: absolute;
left: 35px
}
#menu label:before {
font-size: 1.6em;
content: "\2261";
margin-left: 20px;
}
#menu ul.sub-menus{
height: auto;
overflow: hidden;
width: 170px;
background: #444444;
position: absolute;
z-index: 99;
display: none;
}
#menu ul.sub-menus li {
display: block;
width: 100%;
}
#menu ul.sub-menus a {
color: #FFFFFF;
font-size: 16px;
}
#menu li:hover ul.sub-menus {
display: block
}
#menu ul.sub-menus a:hover{
background: #F2F2F2;
color: #444444;
}
<nav id="menu">
<input type='checkbox' id='responsive-menu' onclick='updatemenu()'><label></label>
<ul>
<li><a href='/'>DASHBOARD</a></li>
<li><a href='/model'>MODEL</a></li>
</ul>
</nav>
I need to make something like this.
How do i manage the floats of the text, image and the number. Cant seem to get the text right.
i used span for all three and set background for the image of the span.
is there any better way to do this? and how do i get it as this.
Thank you!
http://jsfiddle.net/yapamjfy/
.counter-inner ul li{
float: left;
background: red;
}
.counter-image {
display: block;
width: 58px;
height: 70px;
border-right: 2px solid #fc6867;
background: red;
}
.counter-text{
float: left;
}
you can try this one:
.counter-inner {
width: 763px;
margin: 0 auto;
}
.counter-inner ul {
list-style: none;
}
.counter-inner ul li {
float: left;
background: red;
}
.counter-image {
display: block;
width: 58px;
height: 70px;
border-right: 2px solid #fc6867;
background: red;
}
.counter-image.first {
background: url('../images/counter-1.png') center center no-repeat;
float: left;
}
.counter-number {
font-family: 'Roboto', sans-serif;
float: left;
padding-top: 15px;
padding-left: 17px;
}
.counter-text {
float: left;
margin-top:40px;
margin-left:-15px;
}
ul li
{
padding-right:10px;
}
DEMO HERE
I know this question has been asked a lot but I can't find any fix working for my sample.
I read and tried solutions stated in alignment tutorial.
I tried playing with display: inline-block; and vertial-align: middle; as much as I could.
My HTML:
<div id="header_container">
<div id="logo"></div>
<div id="menu_and_social_icons_container">
<div id="menu_container">
<ul>
<li>Portfolio</li>
<li>About</li>
<li>Contact</li>
</ul>
</div><!--//menu_container-->
<div id="social_icons_container">
<div id="twitter_icon"></div>
<div id="pinterest_icon"></div>
</div><!--//social_icons_container-->
</div><!--//menu_and_social_icons_container-->
</div><!--//header_container-->
My CSS:
/* Header */
#header_container { padding: 10px 0 30px; width: 100%; height: auto; padding-top: 3%; border-bottom: 1px solid #CBCBCB; display: inline-block; }
#logo { background: #aaa; width: 200px; height: 100px; float: left; vertical-align: middle; }
#menu_and_social_icons_container { float: right; display: inline-block; vertical-align: middle; }
#menu_container { text-transform: uppercase; font-size: 1.3em; font-style: bold; float: left; font-family: 'Lato', sans-serif; vertical-align: middle; }
#menu_container ul { list-style-type: none; }
#menu_container ul li { display: inline-block; margin-left: 20px; text-decoration: none; color: #4e918b; }
#menu_container ul li:hover { font-weight: 900; }
#social_icons_container { float: right; vertical-align: middle; }
#social_icons_container div { width: 50px; height: 50px; float: left; margin-left: 25px; }
#twitter_icon { background: #555; }
#pinterest_icon { background: #888; }
Here is a JSFiddle to make things easier.
Vertical-align won't work with Floated elements.
Remove float and try to do it with inline-block alone.
Here is the solution fiddle. http://jsfiddle.net/yvxb1os1/11/
/* Header */
#header_container { padding: 10px 0 30px; width: 100%; height: auto; padding-top: 3%; border-bottom: 1px solid #CBCBCB; display: inline-block; }
#logo { background: #aaa; width: 200px; height: 100px; display: inline-block; vertical-align: middle; }
#menu_and_social_icons_container { display: inline-block; vertical-align: middle; width: calc(100% - 204px); }
#menu_container { text-transform: uppercase; font-size: 1.3em; font-style: bold; font-family: 'Lato', sans-serif; vertical-align: middle; display: inline-block;}
#menu_container ul { list-style-type: none; }
#menu_container ul li { display: inline-block; margin-left: 20px; text-decoration: none; color: #4e918b; }
#menu_container ul li:hover { font-weight: 900; }
#social_icons_container { float: right; vertical-align: middle;}
#social_icons_container div { display: inline-block; width: 50px; height: 50px; float: left; margin-left: 25px; }
#twitter_icon { background: #555; }
#pinterest_icon { background: #888; }
Thanks to "Vertical-align won't work with Floated elements." from #user387249, I found the best solution in my case. See Justin Drury's answer for more details.
Most important change:
#logo_container:after, #menu_container:before, #social_icons_container:before { height: 100%; content: ''; font-size: 0; vertical-align: middle; display: inline-block; }
And height: 100% on my 3 floated div.
Here is the updated JSFiddle.
I am trying to center my navigation. The CSS text-align: center; is not working. It doesn't seem to affect the nav in anyway, shape, or form.
here's my html:
<nav id="user_nav"><ul>
<li>Friends</li>
<li>Followers</li>
<li>Photos</li>
<li>Interests</li>
</ul></nav>
here's my CSS:
#user_nav {
height: 60px;
border-bottom: 1px solid black;
width: 100%;
}
#user_nav ul {
margin: 0 auto;
width: 100%;
}
#user_nav ul li {
list-style: none;
display: inline;
text-align: center;
}
#user_nav ul li a {
padding: 15px 25px 0 0;
font-size: 18px;
float: left;
}
Please note: I am trying to make the links centered horizontally as well as vertically.
If there is a better way to do it than how I am doing it now, I am open to suggestions.
Please help me.
Fiddle
CSS
#user_nav {
height: 60px;
border-bottom: 1px solid black;
width: 100%;
}
#user_nav ul {
margin: 0 auto;
width: 100%;
text-align: center;
}
#user_nav ul li {
list-style: none;
display: inline-block;
}
#user_nav ul li a {
vertical-align: middle;
padding: 15px 25px 0 0;
font-size: 18px;
display: block;
}
HTML
<nav id="user_nav"><ul>
<li>Friends</li>
<li>Followers</li>
<li>Photos</li>
<li>Interests</li>
</ul></nav>
You may be interested in this: Live demo (click).
#user_nav {
height: 60px;
border-bottom: 1px solid black;
width: 100%;
}
#user_nav ul {
width: 100%;
display: table;
}
#user_nav ul li {
list-style: none;
display: table-cell;
font-size: 18px;
}
If you use inline-block you'll need to space the elements out manually by setting the width: Live demo (click).
#user_nav {
height: 60px;
border-bottom: 1px solid black;
width: 100%;
}
#user_nav ul {
width: 100%;
}
#user_nav ul li {
list-style: none;
display: inline-block;
width: 24%;
font-size: 18px;
}
Here you can see the code: http://jsfiddle.net/LQSK3/1/
I can't get display: inline; working there for every li element.
Also got the problem width the line.png image, as it's height is the same as the font height, I want it to has 35px height with margin left and right set to 5px.
Where is the problem?
You need to update your style sheet. Please add this new style:
#menu {
position: relative;
clear: both;
top: -3px;
background-color: coral;
border: 1px solid black;
width: 800px;
height: 35px;
float:left;
}
li { display: inline;float:left; }
#menu ul {
position: absolute;
font-family: Century Gothic, sans-serif;
font-size: 14px;
list-style-type: none;
padding: 0;
margin: 9px 0 0 123px;
width: 649px;
height: 39px;
color: #FFF;
float:left;
}
a { font-weight: bold; color: red; text-decoration: none; }
a:hover { text-decoration: underline; }
#menu a {
background: url('http://i.imgur.com/rzNj0.png') top right no-repeat;
width: 65px;
height: 18px;
float: left;
margin: 0px 5px;
}
You need to add float: left; to menu div,ul,li and a . Also should set width and height and margin of the a tag.
Here is a working sample : http://jsfiddle.net/YjeBs/
Hope this helps :)
EDIT:
If you want your line to extend from top to bottom of the menu div you can change your styles to:
#menu {
position: relative;
clear: both;
top: -3px;
background-color: coral;
border: 1px solid black;
width: 800px;
height: 35px;
float:left;
}
li {
float: left;
height: 35px;
display:inline;
}
#menu ul {
color: #FFFFFF;
float: left;
font-family: Century Gothic,sans-serif;
font-size: 14px;
height: 35px;
list-style-type: none;
margin: 0 0 0 123px;
padding: 0;
position: absolute;
width: 649px;
}
a { font-weight: bold; color: red; text-decoration: none; }
a:hover { text-decoration: underline; }
#menu a {
background: url("http://i.imgur.com/rzNj0.png") no-repeat scroll right top transparent;
float: left;
height: 29px;
margin: 0 5px;
padding-top: 8px;
width: 65px;
}
Hope this is you want :)
just change li { diplay: inline; } with li { display: inline; } it works.