I want to move link a bit down when clicked, but when I try to do that using :active state everything below that button moves a bit too. What's the easiest fix to that (I don't want to mess too much with my HTML code, so maybe something css-related?).
HTML:
Test
<p>This paragraph moves when I click button above. I want to prevent that.</p>
CSS:
a { display: inline-block; }
a:active { margin: 5px 0 0 0; }
position:relative & top: 5px sounds like a good idea, but this doesn't work either (button moves 1px down for ever :/).
http://jsfiddle.net/JyZLF/
This may suit your needs:
a {
display: inline-block;
margin: 0 0 5px 0;
}
a:active {
margin: 5px 0 0 0;
}
http://jsfiddle.net/JyZLF/3/
personally, I wouldn't use margin for this, I would use:
a:active {
position:relative;
top:5px;
}
http://jsfiddle.net/seemly/jFrCj/1/
Much cleaner, less code and less likely to effect the rest of your layout, improving the future-proofing of your site.
Margin moves the element box itself, where as position relative leaves the box of the element where it is, but takes the element out of the flow of the document, allowing the movement of it anywhere you want without effecting anything else.
You could add position:relative to the a, then in the a:active, change it to top:5px. So your code will look like
a{display:inline-block; position:relative;}
a:active{top:5px;}
http://jsfiddle.net/JyZLF/7/
A positioning of relative basically says "You can move this element wherever you want on the page, but the space will stay where the element originally sat." The link had a default positioning of static, which means it follows in the normal flow of elements. So if you moved the margin down 5px, then everything below it will change
You could wrap the a in a div and then give that div a specified height, while also giving the a absolute positioning.
see below:
http://jsfiddle.net/8P93R/1/
Related
Alright so I have a page that's title always changes based on what person is logged in (their name is the title of the page). However because of the fact that the name is always going to be different that means that it needs to be positioned via the center of the text so that it will expand out horizontally both ways. I'm uncertain as to how to approach this and I have tried a few things however due to the variable length of the title none of the suggestions have panned out. So to give you the basics of where I'm at code wise:
#profteamName{
position:absolute;
text-align:center;
top:220px;
left: 550px;
color: white;
text-shadow: 1px 1px 2px black, 0 0 1em blue, 0 0 0.2em darkblue;
text-decoration:underline;
I wouldn't be against using relative positioning. Just so long as it will expand horizontally.
(prefer to use absolute positioning long story there but I will take what I can get)
Thank you for your guys time.
Rather than positioning the div from the left side of the page, stretch it across the entire window (or container div on the page) using width:100%;. It'll take up the entire width and align the text - regardless of the length - in the middle of the div.
CSS
.header {
position:absolute;
text-align:center;
top:50px;
width:100%; /* take the width of the window or container div */
/* rest of your code */
}
Here's a CodePen mockup you can play with.
The background of my css class footer does not go across the entire width of the browser depending on how wide I keep the browser. It is making the page look odd because the footer is ending before the main content ends. The site is up at avidest.com so you can see what I'm referring to. Here is the css:
.Footer { width: 100%; padding:10px 0; margin:0px 0 0 0; text-align:center; border-top:1px solid #b3b3b3; background:#d9d9d9; background-repeat: top-repeat-x;}
The css was originally:
.Footer { width: 100%; padding:10px 0; margin:0px 0 0 0; text-align:center; border-top:1px solid #b3b3b3; background:#d9d9d9;}
but that didn't work either.
How do I make the footer go all the way from the left to the right side of the browser?
Thank you.
Looking at your webpage with chrome inspector, this error seems to be related with floating all the columns and header.
When you float an element, that element gets 'out' of the document flow. What this means is that this element actual size wont' be taken into consideration when it's time to layout things.
I usually don't want to have this behaviour on floated elements, so one way to avoid this is to set overflow: auto in the parent container.
Also, your header layout looks really strange. I'll update this when I have a definitive solution.
First update:
I have added said overflow: auto to every parent with floated elements and now it works for me. Please add that rule to the following elements:
.Header
.Logo
.body
Please note that with these changes your page will look messy (specifically, there'll be many scrollbars around).
This is because you have been a little too much strict setting things' size. I would let things flow more naturally instead. For example:
Settings logo size shouldn't be neccessary.
Bullet points on Header have too few height. I would remove it too.
Another thing I would do is to split the background image in 3 (or 2 at least, header and content). That way, things are a little more decoupled and easier to change. Try to think of each 'logical' block (header, footer, sidebars, login form) as an independent module that shouldn't share things with the rest (images, classes, etc).
I'm sorry that all this can't be explained in a comment, but please don't hesitate to ask me anything.
Have you tried left and right pixels at 0 maybe?
.Footer { left:0px; right:0px; padding-bottom:10px 0; margin:0px 0 0 0; text-align:center; border-top:1px solid #b3b3b3; background:#d9d9d9; background-repeat: top-repeat-x;}
I think it may be the container it is within
i have a parent div, which can change its size, depending on the available space. Within that div, i have floating divs. Now, i would like to have spacing between these divs, but no space to the parent div (see drawing).
Is there a way to do this with CSS?
Thank you
I found a solution, which at least helps in my situation, it probably is not suitable for other situations:
I give all my green child divs a complete margin:
margin: 10px;
And for the surrounding yellow parent div i set a negative margin:
margin: -10px;
I also had to remove any explicit width or height setting for the yellow parent div, otherwise it did not work.
This way, in absolute terms, the child divs are correctly aligned, although the parent yellow div obviously is set off, which in my case is OK, because it will not be visible.
You can do the following:
Assuming your container div has a class "yellow".
.yellow div {
// Apply margin to every child in this container
margin: 10px;
}
.yellow div:first-child, .yellow div:nth-child(3n+1) {
// Remove the margin on the left side on the very first and then every fourth element (for example)
margin-left: 0;
}
.yellow div:last-child {
// Remove the right side margin on the last element
margin-right: 0;
}
The number 3n+1 equals every fourth element outputted and will clearly only work if you know how many will be displayed in a row, but it should illustrate the example. More details regarding nth-child here.
Note: For :first-child to work in IE8 and earlier, a <!DOCTYPE> must be declared.
Note2: The :nth-child() selector is supported in all major browsers, except IE8 and earlier.
Add margin to your div style
margin:0 10px 10px 0;
http://www.w3schools.com/css/css_margin.asp
I'm late to the party but... I've had a similar situation come up and I discovered padding-right (and bottom, top, left too, of course). From the way I understand its definition, it puts a padding area inside the inner div so there's no need to add a negative margin on the parent as you did with a margin.
padding-right: 10px;
This did the trick for me!
Is it not just a case of applying an appropriate class to each div?
For example:
.firstRowDiv { margin:0px 10px 10px 0px; }
.secondRowDiv { margin:0px 10px 0px 0px; }
This depends on if you know in advance which div to apply which class to.
A litte late answer.
If you want to use a grid like this, you should have a look at Bootstrap, It's relatively easy to install, and it gives you exactly what you are looking for, all wrapped in nice and simple html/css + it works easily for making websites responsive.
I have a div that I want to use for dynamic content. When the content that fills the div is non-existent, I don't want to see it. Right now, I can see about a 5px box. Even when I remove the padding, I can still see about 1px of the box. How do I remove the box when there is no content?
#test {
border:1px dashed red;
font-size:16px;
margin:20px 0 0 0;
width:332px;
background-color:#eee;
padding:5px 0 5px 60px;
}
You can do in CSS:
div#test:empty {
display: none;
}
There's a jquery way of doing this as well, if you're interested. The :empty selector can hide things like so:
$('#test:empty').hide();
If you remove the padding,margin and border (which you don't mention in your question) then the height will be 0px, and you will not see anything in the browser. Check the screenshot below and the offsetHeight value.
For example you can create another div below #test and then add display:none for #test, you will see that the position of the second div doesn't change.
Because there is a div . You have to do this with server-side programming language (or maybe javascript) . For example :
if(content()) // if there is any content
{
echo "<div id=\"test\"></div>";
}
else
{
}
What about using the search box in the upper right corner?
Hide empty div will point you to some same questions, that have been answered before.
I have a weird li issue I just can't figure out. I have an image set for the li on this page's content, but it's not against the text but behind the image! Confused on how to solve this. Any help would be greatly appreciated.
http://staging.liquor.com/wind-at-your-back/
Add
overflow: hidden;
to the #single_content ul. (overflow: auto will also work). If it needs to work in IE6 too, make sure the list has layout (e.g. by adding zoom: 1).
The lines inside a block box following a float are pushed aside by the floated element. But the block box itself doesn't move, keeping the background images at its left edge, covered by the floating element.
You can stop the block box from overlapping a float by having it establish a new block formatting context. One way to do that is to set the overflow property. That forces the entire list next to the float, instead of just pushing its text aside.
See the CSS2 specification section about floats for more details.
The background images of your list are behind the cocktail image. You could either make the list floating right like this
#single_content ul {
float:right;
list-style-image:none;
list-style-position:outside;
list-style-type:none;
margin:0;
width:280px;
}
or give the lis a margin-left of your image's width+margin like so
#single_content ul li {
background:transparent url(images/ulliarrow.png) no-repeat scroll 0 0;
margin:0 0 0 310px;
padding:0 0 3px 15px;
}
to make the reappear behind the floating image.
To get the background images to show up from outside of the image you can add a margin to the style
add
margin:0 0 0 ~300px;
to
#single_content ul li
Immediate solution is to add the following rule to #single_content ul
margin: 0 0 0 295px;
I don't like that because it's fairly absolute, though your site looks glued together well and it shouldn't hurt. I'll look for something more elegant, and if I find it, post it here.
EDIT 1: Not much better, but you could add the following rule to the li elements instead:
background-position: 295px 0;