Elements within navigation resize separately rather than together - html

One of the biggest problems I have with navigation bars is that, whenever trying to put a logo in with a title, I always find that the image resizes itself to much smaller than the text sooner rather than later.
In the case below, I have a title at one end of the navigation/title bar and an image at the other end. When resizing or even on mobile devices, the image becomes very very small.
The html...
<div id="nav">
<p>Crowes</p>
<img src="pic.jpg" />
</div>
..and the CSS
#nav {
background-color: #7E0E0A;
box-shadow: 1px 1px 1px 1px black;
padding: 1%;
font-size: 5vh;
color: white;
font-weight: bold;
font-family: 'Pacifico';
overflow: auto;
width: 100%;
z-index: 1;
}
#nav p {
margin-left: 2%;
margin-top: 1%;
margin-bottom: 1%;
float: left;
color: white;
}
#nav img {
display: inline-block;
width: 6%;
vertical-align: middle;
float: right;
border-radius: 50%;
border: 2px solid white;
margin-right: 3%;
opacity: 0.7;
transition: all 0.2s ease;
}

It's not only just changing the size of the elements, it was also their positioning. It all had to be changed to ems rather than %.
(Nav-specific)
#nav {
background-color: #7E0E0A;
box-shadow: 1px 1px 1px 1px black;
font-size: 2.3em;
color: white;
font-weight: bold;
font-family: 'Pacifico';
overflow: auto;
width: 100%;
z-index: 1;
}
font-size to 2.3em.
(P-specific)
#nav p {
margin: 1.3em;
display: inline-block;
vertical-align: middle;
float: left;
color: white;
}
margin to 1.3em
(Img-specific)
#nav img {
display: inline-block;
height: 2.3em;
vertical-align: middle;
float: right;
border-radius: 50%;
border: 2px solid white;
margin: 1em;
opacity: 0.7;
transition: all 0.2s ease;
}
height to 2.3em, as guided by #MrLister and margin to 1em.

Related

slide in text on image hover css

I'm trying to make a text appear on image hover, but will need it to slide in from top and cover only 50% of image height, but not sure how can I get this to work, here is the code
<img style="background-color:#3b283e; float:left;" src="images/f1.jpg" />
<div class="cags1">Traditional Pastry</div>
and the CSS
.cags1{
background-color: #3b283e;
float:left;
}
.cags1:hover > img {
opacity:0.5;
padding: 10px;
font-family: Tahoma,Arial,Helvetica;
font-size: 14px;
line-height: 30px;
letter-spacing: 1px;
text-align: center;
color: #ffffff;
text-shadow: 0 1px 3px #000000;
}
Here is a working example based on your code:
.img-container {
position: relative;
overflow: hidden;
display: inline-block;
}
.img-container img {
background-color:#3b283e;
float:left
}
.cags1 {
background-color: #3b283e;
position: absolute;
top: -20px;
transition: 0.5s;
}
.img-container:hover > img {
opacity:0.5;
padding: 10px;
font-family: Tahoma,Arial,Helvetica;
font-size: 14px;
line-height: 30px;
letter-spacing: 1px;
text-align: center;
color: #ffffff;
text-shadow: 0 1px 3px #000000;
}
.img-container:hover .cags1 {
top: 20px;
}
<div class="img-container">
<img src="https://dummyimage.com/150x75/992c99/313abd" />
<div class="cags1">Traditional Pastry</div>
</div>

how to make sizes look the same on all screens

