Padding only applies to me in 1 div, why? - html

I write the same padding for 2 different div elements and it only applies to 1 of them.
I already tried applying the style to different elements, using margin, creating more divs, using width and probably more things, but can't find the solution. Also, is this a correct way of doing it? Should I use buttons instead?
HTML
<div class="login">
<div class="button1"><p class="pButton">Login to see list</p></div>
<div class="button2"><p class="pButton">Login to view profile</p></div>
</div>
CSS
.login {
text-align: center;
margin-right:2px 20px;
}
.button1 {
display: inline-block;
padding:2px 10px;
}
.button2 {
display: inline-block;
padding:2px 10px;
}
.button1, .button2 a {
background-color: #b0f4e6;
}

both div tags have same padding, and I've just found something wrong in your code.
in your CSS code,
/* It means applying background-color at .button1 and .button2 > a */
.button1, .button2 a {
background-color: #b0f4e6;
}
so, this codes would be like it
.button1, .button2{
background-color: #b0f4e6;
}
/* OR */
.button1 a, .button2 a{
background-color: #b0f4e6;
}
.login {
text-align: center;
margin-right: 2px 20px;
}
.button1 {
display: inline-block;
padding: 2px 10px;
}
.button2 {
display: inline-block;
padding: 2px 10px;
}
.button1,
.button2 {
background-color: #b0f4e6;
}
<div class="login">
<div class="button1">
<p class="pButton">Login to see list</p>
</div>
<div class="button2">
<p class="pButton">Login to view profile</p>
</div>
</div>

you can try [attribute^=value] selector. in this case , will use [class^="button"]

better u write ur code like this:
HTML
<div class="button1"><p class="pButton">Login to view List</p></div>
</div>
<div class="login">
<div class="button2"><p class="pButton">Login to see Profile</p></div>
CSS
.button1 , .button2 {
background-color: #b0f4e6;
}

.login {
text-align: center;
}
.button1 ,.button2{
display: inline-block;
}
.button1 a, .button2 a {
background-color: #b0f4e6;
padding:20px 10px;
color:black;
}
<div class="login">
<div class="button1"><p class="pButton">Login to see list</p></div>
<div class="button2"><p class="pButton">Login to view profile</p></div>
</div>
can u try this ?
that's all...

Related

Cant get 2 divs next to each other but on different sides of the page

I cant get 2 divs on the same line but one is aligned right.
.container>* {
display: inline-block;
background-color: rgba(0, 0, 0, .85);
}
.menulinks {
font-size: 50px;
padding-top: 0px;
padding-left: 10px;
text-decoration: none;
color: blueviolet;
float: left;
}
.menulinks:hover {
color: coral;
}
<div class="container">
<div>
<img src="assets/logo.png" width="150">
</div>
<div align="right">
Photos
About
Socials
</div>
</div>
It was working before when I had tables and stuff but I thought this would be easier. They are on the same line but the links just won't align to the right,
The other answers are good in specifying that you can achieve this with flexbox.
My answer shows another flexbox approach. If you define margin-left: auto on the most right element it will always be on the right, even if you have another element right next to the logo, see the added example content.
So my answer is not better than the other ones, it just shows a different way to solve your problem. Depending on if you need more elements in a row or not, chose this approach.
.container>* {
display: inline-block;
background-color: rgba(0, 0, 0, .85);
}
.menulinks {
font-size: 50px;
padding-top: 0px;
padding-left: 10px;
text-decoration: none;
color: blueviolet;
float: left;
}
.menulinks:hover {
color: coral;
}
/*Added CSS*/
.container {
display: flex
}
.right {
margin-left: auto;
}
<div class="container">
<div>
<img src="assets/logo.png" width="150">
</div>
<div style="width: 100px; color: white">
The links are on the right even if here would be another container (with a Slogan, or some other content)
</div>
<div class="right">
Photos
About
Socials
</div>
</div>
Since there are only two divs you could use display: flex and the attribute justify-content: space-between to put all of the extra space between the only two divs.
.container {
display: flex;
justify-content: space-between;
align-items: center;
background-color: rgba(0, 0, 0, .85);
}
.menulinks {
font-size: 50px;
padding-top: 0px;
padding-left: 10px;
text-decoration: none;
color: blueviolet;
float: left;
}
.menulinks:hover {
color: coral;
}
<div class="container">
<div>
<img src="https://placekitten.com/500/500" width="150">
</div>
<div align="right">
Photos
About
Socials
</div>
</div>
Different approach with minor adjustment to your existing code is to use float:right property to the links.
Worth to mention that the attribute "align" deprecated and all layout design need to be from the style sheet.
What i did is to change the align="right" to class="right" and then added on the style sheet .right {float: right;}.
Note: since you giving your links a 50px font-size, on small screen this will span 2 lines. In order to fix this you can add #media queries
Note(2): On the break point, i changed a little the .menulinks with font-size: 25px; display: block; float: none;
So your code can look something like that:
.container > * {
display: inline-block;
background-color: rgba(0, 0, 0, .85);
}
.menulinks {
font-size: 50px;
padding-top: 0px;
padding-left: 10px;
text-decoration: none;
color: blueviolet;
float: left;
}
.menulinks:hover {
color: coral;
}
/* added: */
.right {float: right;}
#media (max-height: 480px) {
.menulinks {font-size: 25px; display: block; float: none;}
}
<div class="container">
<div>
<img src="assets/logo.png" width="150">
</div>
<div class="right"> <!-- change from align="right" that deprecated -->
Photos
About
Socials
</div>
</div>
Firstly, I highly recommend removing your general * selector. It is best to be specific when targeting elements.
I would assign specific class names to your div's. I chose item in my example below.
align="right" does not work on non-table elements. That is why this is no longer working.
Use flexbox! I've added two lines of flexbox code in your container class.
.container {
display: flex;
justify-content: space-between;
}
.item {
background-color: rgba(0, 0, 0, .85);
}
.menulinks{
font-size: 50px;
padding-top: 0px;
padding-left: 10px;
text-decoration: none;
color: blueviolet;
float: left;
}
.menulinks:hover{
color: coral;
}
<div class="container">
<div class="item">
<img src="assets/logo.png" width="150">
</div>
<div class="item">
Photos
About
Socials
</div>
</div>

