Position and height of elements inside li - css

I currently have two problems with a list of links.
First of all I need to display
| button | | text | | button |
side by side in the li. First button left hand side, then the text and the 2nd button on the right hand side of the li. Both buttons need to have the same height as the text in the middle has.
BUT they must not be as high as the whole li is, because the li can contain more elements, like a submenu, and then it would become much to high.
Any ideas (aside from a table per li)?
Thanks a lot for any help. It does look so simple (and I guess it is) but I am really getting frustrated meanwhile cause I didn't get it done...
button {
border: solid 1px #ccc;
}
a {
display: inline-block;
margin-right: 0;
background-color: #ffffff;
margin-left: 0;
}
.btn-left {
display: inline-block;
position: absolute;
top: 0;
left: 0;
width: 40px;
height: 100%;
border-right: solid 1px #333;
}
.btn-right {
position: absolute;
top: 0;
right: 0;
width: 40px;
height: 100%;
border-left: solid 1px #333;
}
ul {
border: solid 1px #333;
list-style-type: none;
padding: 0;
}
li {
background-color: #ccc;
position: relative;
}
li a {
display: inline-block;
}
.clearfix {
clear: both;
}
<ul>
<li>
<button class="btn-left">Btn 1</button>
<a href="#">
Lorem ipsum dolur sit Link Lorem ipsum dolur sit Lorem ipsum dolur sit Link Lorem ipsum dolur sit Lorem ipsum dolur sit Link Lorem ipsum dolur sit
</a>
<button class="btn-right">Btn 2</button>
<!-- here can be other content, e.g. a submenu:
<ul class="sub-menu">
<li>Lorem ipsum</li>
<li>dolor sit</li>
</ul>
-->
</li>
</ul>

Related

Button text to wrap like inline spans

Is it possible to wrap button text next to a span? So that the button appears over multiple lines.
E.g:
div {
background-color: #ccc;
padding: 10px;
width: 150px;
}
button {
border: 0;
background: transparent;
}
<div>
<span>Lorem ipsum dolor sit amet </span><button>Button with a long label</button>
</div>
In the case above the button text should continue as though it were part of the text, similar to a link.
display:contents; can do this but you may lose more than what you will win (it can break the accessibility as well)
div {
background-color: #ccc;
padding: 10px;
width: 150px;
}
button {
border: 0;
background: transparent;
display:contents;
}
<div>
<span>Lorem ipsum dolor sit amet </span><button><span>Button with a long label</span></button>
</div>
Button is always rendered by the browser as inline-block. So what you want is not possible without changing the button tag to something like an href.
Wrap div into container
.container {
display: flex;
justify-content: center;
width: auto;
align-items: center;
}
<div class="container">
<span>Lorem ipsum dolor sit amet </span><button>Button with a long label</button>
</div>

Checkbox checked on load without active components (js, jquery etc.)

I put a simple accordion into a a simple responsive website based on bootstrap.
<div class="container">
<div class="row">
<div class="accordion">
<!--<h1>Descirption</h1>-->
<ul class="features_list">
<li>
<input type="checkbox" checked>
<i></i>
<h2>Lorem ipsum dolor sit amet</h2>
<p>sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren,</p>
</li>
Works fine, ok. But now I want to some of the accordions be opened on load, while some of them stay closed. Just in CSS.
Any ideas?
Thanks so far.
You can set first checkbox in the accordion checked and the other checkbox remain unchecked. Then in css add the behaviour to open the accordion which are checked.
------------- HTML ------------
<div id="wrapper">
<ul>
<li>
<input type="checkbox" >
<i></i>
<h2>What is Lorem Ipsum ?</h2>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</li>
<li>
<input type="checkbox" checked>
<i></i>
<h2>Why do we use it ?</h2>
<p>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).</p>
</li>
<li>
<input type="checkbox" checked>
<i></i>
<h2>Wher we can it ?</h2>
<p>There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc.</p>
</li>
</ul>
</div>
------- CSS ------
body {
width: 100%;
height: 100%;
background-color: #eeeeee;
font-family: 'Poiret One', cursive;
color: rgba(48, 69, 92, 0.8);
}
#wrapper {
min-height: 0;
display: inline-block;
position: relative;
left: 50%;
margin: 50px 0;
transform: translate(-50%, 0);
background-color: #fefffa;
max-width: 450px;
padding: 30px;
}
h1,
h2 {
color: #000000;
}
h1 {
margin: 10% auto 0;
text-transform: uppercase;
font-size: 36px;
line-height: 42px;
letter-spacing: 3px;
font-weight: 100;
text-align: center;
display: table;
padding: 10px 0;
font-weight: bolder;
border-bottom: 2px solid #000;
}
h2 {
font-size: 26px;
line-height: 34px;
font-weight: 300;
letter-spacing: 1px;
display: block;
background-color: #fefffa;
margin: 0;
cursor: pointer;
}
p {
color: rgba(48, 69, 92, 0.8);
font-size: 17px;
line-height: 26px;
letter-spacing: 1px;
position: relative;
overflow: hidden;
max-height: 800px;
opacity: 1;
transform: translate(0, 0);
margin-top: 14px;
z-index: 2;
transition: all 500ms ease;
}
p,
ul li i:before,
ul li i:after {
transition: all 0.25s ease-in-out;
}
ul {
list-style: none;
padding: 0;
margin: 0;
}
ul li {
position: relative;
padding: 0;
margin: 0;
padding-bottom: 4px;
padding-top: 18px;
border-top: 1px dotted #dce7eb;
}
ul li i {
position: absolute;
transform: translate(-6px, 0);
margin-top: 9px;
right: 0;
}
ul li i:before,
ul li i:after {
content: "";
position: absolute;
background-color: #000000;
width: 3px;
height: 16px;
}
ul li i:before {
transform: translate(2px, 0) rotate(45deg);
}
ul li i:after {
transform: translate(2px, 0) rotate(-45deg);
}
ul li input[type=checkbox] {
position: absolute;
cursor: pointer;
width: 100%;
height: 100%;
z-index: 1;
opacity: 0;
}
ul li input[type=checkbox]:checked ~ p {
margin-top: 0;
max-height: 0;
opacity: 0;
transform: translate(0, 50%);
}
ul li input[type=checkbox]:checked ~ i:before {
margin-top: 9px;
height: 9px;
transform: translate(2px, 0) rotate(45deg);
}
ul li input[type=checkbox]:checked ~ i:after {
margin-top: 9px;
height: 9px;
transform: translate(-2px, 0) rotate(-45deg);
}
Here is a working fiddle