So, I am working on two sites, and the padding seems to change tremendously on different screens, I was wondering if this was potentially due to the units I am using? Or the specific CSS tag? However, I am hoping someone can figure it out for me
Two bits of code that keep changing:
codepen
.divider {
background-color: #3498db;
padding-top: 5%;
padding-bottom: 5%;
font-family: Open Sans;
font-weight: 300;
text-align: center;
}
.divider h1 {
margin-bottom: 10px;
margin-top: 0%;
padding-top: 20%;
font-weight: 500;
color: white;
}
.divider p {
color: white;
margin-bottom: 5px;
font-family: Open Sans;
text-align: center;
}
.divider button {
padding: 10px;
height: 15%;
cursor: auto;
width: 17%;
margin-top: 30px;
border-radius: 50px;
text-align: center;
color: white;
border: white 1px solid;
background-color: #3498db;
}
.divider button:hover {
background-color: white;
color: black;
transition: all 0.3s ease 0s;
}
<div class="divider">
<h1>See Something You Like?</h1>
<p>Feel free to contact us at any time and we’ll have someone reply to you 6 as soon as possible.
<br>industry's standard dummy text ever since the 1500s
<br>
<br>Whenever you’re ready, email us with the details you want on your website, and we will
<br>respond with a rough price.</p>
<a href="mailto:hello#baseframe.co">
<button>Email</button>
</a>
</div>
on this, the top padding gets super big (or sometimes it gets smaller) on different screens.
codepen
* {
margin: 0 auto;
padding: 0;
}
html {
height: 100%;
}
body {
font-family: 'Open Sans';
font-weight: 400;
height: 100%;
background-color: #ddd;
}
.nav {
background: rgba(0, 0, 0, 0);
position: absolute;
width: 100%;
}
.nav ul {
text-align: right;
vertical-align: middle;
margin-right: 15px;
margin-top: 15px;
font-size: 1.1em;
}
.nav li {
padding-top: 5px;
list-style: none;
display: inline-block;
padding: 15px;
}
.nav a {
margin-top: 17px;
bottom: 0;
display: inline-block;
color: white;
text-decoration: none;
}
.nav a:hover {
color: #3498db;
transition: ease 0.5s all 0s;
}
.nav hr {
opacity: 0.2;
width: 95%;
text-align: center;
}
.nav-logo {
vertical-align: middle;
top: 0;
float: left;
width: 5%;
display: inline-block;
}
.nav-logo img {
width: 250%;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.3);
}
/*-------------------Home-Page-------------------*/
.home-page {
background-image: url("http://baseframe.co/getanimus/img/cover1.jpg");
background-size: cover;
background-position: top;
background-attachment: fixed;
padding-bottom: 17%;
text-align: center;
}
.home-page h1 {
color: white;
padding-top: 15%;
font-size: 5em;
text-shadow: 0px 0px 10px rgba(0, 0, 0, 0.3);
}
.home-page input {
cursor: auto;
}
.home-page p {
font-weight: 300;
color: white;
margin-bottom: 15px;
}
button#infl {
background-color: #3498db;
color: white;
font-size: 1em;
width: 15%;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.3);
font-family: montserrat;
padding: 15px;
margin: 5px;
border-top-left-radius: 2em;
border-top-right-radius: 2em;
border-bottom-left-radius: 2em;
border-bottom-right-radius: 2em;
border: none;
cursor: auto;
}
button#brands {
background-color: white;
color: #7f8c8d;
font-size: 1em;
width: 15%;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.3);
font-family: montserrat;
padding: 15px;
margin: 5px;
border-top-left-radius: 2em;
border-top-right-radius: 2em;
border-bottom-left-radius: 2em;
border-bottom-right-radius: 2em;
border: none;
cursor: auto;
}
button#brands:hover {
opacity: 0.8;
transition: all 0.3s ease 0s;
}
button#infl:hover {
opacity: 0.8;
transition: all 0.3s ease 0s;
}
/*-------------------About-------------------*/
.about {
background-color: white;
padding-bottom: 10%;
}
.about h1 {
text-align: left;
margin-left: 20%;
margin-top: 5%;
}
.about hr {
background-color: #3498db;
height: 5px;
border: none;
margin-top: 2%;
margin-left: 20%;
width: 5%;
text-align: left;
float: left
}
.about p {
margin-left: 20%;
margin-right: 20%;
line-height: 30px;
margin-top: 5%;
text-align: left;
}
<div class="nav">
<ul>
<li class="nav-logo">
<img src="http://baseframe.co/getanimus/img/logo_white.png">
</li>
<li>Home</li>
<li>Influencers</li>
<li>Brands</li>
<li>Contact</li>
<hr>
</div>
<div class="home-page">
<h1>Animus Digital</h1>
<p>Premium Talent Management Agency</p>
<button id="infl">Influencers</button>
<button id="brands">Brands</button>
</div>
this website navigation doesn't align properly with the logo on the left, for some reason. In addition, on a 1920 x 1080 screen, the buttons get pretty wide.
Really appreciate any help on this. Thanks.
The reason why the sizes of those elements changes on different screens is because you use % instead of px. % scales the size with the browser's size.
You should use CSS Media queries
For first case since you are using % in padding, which leads to unexpected behavior in different situations.
For "n%" margin (and padding) to be the same for
margin-top/margin-right/margin-bottom/margin-left, all four have to be
relative to the same base. If top/bottom used a different base than
left/right', then "n%" margin (and padding) wouldn't mean the same
thing on all four sides.
(Also note having the top/bottom margin relative to the width enables
a weird CSS hack that allows you to specify a box with an unchanging
aspect ratio ...even if the box is rescaled.)
% with margin/padding

