2

Im trying too get CSS too work on my page but I can't fix this. Can some one take a look at my code and help me?

This is the place where I want my css. Css pagename is StyleSheet.css

@model IEnumerable<DNDB.Models.Domeinnaam>

<head> @Styles.Render("~/Content/StyleSheet.css") </head>
@{
ViewBag.Title = "Index";
}
<h2>Domeinnaam Overzicht</h2>

<p>
@Html.ActionLink("Voeg toe", "Create")
</p>
<table class="tabledomeinnamen">
<tr>
    <th>
        @Html.DisplayNameFor(model => model.IsActief) 
    </th>

This is my _layout page:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>@ViewBag.Title - My ASP.NET MVC Application</title>
<link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
<meta name="viewport" content="width=device-width" />
@Styles.Render("~/Content/StyleSheet.css")
@Scripts.Render("~/bundles/modernizr")
</head>

StyleSheet.css

#body {
width: 100%;
background-color: red;
} 

#tabledomeinnamen {
margin: 0 auto;
width: 60%;
color: white;   
background-color: red;
}


#tabledomeinnamen td {
    padding-left: 10px;
    padding-right: 10px;
    border: 1px solid white;
    background-color: forestgreen;
}
#Banner {
width: 75%;
margin: 0 auto;
text-align: center;

}

#Footer {
width       :75%;
margin      :0 auto;
color       :black;
clear       :both;
text-align  :center;
padding-left: 25px;
padding-right: 25px;
}
#menu {
text-align: center;
}

Can some one tell me or explain me how I should fix this?

EDIT: I'm kinda new to programming so this isn't easy for me.

17
  • You should show your output, do you have any errors? Commented Nov 15, 2016 at 9:13
  • i don't. It just won't work. The css that is on my layout page works. But for example I have #table td { padding-left: 10px; padding-right: 10px; border: 1px solid white; background-color: forestgreen; } And that part is on my other page. this won't work. Commented Nov 15, 2016 at 9:14
  • which version of asp.net MVC? Commented Nov 15, 2016 at 9:15
  • Strange location to declare your head section. Where is your body section? Commented Nov 15, 2016 at 9:17
  • 1
    if u used any of these answers which are below. Mark them as answer :) Commented Nov 15, 2016 at 9:36

1 Answer 1

4

Your CSS is wrong, you are using an ID selector instead of a class selector. The hash (#) means that you call to a ID within your HTML. But if you look at your HTML you only have a class defined on the table. To select elements with a specific class, write a period (.) character, followed by the name of the class in your CSS.

More information about ID's and classes can be found here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.