Chrome/Firefox difference with negative margin bottom percentage

I have a difference of box sizing interpretation between webkit and Firefox using height 100% on a parent.
HTML:
<header>
Lorem ipsum dolor amet
</header>
<div class="wrapper">
<div class="content">
My background depends on my ancestor sibling
</div>
</div>
<div class="red">
<p class="white">
Amet ipsum dolor
</p>
</div>
CSS:
header {
height: 150px;
background: #fff;
}
.red {
background: red;
padding: 6em 0;
}
.content {
background: rgba(28,28,28, .3);
margin-bottom: -100%;
}
.wrapper {
position: relative;
height: 100%;
}
p.white {
background: #fff;
width: 70%;
margin: 0 auto;
}
JS fiddle here https://jsfiddle.net/m1fobvwv/
Result on Chrome (expected):
Wrong result on FF:
A colleague of mine found a workaround:
Add position: absolute; width: 100%; to .content
Updated fiddle https://jsfiddle.net/m1fobvwv/3/

Removing white-space between nav-bar items

My navbar is based off an un-ordered list.
Each <li> is displayed as inline-block.
However I am unable to get rid of the white-space between the li's
nav-item li{
width: 123px;
height: 120px;
display: inline-block;
padding: 0;
margin: 0;
}
I have researched this item on stackoverflow/google but haven't found an solution yet.
Plnkr here:
http://plnkr.co/edit/7irazgvxqkpCeurnQ0Yv
Change display: inline-block; to float: left;:
nav-item li{
width: 123px;
height: 120px;
float: left;
padding: 0;
margin: 0;
}
Remove the white space and line breaks in your HTML between the LIs.
<ul>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</li><li>Aliquam tincidunt mauris eu risus.</li><li>Vestibulum auctor dapibus neque.</li>
</ul>
Add white-space: normal; to your nav-item class
.nav-item li{
width: 123px;
height: 120px;
display: inline-block;
padding: 0;
margin: 0;
white-space: normal;
}

vertical align pseudo element in list navigation

I've created a list style navigation and each hyperlink can be multiple lines, after each hyperlink element I added a pseudo element 'arrow' after, would it be possible to align the pseudo element vertically regardless of the hyperlink height?
The requirement would be for this to work in IE8 & above.
The Mark-up:
<ul>
<li>
<a href="#">
<h3 class="title">Cover</h3>
<p class="subtitle">Lorem ipsum dolor sit</p>
</a>
</li>
<li class="current">
<a href="#">
<h3 class="title">Lorem ipsum dolor sit amet</h3>
<p class="subtitle">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Maiores cum!</p>
</a>
</li>
<li>
<a href="#">
<h3 class="title">Lorem ipsum dolor sit amet, consectetur</h3>
<p class="subtitle">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Perspiciatis. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Perspiciatis.</p>
</a>
</li>
<li>
<a href="#">
<h3 class="title">Lorem ipsum dolor sit amet, consectetur adipisicing Lorem ipsum dolor sit.</h3>
</a>
</li>
</ul>
The CSS:
body {
background: #666;
padding: 5em;
}
ul {
background: #fff;
list-style: none;
}
li {
border-bottom: 1px solid #ccc;
position relative;
}
.current a {
border-color: #000;
}
a {
border-left: 8px solid #ccc;
overflow: hidden;
display: block;
line-height: 1.3;
padding: .75em;
position: relative;
text-decoration: none;
color: #000;
}
a:after {
content: '>';
color: #ce4300;
float: right;
font-size: 1.125em;
line-height: 1;
position: absolute;
right: 1em;
}
h3 {
float: left;
font-size: .875em;
margin: 0 1em 0 0;
}
.subtitle {
color: #555;
clear: left;
float: left;
font-size: .875em;
font-style: itatlic;
}
The current prototype:
http://jsfiddle.net/yVJbL/
Here you go:
a:after {
content:'>';
color: #ce4300;
font-size: 1.125em;
position: absolute;
line-height: 0;
right: 1em;
top: 50%;
bottom: 50%;
}
Surprisingly simple :D
I thing best solution to make all browsers happy is to use a background-image (this little arrow won't be so big image) and background-position: right center (or so). You are open to hover efect with this solution as well. Background image can be placed also in padding area so there won`t be any overflow.
Hope this helps you.

Resources