<a href> coming before span in css - html

I am creating a jobs page and was just making this when I ran across what I think is a styling problem.
If you look at the image below you can see the Apply button comes before the time and city but I want the Apply button to be farthest to the left but it will not position that way which only led me to believe this is a styling error on my part. Does anybody know why this would be? Code posted below.
HTML
<div class="job-case">
<h4>iOS Engineer</h4>
<span>Chicago</span>
Apply
</div>
CSS
.job-case {
height: 0 auto;
width: 0 auto;
background-color: white;
margin: 10px;
padding: 0 auto;
border-radius: 5px;
border: 1px solid none;;
}
.job-case:hover {
background-color: #F3EFF5;
border-color: #212121;
}
.job-case h4 {
color: #212121;
font-weight: bold;
font-size: 20px;
display: inline-block;
padding-left: 30px;
}
.job-case a {
float: right;
height: 0 auto;
margin-top: 17px;
padding: 10px;
color: #72b01d;
background-color: none;
border: 2px solid #72b01d;
border-radius: 5px;
}
.job-case a:hover {
background-color: #72b01d;
border-color: #72b01d;
color: white;
-webkit-transition: all 0.2s ease-in-out;
-moz-transition: all 0.2s ease-in-out;
-o-transition: all 0.2s ease-in-out;
transition: all 0.2s ease-in-out;
}
.job-case span {
float: right;
padding: 30px;
font-weight: bold;
font-size: 15px;
color: #212121;
}

It is not a styling issue. When using float:right on siblings they stack and they go to the right in the order they are in the DOM. so the first one with float:right will go to the farthest right.
So you need to change the html and put the a before the span
<div class="job-case">
<h4>iOS Engineer</h4>
Apply
<span>Chicago</span>
</div>
Demo at https://jsfiddle.net/g8kuve66/
Quoting the float specification
A floated box is shifted to the left or right until its outer edge touches the containing block edge or the outer edge of another float. If there is a line box, the outer top of the floated box is aligned with the top of the current line box.

Related

how to make both properties to activate as i hover

i have a button with the following structure:
<button className='ctaBtn'>
<a href={props.url}>Open</a>
</button>
And this is its styles:
.ctaBtn{
border-radius: 5px;
width: 70px;
height: 40px;
padding: 10px;
border: .5px solid rebeccapurple;
background-color: white;
color: rebeccapurple;
font-weight: 700;
font-size: 18px;
cursor: pointer;
margin-top: 15px;
margin-bottom: 30px;
}
.ctaBtn:hover{
background-color: rebeccapurple;
}
.ctaBtn a:hover{
text-decoration: none;
color: white;
}
.ctaBtn a{
list-style-type: none;
text-decoration: none;
color: rebeccapurple;
}
As i hover over the button the background color changes to purple and as i hover over the a tag the font color changes to white. The issue is that before i get with the cursor to the a tag the button background is purple and the text is also purple. What i want to achieve is that as soon is pass through the button both css properties are activated the background color purple for the button and the white color for the text. How can i achieve this?
We combine some of your properties and hit the nested anchor tag from the parent action. See example below, but see additional info below.
.ctaBtn{
border-radius: 5px;
width: 70px;
height: 40px;
padding: 10px;
border: 1px solid purple;
background-color: white;
color: purple;
font-weight: 700;
font-size: 18px;
cursor: pointer;
margin-top: 15px;
margin-bottom: 30px;
transition: background-color .25s ease, color .25s ease;
}
.ctaBtn:hover{
background-color: purple;
}
.ctaBtn:hover a {
color: white;
}
.ctaBtn a {
text-decoration: none;
}
<button class='ctaBtn'>
Open
</button>
On a side note though, you shouldn't nest an anchor tag inside a button as they're mutually exclusive in use. I'd prefer to see something like this instead for WCAG and semantic purposes.
.ctaBtn{
border-radius: 5px;
height: 40px;
padding: 10px;
border: 1px solid purple;
background-color: white;
color: purple;
font-weight: 700;
font-size: 18px;
cursor: pointer;
margin-top: 15px;
margin-bottom: 30px;
transition: background-color .25s ease, color .25s ease;
}
.ctaBtn:hover{
background-color: purple;
color: white;
}
<button class='ctaBtn'>
WORDS
</button>
Or swap button for <a> tag instead but neither as a child of one another.
It's because you set a padding on the button so the a tag is smaller than its parent -> your problem.
Another thing: Don't use an a tag in a button tag, it's accessibility complete nonsense. You only need an a tag and a span.
<a href="#" class="ctaBtn">
<span>Open</span>
</a>

Transition not easing out when un-hovering