How to centering span

How to centering that download button? I tested many times but it's wrong codes.
.col {
width: 100%;
height: auto;
float: left;
}
.download {
width: auto;
font-weight: 600;
font-size: 14px;
color: #000;
border: 2px solid #000;
padding: 17px 37px;
margin-top: 30px;
float: left;
}
<div class="col">
<span class="download">Download</span>
</div>
Just add text-align: center; to .col and replace float:left with display:inline-block; in the button element. jsfiddle
Remove float:left; from .download (because it forces the element to be floated to the left).
Give display:inline-block; (It acts like inline element, it means you can center it by giving text-align:center; to its parent.)
JSFiddle
.col {
width: 100%;
height: auto;
float: left;
text-align: center;
}
.download {
font-weight: 600;
font-size: 14px;
color: #000;
border: 2px solid #000;
padding: 17px 37px;
margin-top: 30px;
display: inline-block;
}

HTML5 CSS3 <a> element not centering inside of <div> element

#buttoncontainer {
position: absolute;
top: 15%;
left: 23%;
width: 200px;
height: 500px;
}
.buttons {
position: absolute;
display: block;
width: 70px;
height: 70px;
font-family: DancingScript-Regular;
font-size: 100%;
padding-top: 50px;
background-color: rgba(255,255,255,.0);
padding: 15px 15px;
border: 5px solid white;
border-radius: 70px;
box-shadow: 0px 0px 5px 5px #000000, 0 0 5px 5px #888 inset;
left: 15%;
-webkit-transition: all .3s ease-in-out;
-moz-transition: all .3s ease-in-out;
}
.buttonText {
text-align: center;
display: block;
padding: 25px;
width: 70px;
height: 70px;
font-size: 100%;
text-decoration: none;
color: white;
}
#b11 {
top: 30px;
}
#b22 {
top: 170px;
}
#b33 {
top: 305px;
}
<div id="buttoncontainer">
<div class="buttons" id="b11">
Upload
</div>
<div class="buttons" id="b22">
Refresh
</div>
<div class="buttons" id="b33">
Logout
</div>
</div>
I am trying to make the element fill up its parent container. But for some reason it doesn't align itself- as a whole block element inside/center of it's container, but instead pushes itself downwards and to the right. Can't figure out what I am doing wrong.
EDIT: I forgot to mention that I need the padding to center the text vertically in the bubble. I also tried padding-top: 25px; an still no success on centering the a block element.
EDIT2: I added text-align: center which centers the text correctly in the a element, but again the a element is not centering inside the div.
Here is a Working Demo
Do this in your CSS -
.buttons { text-align: center;
position: absolute;
display: block;
width: 70px;
height: 70px;
font-family: DancingScript-Regular;
font-size: 100%;
padding-top: 50px;
background-color: rgba(255,255,255,.0);
padding: 15px 15px;
border: 5px solid white;
border-radius: 70px;
box-shadow: 0px 0px 5px 5px #000000, 0 0 5px 5px #888 inset;
left: 15%;
-webkit-transition: all .3s ease-in-out;
-moz-transition: all .3s ease-in-out;
}
.buttonText { /*
width: 70px;
height: 70px;*/
display: inline-block;
padding: 18px 0 0 0;
font-size: 100%;
text-decoration: none;
color: black;
}
This centers your text vertically and horizontally in the center of the button.
.buttonText {
text-align: center;
line-height: 70px;
vertical-align:middle;
display: block;
margin: auto auto;
font-size: 100%;
text-decoration: none;
color: white;
}
Hope this helps!
(EDIT: Adjust your line height to the height of the button. vertical-align:middle; will center it vertically)
Remove padding from class .buttonText
Add line-height: 70px;, text-align: center; to center the links.
.buttonText {
display: block;
line-height: 70px;
text-align: center;
padding: 0; /*Change padding to 0*/
width: 70px;
height: 70px;
font-size: 100%;
text-decoration: none;
color: white;
}
Here's a Fiddle
Remove this in your CSS:
.buttonText {padding: 25px;}
Make it as:
.buttonText {padding: 0;}
Thank you all for the suggestions....I finally got it to work with:
.buttonText {
margin-left: -23px;
margin-top: -23px;
position: absolute;
text-align: center;
padding: 28px;
padding-top: 50px;
padding-bottom: 50px;
font-size: 100%;
text-decoration: none;
color: white;
}
Not sure why this one gave me such a hard time...I usually don't have issues when doing buttons like these.

