I'm redesigning the fixtures section of our football teams page at the moment and would like to add functionality for clicking on the fixutre (most likely the date) and it then 'expands' and shows details of the fixture.
The details to be shown include kickoff time, sponsors and scorers etc....
I will be modifying the previous code for the actual expanding but for the life of me I can't work out why the Div to display this is being confinded to the width of the first div within the li tag.
The div is after the closing of the li so I though that would have stopped that happening. Hopefully makes sense, code below:
<ul>
<li>
<div class="cell"><span><a>July 7th</a></span></div>
<div class="cell">
<span>Nairn County</span>
<span class="h-score">0</span>
<span>Inverness Caledonian Thistle</span>
<span class="a-score">3</span>
</div>
<div class="cell"><span>Friendly</span></div>
</li>
<div class = "fixture-info">
<div class = "kickoff">Kickoff: <span>1930</span></div>
<div class = "match-sponsor">....</div>
.........
</div>
<!--Next Fixture-->
<li>....</li>
What I would like it to look like would be:
(No expanded)
July 7th Nairn County 1 Inverness 3 Friendly
July 14th Nairn County 1 Nairn St Ninian 2
(Expanded)
July 7th Nairn County 1 Inverness 3 Friendly
Kickoff: 1930
Match Sponsor: ......
....
July 14th Nairn County 1 Nairn St Ninan 2
July 15th ...............................
.......
How it currently looks.
July 7th Nairn ..........
Kickoff:1
930
Match Spo
nsor(s): M
adeup spon
sor
I would like the fixture info div to be the same width as the li not the first within.
Any help appreciated.
UPDATE
Have moved the div within the li tag. I am getting very different results from the suggested answers. I think this is because the previous div's are being display as table-cell to keep everything the same, inline-block knocks this out.
I've uploaded images of what is happening.
1st is inline-block styling.
2nd is the details moved inside the li tag.
3rd is how I would like it to be and how it is normally. I would like the
fixture info to the same with as the who fixture (date, fixture and type).
Simple solution:
use display: inline-block; to force those divs in the same line. Since div by default have display: block which will take the whole line.
.cell {
display: inline-block;
}
use toggleClass from jQuery:
$(document).ready(function() {
// Slide
$('ul > li').click(function() {
$(this).next('.fixture-info').toggleClass('collapsed').slideToggle('fast');
});
});
And hide all sub section first using css:
.fixture-info {
background-color: lightgray;
display: none;
}
$(document).ready(function() {
// Slide
$('ul > li').click(function() {
$(this).next('.fixture-info').toggleClass('collapsed').slideToggle('fast');
});
});
.fixture-info {
background-color: lightgray;
display: none;
}
.cell {
display: inline-block;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul>
<li>
<div class="cell"><span><a>July 7th</a></span></div>
<div class="cell">
<span>Nairn County</span>
<span class="h-score">0</span>
<span>Inverness Caledonian Thistle</span>
<span class="a-score">3</span>
</div>
<div class="cell"><span>Friendly</span></div>
</li>
<div class="fixture-info">
<div class="kickoff">Kickoff: <span>1930</span></div>
<div class="match-sponsor">....</div>
111.........
</div>
<!--Next Fixture-->
<li>
<div class="cell"><span><a> 2222 July 7th</a></span></div>
<div class="cell">
<span>Nairn County</span>
<span class="h-score">0</span>
<span>Inverness Caledonian Thistle</span>
<span class="a-score">3</span>
</div>
<div class="cell"><span>222 Friendly</span></div>
</li>
<div class="fixture-info">
<div class="kickoff">222 Kickoff: <span>1930</span></div>
<div class="match-sponsor">....</div>
2222.........
</div>
</ul>
Move the
<div class = "fixture-info">
<div class = "kickoff">Kickoff: <span>1930</span></div>
<div class = "match-sponsor">....</div>
.........
</div>
inside the li
then use something like
var li = document.getElementsByTagName('li');
li.addEventListener('click', expandFunction);
function expandFunction() {
this.classList.add('expanded');
}
//SCSS
li {
height: auto;
.fixture-info {
height: 0;
transition: all 0.25s ease-out;
}
&.expanded {
.fixture-info {
height: 80px; //height value of expanded box
}
}
}
Here's a pure html+css solution if you're not too familiar with javascript. The only downside to using the show/hide checkbox maneuver is having to label each one of your label/inputs so they don't have to toggle one another ( see html, toggle1, toggle2, etc).
Outside of this I'd recommend the the 'toggleClass' jQuery solution from the other answer.
ul {
list-style: none;
margin: 0 0 20px;
}
ul li {
color: #2B91AF;
margin: 0 0 10px;
}
ul li span a,
ul li span[class*='-score'] {
color: red;
}
ul li .cell {
display: inline-block;
}
input[type=checkbox],
ul li .fixture-info {
display: none;
}
input[type=checkbox]:checked+.fixture-info {
display: block;
}
<ul>
<li>
<label for="toggle1">
<div class="cell"><span><a>July 7th</a></span></div>
<div class="cell">
<span>Nairn County</span>
<span class="h-score">0</span>
<span>Inverness Caledonian Thistle</span>
<span class="a-score">3</span>
</div>
<div class="cell"><span>Friendly</span></div>
</label>
<input id="toggle1" type="checkbox">
<div class="fixture-info">
<div class="kickoff">Kickoff: <span>1930</span></div>
<div class="match-sponsor">Match Sponsor: ....</div>
</div>
<li>
<li>
<label for="toggle2">
<div class="cell"><span><a>July 7th</a></span></div>
<div class="cell">
<span>Nairn County</span>
<span class="h-score">0</span>
<span>Inverness Caledonian Thistle</span>
<span class="a-score">3</span>
</div>
<div class="cell"><span>Friendly</span></div>
</label>
<input id="toggle2" type="checkbox">
<div class="fixture-info">
<div class="kickoff">Kickoff: <span>1930</span></div>
<div class="match-sponsor">Match Sponsor: ....</div>
</div>
<li>
</ul>
Don't put any elements between the "li" tags
Here is a possible way of organizing the HTML
<ul>
<li>
<div class="cell"><span><a>July 7th</a></span>
<span>Nairn County</span>
<span class="h-score">0</span>
<span>Inverness Caledonian Thistle</span>
<span class="a-score">3</span>
<span>Friendly</span>
</div>
<ul>
<li>
<div class = "fixture-info">
<div class = "kickoff">Kickoff: <span>1930</span></div>
<div class = "match-sponsor">....</div>
.........
</div>
</li>
</ul>
</li>
<!--Next Fixture-->
<li>....</li>
<ul>
Related
I have the following list and want to add another element to list element with Name. So I am adding Primary User but want the new element Primary User styled to the right of the line. What's the best way to do this? Is it awkward doing this to a list item? Thanks.
<div class="panel-heading">Company Details</div>
<ul class="list-group">
<li class="list-group-item"><b>Name:</b> <%= #company.name %><b>Primary User:</b><%= #company.primary %></li>```
One possibility would be to use float right. Don't know if it is the best one and there are probably plenty others, but it will work.
HTML
<div class="panel-heading">Company Details</div>
<ul class="list-group">
<li class="list-group-item">Name: Test1 <span class="user">User: Test</span>
</li>
<li class="list-group-item">Name: Test1 <span class="user">User: Test</span>
</li>
<li class="list-group-item">Name: Test1 <span class="user">User: Test</span>
</li>
</ul>
CSS
.user {
float: right;
}
.list-group {
width: 250px;
}
https://jsfiddle.net/zy7d48ub/
Wrap your code inside this div wrapper and it should work.
<div class = "panel-heading-wrapper" style = "display: flex;">
I find myself using (maybe overusing?) css grid a lot for layouts such as this. It has so much flexibility for fine-tuning the layout. My approach would be:
<div class="panel">
<div class="panel-heading">
Company
</div>
<div class="name">
Name
</div>
<div class="user">
User
</div>
</div>
.panel {
display: grid;
grid-template-columns: 100px 100px;
grid-template-rows: 20px 20px;
grid-template-areas: 'heading heading''name user'
}
.panel-heading {
grid-area: heading;
}
.name {
grid-area: name;
}
.user {
grid-area: user;
}
here's what it looks like on jsfiddle
I have a dynamic page that displays multiple pages and has a class that starts with 'paged-' and the number of that page. I want to remove a div with SASS when it's on the page 2 and beyond like this:
.paged-2, .paged-3, .paged-4, .paged-5, .paged-100{
.removeonpagetwoandso{
display: none;
}
}
But I don't want to write from paged-2 to paged-100 since I don't know how many pages it will have in the future.
This doesn't work:
div[class^='paged'], div[class*='paged-']{
.removeonpagetwoandso{
display: none;
}
}
EDIT: Added HTML Structure
Page 1:
<body class="home">
<div class="removeonpagetwoandso">Home Page 1 Only</div>
</body>
Page 2 and so:
<body class="home paged-2">
<div class="removeonpagetwoandso">Home Page 1 Only</div>
</body>
SASS compile
div[class^='paged'],
div[class*='paged-']{
.removeonpagetwoandso{
display: none;
}
}
to
div[class^=paged] .removeonpagetwoandso,
div[class*=paged-] .removeonpagetwoandso {
display: none;
}
In your case
div[class^='paged-'] {
.removeonpagetwoandso {
display: none;
}
}
is enough. It is compiled to
div[class^=paged-] .removeonpagetwoandso {
display: none;
}
which means
child element having removeonpagetwoandso class of elements whose class starts with paged-. I think you have problem with your html structure. You HTML must look like as follows:
<div class="paged-1">
<div class="removeonpagetwoandso">
paged-1
</div>
</div>
<div class="paged-2">
<div class="removeonpagetwoandso">
paged-2
</div>
</div>
<div class="paged-3">
<div class="removeonpagetwoandso">
paged-3
</div>
</div>
<div class="paged-4">
<div class="removeonpagetwoandso">
paged-4
</div>
</div>
<div class="paged-5">
<div class="removeonpagetwoandso">
paged-5
</div>
</div>
<div class="paged-100">
<div class="removeonpagetwoandso">
paged-100
</div>
</div>
pls try this css
<style>
div[class^="paged-"]{
.removeonpagetwoandso{
display: none;
}
}
</style>
i have tried This from stackoverflow
which i haven't been able to get to work..
i have .playlist-list and .playlist-feature where only one should be displayed, with a radio button to check on.
so which ever radio button is checked, it should display : block the div. and hide the other.
but it is somehow not working..
I can start out with .playlist-feature being displayed fine, where i check on another button. but here it does not seem to work..
any idea as to a solution to this ?
My code:
html:
<div class="playlist-top">
<label for="playlist-button">Spilleliste</label>
<label for="playlist-feature-button">Indslag</label>
</div>
<input type="radio" id="playlist-list-button" />
<input type="radio" id="playlist-feature-button" />
<div class="playlist-content">
<div class="playlist-list">
<ul class="bar">
<li>
<span>12:36</span ><p class="text- uppercase">brian adams</p><span class="dr-icon-audio-boxed"></span>
<p>You Belong to me</p>
</li>
</ul>
</div>
<div class="playlist-feature">
<ul class="bar">
<li>
<span>08:51</span><span class="dr-icon-audio-boxed"></span>
<p>Gærdesmutten er sej trods sin beskedne størrelse</p>
</li>
</ul>
</div>
</div>
My CSS
#playlist:checked ~div.playlist-toggle{
.playlist-wrapper .container .playlist-content{
.playlist-feature{
display:block;
}
}
}
#playlist-list-button:checked ~div.playlist-toggle{
.playlist-wrapper .container .playlist-content{
.playlist-list{
display:block;
}
.playlist-feature{
display:none;
}
}
}
#playlist-feature-button:checked ~div.playlist-toggle{
.playlist-wrapper .container .playlist-content{
.playlist-feature{
display:block;
}
.playlist-list{
display:none;
}
}
}
I think this one useful for you with jquery
Put this code in your header,
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<style>
.playlist-list{
display: block;
}
.playlist-feature{
display:none;
}
</style>
<script>
$(document).ready(function () {
$('input[type=radio][name=rb1]').change(function () {
if (this.value == 'playlist-list-button') {
$('.playlist-list').show();
$('.playlist-feature').hide();
}
else if (this.value == 'playlist-feature-button') {
$('.playlist-feature').show();
$('.playlist-list').hide();
}
});
});
</script>
And HTML like this
<div class="playlist-top">
<label for="playlist-button" >Spilleliste</label>
<input type="radio" value="playlist-list-button" id="playlist-list-button" name="rb1" checked="" class="rb1" />
<label for="playlist-feature-button" >Indslag</label>
<input type="radio" value="playlist-feature-button" id="playlist-feature-button" name="rb1" class="rb1"/>
</div>
<div class="playlist-content">
<div class="playlist-list">
<ul class="bar">
<li>
<span>12:36</span ><p class="text- uppercase">brian adams</p><span class="dr-icon-audio-boxed"></span>
<p>You Belong to me</p>
</li>
</ul>
</div>
<div class="playlist-feature">
<ul class="bar">
<li>
<span>08:51</span><span class="dr-icon-audio-boxed"></span>
<p>Gærdesmutten er sej trods sin beskedne størrelse</p>
</li>
</ul>
</div>
</div>
i got it to work with this:
because the playlist-content is right under the input, it seems it could access it through that. so i could display the div and hide it at will.
and the class on .playlist-button was wrong.. it should have been .playlist-list-button.. no idea why i didn't see that before..
#playlist-feature-button:checked ~ div.playlist-content {
.playlist-feature {
display: block;
}
.playlist-list {
display: none;
}
}
Here is my code:
a) I have a row of buttons at the top formatted horizontally as such:
HTML:
<ul class="nav">
Work
Volunteer
Education
Skills
References
Images
</ul>
b) I have div blocks each displaying a paragraph:
<div class="jobs">
<h2>text</h2>
<h3>text</h3>
<h4>text</h4>
</div>
c) I want the CSS to not display the jobs div yet:
.jobs {
display: none;
}
d) Now that I hover over the first button I want the jobs div to display:
.button1:hover+.jobs {
display: block
}
e) Repeat for all other div sections
.volunteer {
display: none;
}
.button2:hover+.volunteer {
display:block
}
You will need to markup HTML differently.
.jobs, .volunteer {
display: none;
}
.button1:hover+.jobs, .button2:hover+.volunteer {
display: block;
/* position the divs under the navigation links */
position: absolute;
top: 120px;
}
<ul class="nav">
<li>
Work
<div class="jobs">
<h2>h2 jobs</h2>
<h3>h3 jobs</h3>
<h4>h4 jobs</h4>
</div>
</li>
<li>
Volunteer
<div class="volunteer">
<h2>h2 volunteer</h2>
<h3>h3 volunteer</h3>
<h4>h4 volunteer</h4>
</div>
</li>
<li> Education</li>
<li> Skills</li>
<li> References</li>
<li> Images</li>
</ul>
This is impossible, as described, with your current HTML, with only HTML and CSS (though only perhaps until the reference and :matches() pseudo-selectors arrive). However, if, rather than :hover you'd be willing to work with clicks on the list-elements, it can be done (without JavaScript). Given the corrected HTML:
<ul class="nav">
<li>Work
</li>
<li> Volunteer
</li>
<!-- and so on... -->
</ul>
<div id="details">
<div id="jobs"></div>
<div id="volunteer"></div>
<!-- and so on... -->
</div>
The following CSS will show the relevant div element once the <a> element has been clicked on (note that the use of an id is essential for this to work):
#details > div {
/* to hide the eleemnt(s) initially: */
display: none;
}
#details > div:target {
/* to show the relevant element once the relevant link is clicked: */
display: block;
}
#details > div[id]::after {
content: attr(id);
}
#details > div {
display: none;
}
#details > div:target {
display: block;
}
<ul class="nav">
<li>Work
</li>
<li> Volunteer
</li>
<li> Education
</li>
<li> Skills
</li>
<li> References
</li>
<li> Images
</li>
</ul>
<div id="details">
<div id="jobs"></div>
<div id="volunteer"></div>
<div id="education"></div>
<div id="skills"></div>
<div id="references"></div>
<div id="images"></div>
</div>
With plain JavaScript, on the other hand, it can be achieved with:
// the 'e' argument is automatically to the function by addEventListener():
function toggleRelevant (e) {
// caching the 'this' element:
var self = this,
// finding the div element with a class equal to the href of the 'a' element
// (though we're stripping off the leading '#':
relevantElement = document.querySelector('div.' + self.getAttribute('href').substring(1) );
// if the event we're responding to is 'mouseover' we set the display of the
// found div to 'block', otherwise we set it to 'none':
relevantElement.style.display = e.type === 'mouseover' ? 'block' : 'none';
}
// finding all the a elements that are in li elements:
var links = document.querySelectorAll('li a');
// iterating over those a elements, using Array.prototype.forEach:
[].forEach.call(links, function(linkElem){
// adding the same event-handler for both mouseover and mouseout:
linkElem.addEventListener('mouseover', toggleRelevant);
linkElem.addEventListener('mouseout', toggleRelevant);
});
function toggleRelevant(e) {
var self = this,
relevantElement = document.querySelector('div.' + self.getAttribute('href').substring(1));
relevantElement.style.display = e.type === 'mouseover' ? 'block' : 'none';
}
var links = document.querySelectorAll('li a');
[].forEach.call(links, function(linkElem) {
linkElem.addEventListener('mouseover', toggleRelevant);
linkElem.addEventListener('mouseout', toggleRelevant);
});
div[class] {
display: none;
}
div[class]::before {
content: attr(class);
color: #f00;
border: 1px solid #f00;
padding: 0.2em;
}
<ul class="nav">
<li>Work
</li>
<li> Volunteer
</li>
<!-- and so on... -->
</ul>
<div class="jobs">
<h2>text</h2>
<h3>text</h3>
<h4>text</h4>
</div>
<div class="volunteer">
<h2>text</h2>
<h3>text</h3>
<h4>text</h4>
</div>
<!-- and so on... -->
I don't think this is do able in css since display blocks (job, volonteer, ...) and button are not parent. But in jQuery this is fairly simple :
$('.buttonX').hover(
function() {
// Styles to show the box
$('.boxX').css(...);
},
function () {
// Styles to hide the box
$('.boxX').css(...);
}
);
It sounds like you're trying to do some kind of a tab menu where pressing a specific button shows a different content. Here's a SO page that describes how it's done: How to make UL Tabs with only HTML CSS
I am having issues with the document flow when floating a div to the left and another div to the right.
Both divs left and right are aligned perfectly horizontally with one another. (Menu Item name and menu item price)
However the following Menu Category Name (Burgers) and Menu Category description is starts all the way on the top. Right below the first Menu Category (Breakfast)
I have set Menu Item Name Div to float left and clear left. I did the same with menu item price, but instead I floated right and clear right.
The "Burgers" category and its description needs to show below the last menu item name and price which is. "Oatmeal 3.50"
Doesn't the burgers category needs to follow normal document flow when clearing broth divs?
I have tried changing the .menu_item_name css to display as inline_block , that solved the issue but the menu prices wouldn't line up with the menu items.
Can you guys please help me resolve this issue? I would much appreciate it.
Below is a link to a js fiddle example.
http://jsfiddle.net/eldan88/NkH74/
<style>
#menu_container {
width: 750px;
margin-left: auto;
margin-right: auto;
}
#menu_left_wrapper {
width: 350px;
float: left;
clear: left;
padding-right: 25px;
border-right:thick solid #ff0000;
}
#menu_right_wrapper {
width: 350px;
float: right;
clear: right;
}
.menu_item_name a {
float: left;
clear: left;
}
.menu_item_price {
float: right;
clear: right;
}
</style>
HTML:
<div id='menu_left_wrapper'>
<div class='menu_category'>Breakfast</div>
<div class='menu_item_name'>
<a href='/menus/item-detail.php' > H&H Bagel </a>
</div>
<div class='menu_item_price'>
1.00<img class='item_image' src='21404.jpg' width='15px' height='15' />
</div>
<div class='menu_item_name'>
<a href='/menus/item-detail.php' > One Egg Sandwich </a>
</div>
<div class='menu_item_price'>1.75</div>
<div class='menu_item_name'>
<a href='/menus/item-detail.php' > Breakfast Platter </a>
</div>
<div class='menu_item_price'>4.25</div>
<div class='menu_item_name'>
<a href='/menus/item-detail.php' > Create your own egg sandwich </a>
</div>
<div class='menu_item_price'>3.25</div>
<div class='menu_item_name'>
<a href='/menus/item-detail.php' > Two Pancakes and Two Eggs </a>
</div>
<div class='menu_item_price'>4.75</div>
<div class='menu_item_name'>
<a href='/menus/item-detail.php' > Oatmeal </a>
</div>
<div class='menu_item_price'>3.50</div>
<div class='menu_category'>Burgers</div>
Our certified Angus beef burgers are grilled to order and served on a toasted brioche bun with lettuce and tomato, pickles and red onion upon request
<div class='menu_category'>Mexican Quesadillas</div>
<div class='menu_category'>Salad </div>
<div class='menu_category'>Cold Beverages</div>
</div>
This is all you need: http://jsfiddle.net/NkH74/2/
<div class='menu_item_name'>
<a href='/menus/item-detail.php'> H&H Bagel </a>
<span class="menu_item_price">1.00</span>
</div>
#menu_left_wrapper {
width: 350px;
padding-right: 25px;
border-right:thick solid #ff0000;
}
.menu_item_name span{
float:right;
}
really.
What I did is I used a common parent for both the link and price.
Try inserting a clearing div above Menu Category Name:
<div class="clr"></div>
.clr { width: 100%; height: 0; clear: both; }
simply you can insert a new div with clear before the Burgers Category
<div id='menu_left_wrapper'><div class='menu_category'>Breakfast</div>
<div class='menu_item_name'><a href='/menus/item-detail.php' > H&H Bagel </a></div><div class='menu_item_price'>1.00<img class='item_image' src='21404.jpg' width='15px' height='15' /></div>
<div class='menu_item_name'><a href='/menus/item-detail.php' > One Egg Sandwich </a></div><div class='menu_item_price'>1.75</div>
<div class='menu_item_name'><a href='/menus/item-detail.php' > Breakfast Platter </a></div><div class='menu_item_price'>4.25</div>
<div class='menu_item_name'><a href='/menus/item-detail.php' > Create your own egg sandwich </a></div><div class='menu_item_price'>3.25</div>
<div class='menu_item_name'><a href='/menus/item-detail.php' > Two Pancakes and Two Eggs </a></div><div class='menu_item_price'>4.75</div>
<div class='menu_item_name'><a href='/menus/item-detail.php' > Oatmeal </a></div><div class='menu_item_price'>3.50</div>
<div style="clear: both;"></div>
<div class='menu_category'>Burgers</div>
Our certified Angus beef burgers are grilled to order and served on a toasted brioche bun with lettuce and tomato, pickles and red onion upon request
<div class='menu_category'>Mexican Quesadillas</div>
<div class='menu_category'>Salad </div>
<div class='menu_category'>Cold Beverages</div>
</div>
I updated your fiddle and I think everything lines up as expected. It's not elegant but it works.
http://jsfiddle.net/mlnmln/WG5TK/2/
CSS:
.menu_item_name {
float: left;
clear: left;
}
.menu_item_price {
text-align: right;
}
Doesn't the burgers category needs to follow normal document flow when clearing broth divs?
The burger category itself doesn't follow normal document flow because you need to clear after an element, not within it to restore normal flow.
Bonus points: As others have stated it would probably be better to wrap .menu_item_name and .menu_item_price in a parent element and apply a clearfix.(What methods of ‘clearfix’ can I use?).