I'm making a simple button with a CSS underline ease transition. All other ease transitions are working fine (hover, ease in, un-hover, ease out), but border-bottom will not ease out. When you quit hovering, it simply reverts back to normal without easing out.
Here is a code-pen with a quick button I made to illustrate the problem.
https://codepen.io/anon/pen/jwgpdv
Here is my CSS:
.gbtn {
background: #bba989;
text-align: center;
line-height: 150px;
height: 150px;
color: white;
text-transform: uppercase;
letter-spacing: 1px;
font-size: 12px;
display: inline-block;
transition: all .25s ease;
box-sizing: border-box;
font-family: "montserrat", serif;
padding: 0px 30px;
}
.gbtn:hover {
background-color: #aa9470;
border-bottom: 150px solid #242424;
}
You didn't define a border before hover, how is the browser supposed to know how to transition out?
Add this:
.gbtn {
border-bottom: 0 solid #242424;
}

Center horizontally and vertically text in relative height div

I want to center my text in a relative height div which contains an image. I use absolute position but when my text is on two lines, the text is not centered. I've already tried to use a table but it doesn't work due to the img.
HTML:
<div id="hubs">
<h3>Nos Hubs</h3>
<hr>
<a class="thumbnail vignette-hub" href="http://kkw.fr">
<img style="opacity: 0.6;filter: alpha(opacity=60);" alt="AĆ©roport de Nantes" src="http://kkw.fr/uploads/upload-center/nantes-vue-aerienne091501270208.png" width="100%" />
<p class="txt-hub-image">
Hub de</br>Nantes
</p>
</a>
</div>
CSS :
.txt-hub-image {
z-index: 100;
position: absolute;
left: 0px;
top: 50%;
width: 100%;
height: 100%;
text-align: center;
text-decoration: none;
color: white;
font-weight: bold;
font-size: 16px;
}
.vignette-hub {
position: relative;
width: 25%;
min-width: 135px;
}
.thumbnail {
display: block;
padding: 4px;
margin-bottom: 20px;
line-height: 1.42857143;
background-color: #fff;
border: 1px solid #ddd;
border-radius: 4px;
-webkit-transition: border .2s ease-in-out;
-o-transition: border .2s ease-in-out;
transition: border .2s ease-in-out;
}
.thumbnail > img,
.thumbnail a > img {
margin-right: auto;
margin-left: auto;
}
a.thumbnail:hover,
a.thumbnail:focus,
a.thumbnail.active {
border-color: #337ab7;
}
.thumbnail .caption {
padding: 9px;
color: #333;
}
Do you have any ideas ?
There are a few changes required to your snippet to make it automatically work for all dimensions:
p tags by default have a margin-top. If you don't reset it, then absolutely positioning it at 50% would become 50% + margin-top. This needs to be reset.
When you absolutely position an element at top: 50%, the box gets positioned at 50% height of the container and text keeps getting added from that position on. So, to match the center of the text block with the center of the parent, you have to translate the box with the text up by 50% of its own size. This can be done by adding transform: translateY(-50%).
You don't need to add a height: 100% on the p tag and it can be removed.
Note: Using transform method for positioning needs CSS3 support but I assume this shouldn't be a problem because you are already using transition.
If you want to support non CSS3 compatible browsers, have a look at the other approaches mentioned here. I have added a different answer just to explain the first two points I had mentioned above.
.txt-hub-image {
z-index: 100;
position: absolute;
left: 0px;
top: 50%;
width: 100%;
text-align: center;
text-decoration: none;
color: white;
font-weight: bold;
font-size: 16px;
/* added to fix the vertical centering */
margin-top: 0px;
transform: translateY(-50%);
}
.vignette-hub {
position: relative;
width: 25%;
min-width: 135px;
}
.thumbnail {
display: block;
padding: 4px;
margin-bottom: 20px;
line-height: 1.42857143;
background-color: #fff;
border: 1px solid #ddd;
border-radius: 4px;
-webkit-transition: border .2s ease-in-out;
-o-transition: border .2s ease-in-out;
transition: border .2s ease-in-out;
}
.thumbnail > img,
.thumbnail a > img {
margin-right: auto;
margin-left: auto;
}
a.thumbnail:hover,
a.thumbnail:focus,
a.thumbnail.active {
border-color: #337ab7;
}
.thumbnail .caption {
padding: 9px;
color: #333;
}
<div id="hubs">
<h3>Nos Hubs</h3>
<hr>
<a class="thumbnail vignette-hub" href="http://kkw.fr">
<img style="opacity: 0.6;filter: alpha(opacity=60);" alt="AĆ©roport de Nantes" src="http://kkw.fr/uploads/upload-center/nantes-vue-aerienne091501270208.png" width="100%" />
<p class="txt-hub-image">
Hub de</br>Nantes
</p>
</a>
</div>
Here is a demo fiddle as the snippets feature seems to be down.
Change your .txt-hub-image class, top value from 50% to 25%.

