CSS default width prior to selector - html

Is there any way to set a default width for a group of divs, but then change each width regardless of order in just CSS? Example JSFiddle is at http://jsfiddle.net/RfHSA/.
I'm attempting to have each div set to width:20%, but then upon the mouse hovering one of the inner divs, the specific div hovered over should be set to width:72% and the others set to width:7% (including ones that occur prior to it in the HTML structure). Is this possible with just CSS, or is Javascipt/jQuery required?
Edit: Example of what I'm trying to achieve is here: http://www.kriesi.at/themes/newscast/

I'd like to recommend an easy solution to your need: http://jsfiddle.net/linmic/qcnmu/1/
We simply apply display: table to the "listwrapper" and display: table-cell to the "outerbox", then everything works perfectly.
Cheers

You were 99% there: http://jsfiddle.net/RfHSA/2/
.featuredwrapper {
width:100%;
height:350px;
margin:auto;
background-color:rgba(0,0,0,0.5);
padding-top:12px;
position:relative;
}
.listwrapper {
width:95%;
max-width:1100px;
height:325px;
margin:auto;
position:relative;
}
.listwrapper:hover .outerbox {
width:7%;
}
.outerbox {
width:20%;
height:100%;
display:inline-block;
background-color:#e8e8e8;
margin-left:-4px;
box-shadow:-5px 0px 5px rgba(51,51,51,0.85);
-webkit-transition: width .3s ease-out;
}
.listwrapper:hover .outerbox:hover {
width:72%;
}
.outerbox:first-child{
margin-left:0px;
}
.hoveractive {
position:absolute;
width:95%;
height:325px;
z-index:1000;
padding-top:12px;
}
I minimally fixed them all errantly closing, I think the remaining problems related to decimal widths associated with % widths...

http://jsfiddle.net/RfHSA/15/
Here's a working version of your script. You definitely need some javascript manipulation here to make it work. I tried to use as little as possible and as you can see from the results, it's a little shaky, but hopefully it gets you on the right track.
EDIT: Oh well, I tried, but the other guy's solution is better =P

Updated to prevent premature collapsing
Tweaking your CSS gave this solution (see fiddle). It requires the padding-top to move from the .listwrapper to the .featuredwrapper to prevent premature collapse from top entry:
Tweaked CSS
.outerbox {
width:20%;
height:100%;
display:inline-block;
background-color:#e8e8e8;
margin-left:-4px;
box-shadow:-5px 0px 5px rgba(51,51,51,0.85);
-webkit-transition: width .3s ease-out;
}
/*prevents premature collapse on right side entry*/
.outerbox:last-of-type:after {
content: '';
width: 2px;
height: 100%;
position: absolute;
top: 0;
right: -2px;
}
.listwrapper:hover .outerbox {
width: 7%;
}
.listwrapper .outerbox:hover {
width:72%;
}

Related

How to spread div blocks in a page?

I was looking at Android developer's website and I wanted to copy how they designed the article's animation when someone hovered on top of it. As such I tried to make something similar in plain HTML/CSS. However, I am running into an issue.
I used float expecting that the div tags would seperate from one another and apply the appropriate margins. However, It seems that the div tags are stacking on top of each other instead of being spread out.
I wanted them to look like this
but it ended up looking like this
https://codepen.io/alfielytorres/project/full/XYxPVO
I provided my files below.
HTML
<div class="new"><div>
<div class="new"><div>
<div class="new"><div>
CSS
body {
background: white;
font-family:courier;
padding:20px 100px 20px 100px;
}
.new {
width:100px;
height:100px;
background-color:white;
position: relative;
border:2px solid black;
float:left;
padding:15px;
border-radius:5%;
}
.new::before {
content:"";
width:100px;
height:100px;
padding:15px;
background-color:black;
position:absolute;
transform:translate(-6px,-6px);
border-radius:5%;
z-index: -1;
}
.new:hover:before{
animation-name:click;
animation-duration:500ms;
animation-fill-mode:forwards;
}
#keyframes click {
0% {
transform:translate(-6px,-6px);
}
100% {
transform:translate(-10px,-10px);
}
}
Thank you for your help!
You need to close your div tags like so </div>, then you could put these 3 div in a flex container and space them evenly.
hope this helps

