CSS - Customising heading settings - css

The basic idea is that I have a sidebar div tag that I have been tweaking with the CSS, and I want to do everything in the same place:
.sidebar{
border: solid;
float:left;
margin-right:-100px;
margin-top: -200px;
width:200px;
}
.sidebar h2{text-decoration:underline}
This is what the code looks like right now and it technically works but it looks like bad practice to me and I want to add the bottom bit that changes h2 to the main chunk on the top which has everything else in it but I don't know how to incorporate it.
I imagine that this is fairly straight forward and I'm just missing something.

I think what you're thinking about is using a CSS preprocessor that allows you to combine multiple child classes into one big class, giving it a nicer look and feel, like this:
.sidebar{
border: solid;
float:left;
margin-right:-100px;
margin-top: -200px;
width:200px;
h2
{
text-decoration:underline;
}
}
For this you can use LESS. More info on it here: LESS CSS

Related

Changing wordpress thems's CSS with media queries

I am looking to improve the style of a Wordpress site.
I have a div with the group-input class which has this style:
.group-input {
display: inline-block;
margin-bottom: 0px;
float: right;
padding-left: 10px;
text-align: right;
}
I would like that below 572 px of screen we switch to float : left so I wrote this below the previous code, in my theme's CSS file, like this:
.group-input {
display: inline-block;
margin-bottom: 0px;
float: right;
padding-left: 10px;
text-align: right;
}
#media (max-width: 572px) {
.group-input {
float: left !important;
}
}
On the other hand it does not work, the new style does not apply to my div.
suddenly I don't know how to do it. Do you have an idea, a lead to advise me?
I want some explanations, something simple for you is not necessarily obvious to me suddenly I need to understand. Thanks for your time and help.
In general, that should overwrite the css rule you are trying to do, but it's probably another css rule that more specifically targets that element. A few reasons it may not be overwriting is because:
another css rule is more specific than yours
it's in a breakpoint more specific than yours
it uses !important
A combo of all of those will require you to be even more specific in targeting the element.
If you find you are unable to overwrite a rule, try and be more specific in your targeting of the element by targeting it's grandparent/parent and working down the html tree. If you notice that that isn't working either, then try using !important.
Check the html structure around it try that. Sometimes even body .group-input might be specific enough, but the closer you specify to the element, the better off you will be.

Css performance! more duplicate or unique

In large projects...
Which one is Faster and Optimized?
Which is better for browser and traffic?
*1.
.class1,.class2{
line-height:40px;
text-align:left;
margin-left:4%;
width:34%;
float:right
}
.class2{
width:44%;
float:left
}
.class1{
line-height:40px;
text-align:left;
margin-left:4%;
width:34%;
float:right
}
.class2{
line-height:40px;
text-align:left;
margin-left:4%;
width:44%;
float:left
}
*3.
.class1,.class2{
line-height:40px;
text-align:left;
margin-left:4%;
}
.class1{
width:34%;
float:right;
}
.class2{
width:44%;
float:left;
}
*new update suggested by #connexo.
Sepas for your time!
This is how I'd do it. Put all properties both classes share in one block, then define deviating properties solo after that.
.class1,
.class2 {
line-height: 40px;
margin-left: 4%;
text-align: left;
}
.class1 {
float: right;
width: 34%;
}
.class2 {
float: left;
width: 44%;
}
Aside from that structural thing I'd recommend to sort the declarations alphabetically and do not omit the semi-colon after the last declaration in a block.
I am not sure if the question is correct. In case of CSS, I would ask how easy it will be to maintain it. When you work on bigger websites, updating 1 piece of style declarations is better than updating 10 pieces of declarations. If you are sure that class1 and class 2 behavior will always be the same, I would go with the first example. It will be easier down the road to find what exactly needs to be updated.
Both examples will not affect the performance any noticeably, also, they have nothing to do with SEO (to the best of my knowledge).
I hope this answers the question...
There are several things you should pay attention to:
1. Use shorthands
This will reduce unnecessarily used space. --> Optimized the traffic
2. Minify your code
Same as for 1.
3. Split up your CSS - Code (Critical Above the Fold CSS)
This is a very effective way to optimize your page speed. You can put the code for the first view that the user can see at the top of your page and the rest at the bottom. Then the browser can render the page, without completely downloading the page.
4. Use inline CSS
This is not the beautifulest solution, but it can impair the performance. But do not write all of your CSS inline, only some small parts.

Make search bar in bootstrap navbar flush with borders of navbar

I'm building a bootstrap WP theme and am at the stage of just building the static html. I've tried googling, but since it's hard to describe I've not had any luck. To simplify things, instead of telling you what I'm trying to do, I'll show you via very bad photoshop mockups and hopefully we can do some good together :).
I'm using the navbar snippet from http://getbootstrap.com/components/#navbar
At the moment, it looks like this:
I want it to look like this:
ive tried playing with the paddings and the margins but am coming up blank. Any help is appreciated :).
.navbar-form{
margin-top:0px;
margin-bottom:0px;
}
.navbar-form input{
min-height:50px;
border-radius:0;
}
.navbar-form button{
min-height:50px;
border-radius:0;
background:green;
color:white;
}