Safari's "Float:right" causing inline div elements to act as block elements

My problem is particular to Safari. Namely, inside of my header is a div consisting of two buttons. The div is floated to the right. But, this 'float:right' makes the two button elements behave like block elements - with each on a different line. I've tried applying the "clear" property to the div, to no avail. I've also tried applying "display: table" to parent div and changing child elements accordingly. All to no avail. The problem is not present in Firefox or Chrome. I have not been able to test it in IE yet - nothing but macs in the house.
I tried to upload two pictures showing the site in Firefox and Safari, but I was denied since I don't have the 10 reputation points necessary to post pictures.
Here's the HTML:
<header role="banner">
<!--Start Navigation-->
<nav role="navigation" id="global-navigation">
<ul><li>Home</li><li>
Link 1</li><li>
Link 2</li><li>
Link 3</li><li>
Link 4</li><li>
Link 5</li>
<!--Start Signup/LogIn Div-->
<div id="signup-login">
<button type="button" onclick="----">sign-up</button>
<button type="button" onclick="----">log-in</button>
</div>
<!--End Signup/LogIn Div-->
</ul>
</nav>
<!--End Navigation-->
</header>`
Here's the CSS:
header {
width: 100%;
height: 4em;
background-color: rgb(46, 46, 46);
position: fixed;
top: 0;
}
#global-navigation {
width: 100%;
height: 4em;
margin: auto;
}
#global-navigation ul {
height: 4em;
text-align: center;
}
#global-navigation ul li {
height: 100%;
display: inline-block;
border-radius: 2%;
padding: 0 3em;
}
#global-navigation ul li a {
color: #fff;
text-decoration: none;
font-size: 1em;
font-weight: normal;
height: 100%;
line-height: 4em; /***Vertically centers global-nav text ***/
vertical-align: center;
}
#global-navigation ul li:hover {
background: #e74c3c;
transition: background-color .30s ease-in-out;
-moz-transition: background-color .30s ease-in-out;
-webkit-transition: background-color .30s ease-in-out;
}
#signup-login {
display: inline-block;
float: right;
line-height: 4em;
}
#signup-login button {
background-color: rgb(46, 46, 46);
height: 3em;
width: 4vw;
border: 1px solid #fff;
border-radius: 7%;
color: #fff;
font-size: .7em;
}
#signup-login button:hover {
background: #e74c3c;
transition: background-color .30s ease-in-out;
-moz-transition: background-color .30s ease-in-out;
-webkit-transition: background-color .30s ease-in-out;
border-color: rgb(32, 32, 32);
border-radius: 7%;
}

Relative blocks are not considering top positioning in a div

I have created a button with border-bottom of 4px. While hovering the button , I'm reducing the border-bottom-width as 0px and adding top of 4px to avoid affecting other elements below the button.
But the items below the button are moving while i'm hovering the button. Because, the blocks after the button are not considering the 4px top. So, It not looks good. How to overcome this problem..
.btn{
padding: 30px;
background-color: #30d589;
cursor: pointer;
border-bottom: 4px solid #1b8454;
}
.btn:hover{
border-bottom-width: 0px;
top: 4px;
}
I have updated my code in jsFiddle
Thanks in advance..
Use this css:
.btn{
padding: 30px;
background-color: #30d589;
cursor: pointer;
border-bottom: 4px solid #1b8454;
display: block;
float: left;
box-sizing: border-box;
transition: all 0.2s linear;
margin-right: 100%;
}
.btn:hover{
margin-top: 4px;
border-bottom-width: 0px;
}
Here is a working fiddle:
http://jsfiddle.net/Hive7/5mhGt/2/
If you want to keep the border color and keep the text from jittering while animating the :hover state, try wrapping your button(s) in a relatively positioned container.
Then, update your css:
.btn-wrapper {
position: relative;
height: 100px;
}
.btn{
position: absolute;
top: 8px;
padding: 30px;
background-color: #30d589;
cursor: pointer;
border-bottom: 4px solid #1b8454;
display: inline-block;
transition: 0.2s;
}
.btn:hover{
top: 12px;
border: 0px;
}
jsfiddle: http://jsfiddle.net/BpL2A/
Updated fiddle: http://jsfiddle.net/5mhGt/5/.
The easiest way to resolve your problem is to make the border transparent:
.btn:hover {
border-bottom-color: transparent;
}
You don't have to mess with another properties like margin-bottom or so. If you decide to change the border width in the future you won't have to have this margin always in mind.