Changing CSS of <img> when hovering over `<button>. The <img> is inside <button>

I would like an easier / efficient way to edit the CSS of the <img class "search-button> when hovering over <button class="search-button"> instead of changing the search-button itself like I have done below.
The fact that the img is changing height and the button isn't is also bizarre to me. I would think changing the height attribute would change the height of the button and not the height of the img
Is it possible to do without using Javascipt and a pure CSS method? An explanation would be appreciated as I am self-studying and more information is far valuable than just a solution.
After fix and edit - My Question : Could it be simplier?
HTML
<button type="submit" class="search-button">
<img class="search-button-img" src="http://teacherweb.co.za/wp-content/uploads/2014/10/search.png" alt="">
</button>
CSS
search-button {
padding:0px;
margin:0px;
width:145px;
height:145px;
border-radius: 5px;
background-color:transparent;
overflow:hidden;
}
.search-button-img {
height:80%;
}
.search-button:hover .search-button-img { /*Fixed hover space */
margin-top:-1px;
margin-left:-1px;
height:100%;
}
Original : http://jsfiddle.net/x8xwxg3z/
Updated (Working Well) : http://jsfiddle.net/x8xwxg3z/5/
*random magnifier image for example
Use Tramsform scale
.search-button {
padding:0px;
margin:0px;
width:145px;
height:145px;
border-radius: 5px;
background-color:transparent;
overflow:hidden;
}
.search-button-img {
width: 80%;
transition: transform .3s ease
}
.search-button-img:hover {
transform: scale(1.2,1.2)
}
<button type="submit" class="search-button"><img class="search-button-img" src="http://teacherweb.co.za/wp-content/uploads/2014/10/search.png" alt=""></button>
Or apply the :hover on the parent
.search-button {
padding:0px;
margin:0px;
width:145px;
height:145px;
border-radius: 5px;
background-color:transparent;
overflow:hidden;
}
.search-button-img {
width: 80%;
transition: transform .3s ease
}
.search-button:hover .search-button-img{
transform: scale(1.2,1.2)
}
<button type="submit" class="search-button">
<img class="search-button-img" src="http://teacherweb.co.za/wp-content/uploads/2014/10/search.png" alt="">
</button>
your problem is from the space between :hover and your class so remove the space
.search-button:hover {
margin-top:-1px;
margin-left:-1px;
height:100%;
}
So if I understood you right, you want only the image to become bigger, but not the button?
You could try the following:
.search-button:hover .search-button-img {
height: 90%;
}
instead of:
.search-button :hover {
margin-top:-1px;
margin-left:-1px;
height:100%;
}
This won't work, because you're using a space between the class/selector and the pseudo class. In CSS you write selector:pseudoclass as soon as you use a space, CSS interprets that as a child. So .foo .bar would adress the div with the class bar in <div class="foo"><div class="bar">Baz</div></div>. CSS Selectors can be ID's, Classes or simply selectors. Classes are adressed by a . in front and IDs by a #. I hope this helps.
With CSS you are able to adress a child element like the image. And it's Javascript, what you meant not Java ;)
try this : http://jsfiddle.net/x8xwxg3z/3/
and css code is here:
.search-button {
padding:0px;
margin:0px;
width:105px;
height:105px;
border-radius: 5px;
background-color:transparent;
overflow:hidden;
position:relative; transition:all 0.5s ease-in 0s;
}
.search-button-img {
height:50px;
position:absolute; top:10px; left:20px
}
.search-button:hover {
margin-top:-1px;
margin-left:-1px;
height:500px;
width:80%;
}
I think that you want is to make bigger the button without making bigger the image. The image is getting bigger because it has a % size (it depends of his parent, in this case, the button).
Anyway:
.search-button:hover{} refers to: when you hover over the button do this to the button.
.search-button:hover .search-button-img{} refers to: when you hover over the button do this to the image.
Then you only need the change, that you want to do.

Footer gets cut off?

I'm having some issues with parts of the footer on my website getting cut of on different browsers.
On my website here http://reportalert.info/index-test.php, the twitter, rss and share icons get cut off and move around slightly when on different browsers. I've tried changing the background position and padding of each of the icons but I can't seem to get it to work across different browsers. Any suggestions on how to fix this?
Here is the code that I have for the footer:
#footer
{
clear: both;
font-family: "Droid Serif";
margin:10px 0;
padding-bottom:60px;
width:100%;
height:10px;
text-align:left;
font-size:80%;
color:#444;
}
a.ftwitter
{
background:url(http://reportalert.info/images/nra/ra-share.png/images/nra/ra-twitter.png) left no-repeat;
background-position:0 -22.5px;
padding:3px 55px;
}
a.ftwitter:hover
{
background-position:0 0;
padding:4px 55px;
}
a.frssfeed
{
background:url(http://reportalert.info/images/nra/ra-share.png/images/nra/ra-feed.png) left no-repeat;
background-position:0 -26.5px;
padding:5px 55px;
}
a.frssfeed:hover
{
background-position:0 0;
padding:6px 55px;
}
a.fshare
{
background:url(http://reportalert.info/images/nra/ra-share.png) left no-repeat;
background-position:0 -22.5px;
padding:3px 60px;
}
a.fshare:hover
{
background-position:0 0;
padding:4px 60px;
}
Thanks in advance for your help
Padding works differently in every browser, that's why your icons gets cut off in Chrome.
I would use a specific width and height instead.
Instead of padding, try using width and height. And add a display: inline-block. Here for example:
a.ftwitter
{
display: inline-block;
background:url(http://reportalert.info/images/nra/ra-share.png/images/nra/ra-twitter.png) left no-repeat;
background-position:0 -22.5px;
width: 110px;
height: 22px;
}
I think this might help. Apply this to your icons:
position:relative;
z-index:99;
The icons that get cut off are all empty a elements. Because it's an inline flow element, that means it collapses to default text height - 20 pixels in the font you use, while the Twitter icon is 22, hence causing 2 pixels to be cut off.
Set the anchors to display:inline-block, or another block layout style fitting in your layout, and the correct height which is then allowed, and it's solved.

CSS Transitions Error

I am having a few problems with CSS. I have scripted a simple text box, that when it is clicked a div drops down, but it does not seem to be working. If anyone could help me, I'll be greatfull.
CSS:
input {
top:18px;
left:20px;
width:1230px;
padding:4px;
border:1px dashed #eeeeee;
font:16px arial;
font-weight:bold;
color:#d8d8d8;
}
input:focus {
height:200px;
}
div {
overflow:hidden;
padding:0;
margin:0;
height:0;
width:1230px;
border:1px dashed #eeeeee;
background-color:transparent;
transition:height.5s;
-moz-transition:height 0.5s;
-o-transition:height 0.5s;
-webkit-transition:height 0.5s;
}
body {
background-image:url('pic.bmp');
background-repeat:no-repeat;
}
I'm guessing that you need to change input:focus to input:focus div (if the div is in the input element), or something like input:focus + div (if the div is after the input), but without seeing your markup it's hard to say.
You have to use input:focus + div to select your division.
Here is the Pure CSS version of what you want : jsFiddle
The div has overflow: hidden property, which will cause any inner elements' heights to be ignored in the rendering of the div's height.

image above list borders.. probably very easy

I probably have one of the easiest questions of the day, but I'm having a hard time finding a direct answer for how to fix it (HTML/CSS -n00b)...
I have in my mark-up an img-tag and under that a div-tag containing an horizontal list.
In the lists ul-CSS I have declared a top and bottom border, the img (which is a .PNG with transparent background) is showed in front of the ul border-top, which is what I want. But for the li-CSS I have border-right for each element to separate them, and this border is in front of the img...
Here you see what I mean:
Edit:
#topLeftImage {
z-index: 999;
margin-left: 1em;
margin-top: 3px;
#navigationlist li
{
z-index: 0;
display: inline;
list-style-type: none;
padding-right: 2px;
font-size: 75%;
border-right: 2px solid #C0C0C0;
}
So how do I declare the img for it to be showed in-front of that li-border?
And another fast question, can I declare so that the last li-element doesn't get that border-right, since it doesn't have a right-neighbour?
Any tips would be helpful!
-Thanks
Are you using IE to check the results of these changes you are making? IE's z-index method is a little mental. Try the code below and see if that helps.
#topLeftImage {
z-index: 999;
margin-left: 1em;
margin-top: 3px;
position:relative;
}
#navigationlist li {
z-index: 0;
display: inline;
list-style-type: none;
padding-right: 2px;
font-size: 75%;
border-right: 2px solid #C0C0C0;
position:relative;
}
and give the parent of these two items:
#parent {
z-index: 0;
position:relative;
}
Firstly the css property z-index should help for the first problem.
img{
z-index:999;
}
That should make it appear above everything.
(IMPORTANT... Be careful with this though... The whole area of the image will be displayed on top of the nav, making it impossible to click the Item one hyperlink.)
For the latter question, you can use last-child pseudo class to set the right border to nothing. eg.
#nav li:last-child{
border-right:none;
}
This is a CSS3 feature... so IE8 and below will not let it work. Maybe just adding a class to the last item will be the most browser friendly way!
#nav li.last{
border-right:none;
}
<li>normal</li><li class="last">furthest right</li>
Let me know if the z-index advised by me and another guy causes the problem I outlined. There will be some solutions to this but require a little bit of effort!
You could set the z-index:9999; for the img if you give it a class and/or set the z-index:0; for the li's class.
e.g.
img.className {
z-index:9999;
}
li.className {
z-index:0;
}
Or if you use ID's:
img#idName {
z-index:9999;
}
li#idName {
z-index:0;
}
in your code you use z-index, and correctly, but you have to keep in mind that z-index works only with positioned elements. So in both #navigationlist li and #topLeftImage add position:relative;