Gettign the last <li> element to work the way I want it to

Iam needing help with my footer in CSS.
I'm a new wordpress developer and I get the gist of how to work with it but as usual I've run into a problem, it's probably simple too, as I'm not sure exactly how to pick out the certain CSS snippets I need. I use Firebug but sometimes I just not sure whats happening with my CSS I guess.
This is my testing site so you can have a look at what I'm going to be talking about. In my footer, my last < li > element (the Archives) I'm hoping to get up right underneath Follow Us. I can always us the last child css rule however I know IE ignores that. So whats my next option? I know what to do if wordpress has given the lists individual styles but in this case it hasn't, so I'm not sure what to do.
CSS
#footer { width: 100%; height: 503px; background: url(img/FOOTER-bg.jpg) repeat-x; background-color: #821d20; position: relative; top: 100px;/*border: 1px solid #0C0;*/}
.footer-widgets { width: 960px; margin: 0px auto; padding: 0px; /*border: 1px solid #fff;*/ }
.footer-widgets li { width:280px; height: auto; list-style-image: none; list-style-position: outside; list-style-type: none; float: left; color: #fff; padding: 13px; margin-right: 10px; /*border: 1px solid #fff;*/ }
.footer-widgets li ul {color: red;}
.footer-widgets li ul li {color: #fff; margin-left: -50px; margin-top: -15px;}
What is the best way to make this work? Any help is appreciated!
If you need to support browsers that do not accept a :last-child selector then you have two options.
Manually add a class to the last element and style it.
Use javascript to find the last <li> and add a class, then style it.
[edit]
Unfortunately, the very handy lastElementChild that was introduced in the W3C Traversal Spec is also not supported in IE8/7. That leaves you, again, with two options.
Use a library like jQuery, which has very simple $('.footer-widgets li:last-child') selector
Use regular js and find the element through tedious DOM traversal.
I would say it's silly to use jQuery for this one thing, but if you will be doing other javascript stuffs on your site, might as well use jQuery, right? Otherwise, I would stay away from the DOM traversal as it's just a pain. Just manually put a class on the last <li> and be done with it :)
There are 2 alternatives I see:
Add a class to your last element and take it with JavaScript to do your own manipulation.
Use jQuery to get the nested elements (unnecessary I think).
Example:
$('.yourElement').css('property', 'value')
Complement:
Getting any element with JavaScript:
var x = document.getElementById("id");
I suggest you to take a look at this W3C documentation with an example. Right after you get the element with JavaScript comes manipulation anyway you need it.
I think it may help you!

Best way to accomplish knocked-out rule in CSS

Ive been handed a design that has a particular header with style the type knocking out a rule like:
------ Text Content ------
Ive done this a couple times over the years but i was never happy with my solution. Usually it involved using numerous elements. Since these are headers id like to keep the markup as lean as possible.
My first thought this time around was to use box collapsing to my advantage: http://jsfiddle.net/cEcCL/
However there a are few problems here:
This relies on setting the background of the span to something opaque in order to knockout the line. Problem is most of these will probably be in the upper portion of the page where the gradient background hasnt yet faded to its solid
Actually i wasnt aware of this till i made the fiddle - the text seems slightly off center, not sure why that is.
While it can probably be managed, Im worried about the robustness of the vertical offsets to center the line on the median of the text line-box.. What if i have long header that goes to 2 lines?
Does anyone have any other ideas?
Here's a very quick example that uses a single h2 and the before/after pseudo elements.
h2:before, h2:after {
content:' '; display:inline-block;
height:0; width:100px;
border-top:1px solid black;
vertical-align:middle;
margin:0 1em
}
Obviously, there are some drawbacks:
No IE6/7 support
As it stands, you have to explicitly declare a width for the lines (but you might be able to mess with this)
Doesn't handle multiple lines too well, but again, you might be able to edit the h2 styles to make this work a little better
While not a perfect solution (I feel your pain here, this is a tough one), sometimes you can use background-attachment:fixed to remedy the background issue using the <span> technique if you are using a background image:
Demo: http://jsfiddle.net/cEcCL/3/
<h2><span>Text Content</span></h2>
h2 span,
body{ /* Apply to h2 span and whatever the parent element is */
background:url(background.gif) fixed;
}
h2 {
line-height: 10px;
font-size: 18px;
text-align: center;
padding: 5px 0;
}
h2:after{
content:" ";
float:left;
border-bottom: 1px solid #000;
width:100%;
height:10px;
margin-top:-15px;
}
Of course this only works if the parent element can have a fixed background image, and won't work with CSS3 gradient backgrounds. It's a limited-use idea, but I just thought I'd bring it to light.
It seems only <legend> tags have this behavior, and I know of no way to emulate that with CSS, and I don't think you don't want to start using <legends> for headings...

Resources