I want to define the style of Div based on a CSS file. The CSS code I have written is:
.body
{
text-align: center;
padding: 1px;
margin: 1px;
color: black;
background-color:lightgrey;
}
I want the background of each Div section to be light-grey. What's wrong with the above code?
Edited:
This is my HTML code. I changed the Div class as suggested below, but it is not working. Please also check whether the Link tag contains path correctly or not. The CSS file is located in a Lib folder, up-one-level.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Add/Update Political Party</title>
<link rel="stylesheet" href=".\Lib\entryformstyle.css" type="text/css"/>
</head>
<body>
<div id="sectionEntryForm" class="div">
<table id="tblEntryForm" cols="2">
<tr>
<td colspan="2" align="center">Add/Update Political Party</td>
</tr>
<tr>
<td>Party full name:</td>
<td><input id="inPartyFullName" name="inPartyFullName" accept="text/plain" maxlength="80" class="inputBoxStyle"></td>
</tr>
<tr>
<td>Party short name (initials):</td>
<td><input id="inPartyShortName" name="inPartyShortName" accept="text/plain" maxlength="80" class="inputBoxStyle"></td>
</tr>
</table>
</div>
</body>
</html>
Nothing, you just have to use <div class="body"> to make the DIV pick it up.
ALL DIVs:
div
{
text-align: center;
padding: 1px;
margin: 1px;
color: black;
background-color:lightgrey;
}
DIVs with class "body":
div.body
{
text-align: center;
padding: 1px;
margin: 1px;
color: black;
background-color:lightgrey;
}
If your CSS file is up one level, you have to include it like this:
<link rel="stylesheet" href="../lib/entryformstyle.css" type="text/css"/>
This only works on the class "body", that is
<div class="body">
If you want it to work on any divs, the selector (".body" in your sample code) should be div.
try deleting the period (.) before 'body'
edit: it is also probably worth having a quick read of this post
it explains the difference between "." and '#' when defining styles.
For this style to work, your div needs to be written like this:
<div class="body">Your text here</div>
In other words, the . in front of the body in your css tells the browser to apply the style in the braces to an element whose class is named body.
Try changing:
background-color:lightgrey;
to
background-color:silver;
or
background-color:#CCC;
This is assuming that your div has the body class applied:
<div class="body"></div>
Either use
div
{
text-align: center;
padding: 1px;
margin: 1px;
color: black;
background-color:lightgrey;/*#CCC*/
}
to set background color of all div
Or use
div.body
{
text-align: center;
padding: 1px;
margin: 1px;
color: black;
background-color:lightgrey;
}
and set <div class="body"></div> for each div.
You can use inline stylesheet as :
<div style="background-color:lightgrey;"></div>
Related
I used text-align:center to center the three divisions, but they are all aligned on the left.
I was told that because these three elements are all block, so they wouldn't center.However, I tried to add display:inline-block, but when I inspected the page, it still showed me display:block.
Here's my code:
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
.Google-logo {
width: 250px;
}
.Google-search-box {
font-size: 13px;
padding-left: 15px;
height: 30px;
width: 460px;
border-radius: 15px;
border-style: solid;
border-color: rgb(160, 157, 157);
box-shadow: 0 1px 6px rgb(183, 181, 181);
margin-top: 15px;
}
.div {
text-align: center;
}
</style>
</head>
<body>
<div>
<img
class="Google-logo"
src="images/Google_2015_logo.svg.png"
alt="Google logo"
/>
</div>
<div>
<input
class="Google-search-box"
type="text"
placeholder="Search Google or type a URL"
/>
</div>
<div>
<button class="left-button">Google Search</button>
<button class="right-button">I'm Feeling Lucky</button>
</div>
</body>
</html>
Very simple,
div is not a class, is a html element, so do this;
CSS
div {
text-align: center;
}
You can do it in multiple ways, the simplest and the first way is to write a CSS like:
div {
text-align: center
}
The second way if you want to use a inline CSS in your HTML code itself:
<div style="text-align:center">
The third way is what you were trying to do by using classes/id for that you need to change both your HTML and CSS code:
*for class
HTML:
<div class="center"> </div>
CSS:
.center {
text-align: center,
}
*for id
HTML:
<div id="center"> </div>
CSS:
#center {
text-align: center,
}
And most importantly div is not a class it's an HTML tag so your code didn't work because you used
.div {
text-align: center,
}
in your CSS code and the . symbolizes a class whereas if you had written it like this it would have worked as it would have given the text center to all the divs present in your code
div {
text-align: center,
}
But I feel you should use classes and center the text in div so that it could be specific to the div you wanna center texts for so try to prioritize the second or third way over the first one.
I want to know how I can change the background size around a link.
here is my HTML
<!DOCTYPE html>
<head>
<title>Library for Macintosh games.</title>
<link rel="stylesheet" type="text/css" href="styles.css" />
</head>
<body>
<h1>Old Mac Games for Free</h1>
<p>Google</p>
<script src="javascript.js" type="text/javascript">
</script>
</canvas>
</body>
</html>
here is my CSS
html {background-color: #d0e0c9}
h1 {
font-family: Arial;
font-weight: bold;
text-align: center;
margin-bottom: 85px;
margin-top: 85px;
font-size: 45px;
}
#link {
background-color: fuchsia;
text-align: center;
margin:500;
height: 100px;
width: 200px;
}
I believe you're referring to the padding of the link element.
If you'd like to increase the appearance of the background of the link element, you can easily add in this css:
#link {
background-color: fuchsia;
text-align: center;
padding:2em;
}
You should be able to see the link's "background-size" easily.
You can see a working demonstration here: http://codepen.io/anon/pen/xOVYvL
I invite you to check out some further reading:
https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Box_Model/Introduction_to_the_CSS_box_model
If you want to change the size of the link's text, you can use
<span style="font-size: 10px;"> <a href"..."> Text Here </a></span>
If you want to change the font color, "color: blue;", if you want to change the background color "behind the text":
<div style="background-color: black;">
<span style="font-size: 10px;">
<a href"...">
Text Here
</a>
</span>
</div>
And you change the size of the div like this:
<div style="width: 100px; height: 5px">
<div style="width: 50%; height: 5px; margin: auto;">
Here is a link to common CSS styling: http://www.w3schools.com/css/default.asp
EDIT: Also, its pretty unclear what you mean by "background size" you might want to be a little more specific when you post a question!
I am trying to give the date a margin of 15px between the bottom of the header and the text itself, but it doesn't move no matter what I tried.
HTML:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<link type="text/css" rel="stylesheet" href="stylesheet.css"/>
<script src="myscripts.js"></script>
<title>The Impertus ยท Understand the News</title>
</head>
<body>
<div id="Preheader">
<img src="images/masthead.png">
<div class ="ph" id="hd"></div>
<p class="ph">May 14, 2016</p>
</div>
</body>
</html>
CSS:
#import url('https://fonts.googleapis.com/css?family=Oswald');
html, body {
background-color: #E1D4C0;
margin: 0 0 0 0;
}
.ph {
display: inline-block;
margin-bottom: 15px;
}
#Preheader {
height: 150px;
width:100%;
background-color: #104386;
font-family: Oswald;
color: #F5EDE3;
}
Created Fiddle here: https://jsfiddle.net/fhkh6ae0/
Add .ph { vertical-align:15px; }
See https://jsfiddle.net/fhkh6ae0/2/
Try
.ph {
padding-bottom: 15px;
}
I think your issue lies in your html elements display property.
I see you are using this for the .ph class:
display: inline-block;
In order for your elements to align next to each other, but I think what you are trying to achieve here is possible by applying a float to your #hd and .ph elements:
float: left;
Here is some detailed information on CSS Floats by CSS-Tricks. The method you are using can be a good thing to do in a lot of specific situations, but for your specific case, I think this is the right path to take.
Here is a Fiddle for you.
You can see I changed some things and I added new things. One is the float property I am referencing above, and I have added an overflow: hidden property to the main container #Preheader , this is a fix for floating elements that try to escape their position or break your layout in bits. Remember the last one.
Just add a padding in #Preheader and it will be okay. take a look https://jsfiddle.net/fhkh6ae0/3/
#Preheader {
height: 150px;
width:100%;
background-color: #104386;
font-family: Oswald;
color: #F5EDE3;
padding-bottom:15px; /*added*/
}
I am programming a website for work (have almost no coding experience, so I might be missing crucial info - will update as needed). DOCTYPE html Public, link href="includes/style.css" rel="stylesheet" type="text/css" media="all"
<div id="main">
<table border="1" style="width:100%">
<...>
</table>
</body>
</html>
</div><!--#main -->
I've set up a table of names using following formatting in the .html doc:
<div id="main">
<table border="1" style="width:100%">
<...>
</table>
</body>
</html>
</div><!--#main -->
Now, in style.css, tables are defined as follows
table.hist-table {
width:98%;
border: 1px solid #CCC;
font-size:12px;
border-spacing:0px;
}
.hist-table tr{
border:1px solid #CCC;
}
.hist-table .row1 td {
padding: 4px;
margin: 3px;
border: 0px solid #ccc;
vertical-align: text-top;
background-color: #eff0f1;
}
.his-table th {
padding:4px;
text-align: left;
background-color: #00274c;
color: #FFF;
font-weight: bold;
}
#header {
margin-top: 30px;
clear:both;
background: #536a93;
background: #00274c;
padding: 0px 0 10px 60px;
margin: 0 4.6%
font-size: 11px;
max-width: 1000px;
}
For some reason, when opening the .html webpage, the table does not include a border, so it is very difficult to distinguish the rows of text from one another. Does anyone have a possible solution?
You're .html document should be set up as follows,
<...DOCTYPE etc...>
<html>
<head>
</head>
<body>
<div id="main">
<table>
Table contents...
</table>
</div>
</body>
</html>
This is because your tags should encompas almost all of your document. The and tags should both be encompased by the tag. Then within your tag should be all of your external links to your css files, external fonts etc.
Inside of your tag should be all of the , , and all of the other tags.
I hope this helps. I may not have understood all of your points but it looks the be the arrangement of your html document that is the problem. :)
Why isn't the text align changed? Here's my HTML.
<!DOCTYPE html>
<html>
<head>
<title>CSS 3 Animation</title>
<style>
.table
{
width: 400px;
height: 80px;
border: 1px dotted black;
}
.animatedMargin
{
font-size: xx-large;
-webkit-animation: marginAnimation 1s;
}
#-webkit-keyframes marginAnimation
{
from {text-align: left}
to {text-align: right}
}
</style>
</head>
<body>
<table class="table">
<tr>
<td class="animatedMargin">
SAMPLE TEXT
</td>
</tr>
</table>
</body>
</html>
I've changed text-align to background to see if it works, and it did. So is it something with text-align?
text-align is not supposed to be a transitionable property.
I think text-align simply can not be animated.
Exactly text-align is not supposed to be a transitionable property.