I have code sort of like this:
<div class="right_col">
<div class="right_box">
<div class="other_div">text</div>
text etc
</div>
<div class="right_box">
<div class="other_div">text</div>
text etc
</div>
<div class="right_box">
<div class="other_div">text</div>
<div class="anotherother_div">text</div>
text etc
</div>
<div class="right_box">
text etc
</div>
</div>
So a main div with other divs inside which may or may not contain additional divs.
What I want to do is style them so "right_box" has alternate background colours.
The problem is that I am selecting the interior divs/taking them into account when doing odd/even etc.
This is the CSS I've tried:
.right_col .right_col:nth-child(even) {background:red}
.right_col .right_col:nth-child(0n+1) {background:red}
Any ideas where I'm going wrong?
You should be using nth-of-type() rather then nth-child().
Here's an awesome article on CSS-Tricks by Chris Coyer which explains the difference between the two.
Related
I have a problem, maybe it's obvious, but I couldn't find any answers how to do this.
I have a structure like this on my website:
<div class="row-even">
<article class="featured-job">a</article>
</div>
<div class="row-odd">
<article class="featured-job">b</article>
</div>
<div class="row-even">
<article class="regular-job">a</article>
</div>
<div class="row-odd">
<article class="regular-job">b</article>
</div>
<div class="row-even">
<article class="regular-job">c</article>
</div>
This tiny thing is generated by PHP for listing some articles from two types, a Featured job, and a Regular job. I want to separate these two content types by adding a margin-top for the first one of the .regular-job articles. I tried using first-line, first-child, first-of-type, all from the first-* and even tried nth-child, but nothing worked for me.
(I know these separators working on the parent of the element I am using on.)
Is there any way it can be done?
The problem with first-child and regular-job is that the articles are not directly in the same parent because they are nested in row-even & row-odd. You either could wrap the regular-job rows in another div which gets the margin applied or add another class to the first row containing a regular-job. You could even add a class directly to the first regular-job.
I don't know how you PHP loop looks like, but maybe try to use a counter for that matter.
If needed I will gladly provide an HTMl/CSS example!
You would probably want to do someting like that:
div:first-child .regular-job {
margin-top: 20px;
}
You select the first parent element that has the child of .featured-job.
PS. Be careful where you are applying the margin, it won't work on inline elements or if you want to separate the parent elements then applying it to the article is not a good idea.
As Sven says, the problem is that you need the elements to be siblings for this selectors to work.
Set a class in the parent, matching the one of the child:
HTML
<div class="row-even featured-father">
<article class="featured-job">a</article>
</div>
<div class="row-odd featured-father">
<article class="featured-job">b</article>
</div>
<div class="row-even regular-father">
<article class="regular-job">a</article>
</div>
<div class="row-odd regular-father">
<article class="regular-job">b</article>
</div>
<div class="row-even regular-father">
<article class="regular-job">c</article>
</div>
Then, it is easy to set the CSS. for instance:
.featured-father + .regular-father article {
background-color: red;
}
fiddle
while iterating in the PHP, add another dummy class with index.
Then it will be a piece of cake to make your custom class:
<div class="row-even featured_1">
<article class="featured-job">a</article>
</div>
<div class="row-odd featured_2">
<article class="featured-job">b</article>
</div>
<div class="row-even regular_1">
<article class="regular-job">a</article>
</div>
<div class="row-odd regular_2">
<article class="regular-job">b</article>
</div>
<div class="row-even regular_3">
<article class="regular-job">c</article>
</div>
notice the two introduced classes: featured_X and regular_X.
then:
.regular_1{
margin-top:50px;
}
I'm having some issues with my CSS on a transform fold out on hover style element. At the moment it folds out too much and I'd like to reduce the height. I've tried several things to no avail. I was able to find the code itself from a demo located here: http://lab.aqro.be/fb_btn_concept.html
I've tried adjusting a lot of the #under div parameters but so far every time I get the hover state the way I want it the transition messes up and doesn't look right. I'm not very familiar with transitions so I'm hoping somebody on here can help? Here is my jsfiddle:
http://jsfiddle.net/HD2pm/
My goal is to have the fold out be around 100px in height instead of the obviously much larger version that it is at currently.
<div class="row">
<div class="span4">
<section id="btn">
<p>Some Text Will Go Here</p>
<div id="under">
<div class="logo"><div class="recto"><i class="fa fa-user"></i>Consumer</div></div>
<div class="top"></div>
<div class="logo verso"></div>
</div>
<div id="shadow"></div>
</section>
</div>
</div>
Looks a lot better with
-webkit-perspective: 550;
http://jsfiddle.net/DrQP2/
I want to achieve the following effect using HTML & CSS:
Printscreen
However, I'm not sure if I'm doing it correctly.
The current state is the following:
<div class="post"><!-- Posts are just divs with a white background -->
<div class="post-header">
<div class="left">Som Text</div>
<div class="center">
<img src="pseudo" class="center" />
</div>
<div class="right">Som Text</div>
</div>
<p class="title">Som Text</p>
</div>
Then, I'm simply doing a margin-top:-66px; on div.post div.post-header.
This is probably not what one should do.
Can you give me an idea on how to approach this?
You Can Try Position-relative thing also, for this make post class position:relative and other class as position:absolute and set them where u want
a print screen or just a margin-top property won't do any good, since the screenshot is not displayed here too.
can u give me the link to see the live preview of the page
I did something similar on my site. Feel free to visit http://robertfauver.com/
I have a layout built using CSS display:table (inline, row, cell, etc). I'm doing local development on it with apache, and when I refresh the page, two of the div containers are incorrectly lined up. However, if I uncheck and re-check display:table-row, they correct themselves, and the page displays correctly.
http://jsfiddle.net/fNNKT/
You can see the HTML and CSS at the jsFiddle above. It's actually not working there either, so maybe I'm doing something wrong, and can use help with that.
<div class="cabinet-container">
<div class="mode-bar">
<div class="mode-bar-left">
<div class="mode-bar-item">logo</div>
<div class="mode-bar-item active">Dispense</div>
<div class="mode-bar-item">Inventory</div>
</div>
<div class="mode-bar-right schedule">
<div class="mode-bar-item">Sign-Out</div>
</div>
</div>
<div class="table"></div>
<div class="left-container"></div>
<div class="center-container">
<div class="search-container">
<div class="table-cell">
<div class="search-field"></div>
</div>
</div>
<div class="nav-button-center-container">
<div class="table-cell">
</div>
</div>
<div class="list">
<div class="table-cell">
<div class="list-item-center-container"></div>
<div class="list-item-center-container"></div>
<div class="list-item-center-container-partial"></div>
</div>
</div>
<div class="nav-button-center-container-down-active">
<div class="table-cell"></div>
</div>
</div>
<div class="footer">
<div class="button-group table-border-5">
<div class="button-secondary">Dispense Non-Drug</div>
<div class="button-secondary">Sort By: Last Name</div>
</div>
<div class="button-group-right table-border-5">
<div class="button-primary">New Clinical Order</div>
</div>
</div>
</div>
Is your question related to .mode-bar-left and .mode-bar-right wrapping onto two lines? If so, the problem relates to whitespace. Think of two images displayed inline, side by side. If there's whitespace between the tags in the code, there will be whitespace displayed in the browser.
Solution #1:
Take your logic one level higher up in the DOM. Change the display value for both mode-bar elements to table-cell (instead of the current inline-table). Then change the .mode-bar-item elements to display: inline-block (instead of table-cell).
Solution #2:
A faster, less elegant solution is to add float: left to .mode-bar-left.
On the topic of elegance, I strongly recommend that you consider some more semantically meaningful tags than just div. For example, .mode-bar-left is clearly a list (ul perhaps?) and the .mode-bar-item elements are clearly list items (li).
Are you using any javascript/jQuery? On a recent project of my own, I was having a similar issue and all I had to do was move my custom lightbox script from the to right before the tag, and it seemed to fix the issue. Sometimes javascript can be wonky like that. I don't understand why, but that's the way it is.
I've got problem with paragraph on my website: naprawiamy.za.pl. As u can see there is a big white space in the text. What's that and how it got there? Could somebody tell me?
This happen because the above div contains img that have float:left. So there is need to clear the float. Add overflow:hidden for the div with img tags and will fix the text below.
Your code is written as:
<div id="main">
<div>
<img src="lol.png" id="logo" alt="logo serwisu">
//more images
</div>
<div id="story" >
Your Text
</div>
</div>
Set the CSS Property float:left for
1. <div style="float:left">
2. <div id="story" style="float:left">