How do you make an IMAGE move independent of the elements around it using CSS3 Transition?

I'm trying to use a CSS3 transition to make the image inside this <div> move 10 pixels upward when the <div> is hovered over. It works great in Firefox, but when I view it in Chrome and Safari, the <h3> and <p> elements jitter up and down a bit.
This is my CSS:
.feature-table #box {
width: 325px;
height: 372px;
margin-right: 20px;
float: left;
}
.feature-table a {
display: block;
width: 325px;
height: 372px;
}
.feature-table a img {
display: block;
margin-left: auto;
margin-right: auto;
padding-top: 54px;
padding-bottom: 40px;
-moz-transition: all 0.3s linear;
-webkit-transition: all 0.3s linear;
transition: all 0.3s linear;
}
.feature-table a: hover img {
padding-top: 44px;
padding-bottom: 50px;
}
.feature-table a h3 {
font-family: 'GothamBold', sans-serif;
font-size: 30px;
color: #3d3d3d;
text-align: center;
text-decoration: none;
margin: 0;
padding: 0 25px;
}
.feature-table a: hover h3 {
color: #f6ce4f;
}
.feature-table a {
text-decoration: none;
}
.feature-table p {
font-family: 'GothamLight', sans-serif;
font-size: 14.5px;
color: #949494;
text-align: center;
padding: 10px 28px;
}
.feature-table .caret {
border-top: 5px solid #fff;
border-bottom: 5px solid #fff;
border-left: 5px solid #ffc235;
content: "";
display: inline-block;
height: 0;
width: 0;
margin-left: 10px;
}
This is part of my HTML:
<div id="box">
<a href="#">
<img src="images/payment_icon.png" width="114" height="115" border="0" />
<h3>Customizable Campaign Pages</h3>
<p>Tell your story with images, video, rich text and social updates<b class="caret"></b></p>
</a>
</div>
Any ideas?
It may be a performance issue because you're animating 2 different properties that affect the current layout.
The ideal solution would be to use a certain prop that doesn't affect the other elements. In your case, this can be done with the top property, after setting the image's position to relative :
a img{
position : relative;
top : 0;
}
a:hover img{
top : -4px;
}
Here's a working demo : http://jsfiddle.net/p7Lxz/