Need white text on my button instead of the orange I have for links

My normal hyperlink color is orange, but I want the hyperlink color in my button to be white and not to be underline. How would I do that?
Also, if I wanted some vertical spacing between the buttons how would I do that?
JSFiddle:
http://jsfiddle.net/huskydawgs/Uka5v/947/
HTML:
<p>Apple is cool</p>
<a class="btn" href="https://www.apple.com/">Get Started</a>
<a class="orange btn" href="https://www.apple.com/">Get Started</a>
<a class="blue btn" href="https://www.apple.com/">Get Started</a>
CSS:
.btn {
text-align: center;
border-radius: 0px;
background-color: #616161;
display: block;
color: #ffffff;
font-size: 15px;
font-family: sans-serif;
text-decoration: none;
line-height: 30px;
width: 138px;
margin: 0 auto;
}
.orange.btn {
background-color: #f66511;
}
.blue.btn {
background-color: #2251a4;
}
a:link {
color:#f66511;
text-decoration:none;
}
a:visited {
color:#f66511;
text-decoration:none;
}
a:active {
color:#f66511;
text-decoration:none;
}
a:hover {
color:#f66511;
text-decoration:underline;
}
You need to use
.orange.btn {
background-color: #f66511;
}
.blue.btn {
background-color: #2251a4;
}
(you were missing the "." infront of orange and blue which states the class.
For the vertical spacing, you can use this css:
.btn {
margin-bottom: 5px;
}
http://jsfiddle.net/Uka5v/940/
You're not defining the variated classes properly. Try this:
.btn.orange {
background-color: #f66511;
}
.btn.blue {
background-color: #2251a4;
}
As for vertical spacing, you can set a bottom margin on the .btn class. Since you already have a margin property, you can simply add to it:
margin: 0 auto 10px; // Added third argument for bottom value
Here's the updated JSFiddle.
EDIT: To change the color of the orange button, set a color property on the corresponding class:
.btn.orange {
background-color: #f66511;
color: #fff;
}
change your css to
.orange {
background-color: #f66511;
}
.blue {
background-color: #2251a4;
}
You just need to use
.orange {
background-color: #f66511;
}
.blue {
background-color: #2251a4;
}
And take a look at margin for adding vertical spacing.
I suggest you brush up on your html knowledge. Try codecademy for interactive tutorials.

How do I add my text inside the border?

I am trying to get my text within my border that I added as an image. I will be adding more text and would like it to show up in my border as I am writing it. Any help would be appreciated. Thanks!
li {
list-style-type: none;
display: inline-block;
font-size: 20px;
letter-spacing: 4px;
width: 150px;
}
.main-nav a {
text-decoration: none;
}
.main-nav {
border-bottom: 2px solid black;
border-top: 2px solid black;
}
a:link {
color: #008B00;
}
a:visited {
color: #008B00;
}
p {
font-size: 20px;
}
#main-border {
text-align: center;
}
.searchbutton {
font-size: 20px;
}
<div id="main-border">
<p>Hi! My name is Marika and I am excited to join the school soon!</p>
<img src="../desktop/background.gif" alt "border" height="500px" width="550px">
</div>
I could not understand your question but i think this is what you are looking for :
<div id="main-border">
<p>Hi! My name is Marika and I am excited to join the school soon!</p>
</div>
#main-border {
text-align: center;
background : url(../desktop/background.gif);
background-size : 100% 100%;
min-height : 500px;
min-width : 500px;
}
like this? obviously style to your liking
var place=document.getElementById('txtplace');
function add_text(txt){
place.innerHTML=txt;
}
#txtplace{background-color:grey;opacity:0.8;font-size:150%;position:absolute;top:100px;left:50px;}
<input type="text" id="text_to_add" onkeyup="add_text(this.value);"/>
<span id="txtplace"></span>
<img src="http://lorempixel.com/600/600" id="background">
I believe this is what you're looking to achieve (although, instead of a picture of a kitten, your image)
.THIS {
background-image: url(http://placekitten.com/g/500/500);
background-repeat: no-repeat;
height:500px;
width:500px;
}
<div id="main-border">
<p class="THIS">Hi! My name is Marika and I am excited to join the school soon!</p>
</div>
Late answer but if you are trying to add text in the border you can absolute position it and do it like this http://jsfiddle.net/vo7jzz4m/
div{
width:250px;
height:250px;
background:url('http://placekitten.com/300/301') no-repeat;
background-size:cover;
border:10px solid transparent;
outline:1px solid green;
}
div:before{
top:0px;
position:absolute;
content:"aA";
}

Make border-bottom closer to the text

Fiddle
Try
I have applied line-height, display properties. But none of these works fine with double lined text.
.container span {
width:80px;
border-bottom: 1px solid #aaa;
text-decoration: underline;
}
.container {
width: 20%;
display: inline-block;
}
<div class="container">
<span>My Cash & Discounts</span>
(0)
</div>
I have found this.
But it's not working fine.
Ques:
Please take a look at my fiddle. How to make border-bottom to match with text-underline? How to remove the gap between that two lines?
You could insert another container:
<div class="container">
<span><span class="inner">My Cash & Discounts</span></span>
(0)
</div>
And assign a negative value for margin-bottom:
.container span
{
border-bottom: 1px solid #aaa;
text-decoration: underline;
display:inline-block;
}
.container span.inner {
border:none;
display:block;
margin-bottom:-3px;
}
.container
{
width: 20%;
display: inline-block;
}

I'm trying to display images horizontally using CSS

I have a series of images I would like to display horizontally on my website, using CSS and divs. I've looked at several posts about how to display images horizontally already and I wasn't able to get any of them to work.
Here's the code from the page I'm referring to:
<head>
<link rel=StyleSheet href="style.css" type="text/css" media=screen>
<style>
div.imageBox {
float: left;
margin-right: 10px;
}
div.imageBox p {
text-align: center;
}
</style>
</head>
<body>
<?php include 'header.php'; ?>
<div id="content">
<div id="container">
<div class="imageBox">
<img src="image" width="800" height ="600">
</div>
<div class="imageBox">
<img src="image" width="600" height ="450">
</div>
<div class="imageBox">
<img src="image" width="800" height ="450">
</div>
</div>
</div>
</body>
and here's the code for the style sheet:
body{
font-family: helvetica, arial, sans-serfif;
font-size: 14px;}
div#menu {
display: inline;
text-align: center;
width: auto;
top: 20px;
margin-left: 10%;
margin-right: 10%;
background: transparent;
height: 10px;
position: fixed;
}
div#menu ul {
margin: 0;
display: block;
}
div#menu ul li {
padding-right: 55px;
display: inline;
}
div#content {
padding-top: 40px;
text-align: center;
}
div#container{
float: left;
display: inline;
height: 800px;
width: 0px;
}
a:link {
text-decoration: none;
color: #000;
}
a:active {
text-decoration: none;
color: #000;
}
a:visited {
text-decoration: none;
color: #000;
}
a:hover {
text-decoration: underline;
color: #000;
}
Is there perhaps an easier way for me to do this?
Thanks for your help!
Try to change
div#container{
float: left;
display: inline;
height: 800px;
width: 0px;
}
into
div#container{
float: left;
display: inline;
height: 800px;
white-space: nowrap;
}
add:
div.imageBox {
float: left;
margin-right: 10px;
display:inline;
}
You're using divs which are block elements when you should be using something inline.
Images will align next to each other. If you need the divs, you can give them the style display: inline to make them behave in the same way. You can also use float: left, but that will make things harder in most cases.
You can apply styles like margins and borders to images too, so you may not need the divs. Although I'm not sure how you want it to look exactly.
Here is the example: http://jsfiddle.net/hobobne/d5sYM/
<html>
<head>
<style>
img {width: 100px; height: 100px;}
.imageBox {display: inline-block; border: 1px solid grey; background: silver; padding: 4px; text-align: center; font-size: 10px;}
</style>
</head>
<body>
<div class="imageBox">
<img src="http://screenshots.en.softonic.com/en/scrn/80000/80669/easter-icons-5.jpg"><br>
Image 1
</div>
<div class="imageBox">
<img src="http://l-userpic.livejournal.com/82523298/2181918"><br>
Image 2
</div>
<div class="imageBox">
<img src="http://www.jellymuffin.com/icons/emo/images/30.jpg"><br>
Image 3
</div>
</body>
</html>