My styles are lost when I use a div within a p tag

My page requires a URL to be displayed for students without default browser styles, such as changing to a pointer on hover. However, when I wrap the text in a div, I lose my desired styles. Here is what I have:

index.html:

<p>
    Django has generated our first URL, the admin page. As this file serves as our URL entry point (as specified in `settings.py`), if our hostname is "www.eat-it.com",
    <div style="color:blue;">www.eat-it.com/admin</div> can now be accessed. More information about Django admin will follow.
</p>

styles.css:

body {
    background: #f0f0f0;
    width: 80%;
    margin: 0 auto;
}

h1 {
    text-align: center;
    margin-top: 35px;
    margin-bottom: 60px;
}

p {
    font-size: 20px;
    font-family: sans-serif;
}

.cl {
    margin: 38px;
    padding: 25px;
    background: #f8f8f8;
    font-family:DejaVu Sans Mono,Bitstream Vera Sans Mono,Courier New;
    font-size: 12px;
}

.fake-url {
    color: blue;
}

I attempted using .fake-url within the div,

<p>
    Django has created our first URL, the admin page. Since this file acts as our URL entry point (as specified in `settings.py`), if our hostname is "www.eat-it.com",
    <div class="fake-url;">www.eat-it.com/admin</div> is now accessible. More details about the Django admin will be discussed later on.
</p>

and then added this:

p, p div {
    font-size: 20px;
    font-family: sans-serif;
}

https://i.sstatic.net/gD539.png

Answer №1

My recommendation would be to consider using a span element instead of a div. Spans are inline elements and may be more suitable for the specific context you are working with.

Additionally, as pointed out by another user, there appears to be an extra semicolon within the class attribute of the div element.

Answer №2

<div> tags should not be nested inside <p> tags. When this happens, browsers typically close the <p> tag before the <div> tag and then reopen it afterwards. This causes the paragraph to be split into two separate sections.

Instead of using a <div> element within a paragraph, consider using a <span> or an <a> element.

You can find more information about this on MDN. The "Tag omission" section specifically mentions that if an opening <p> tag is followed by an opening <div> tag, the paragraph will be automatically closed.

Answer №3

<p>
    Django has created our first URL for us, which is the admin page. This file serves as the entry point for our URLs (as specified in `settings.py`). For example, if our hostname is "www.eat-it.com",
    <div class="fake-url">www.eat-it.com/admin</div> can now be accessed. More information about Django admin will be discussed later.
</p>

If we simply remove the ; from the class name in the div, it will resolve the issue.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Uploading a file using AngularJs

When it comes to uploading an image or file using HTML tag in AngularJS, it seems that the tag is not supported. The solution? Create a custom directive. In my index.html page, I included the following code: <body ng-controller="myController"> ...

Struggling with connecting relative hyperlinks

When constructing a website, I have opted to use relative hyperlinks. The file structure is organized as follows: /root/website1/ All my code resides within the website1 folder. Within website1, the structure looks like this: /css style.css /static ...

How can I implement a dynamic sidebar drawer in Bootstrap for my navbar?

Is it possible to achieve a layout similar to this example: I've come across some online examples using different versions of bootstrap, but they tend to alter the css too much, making it harder to grasp the concepts of bootstrap. I am curious if it ...

Increasing the font size by 1px for each element within a specified parent element

Is there a method to automatically increase the font size of all elements within the .wrap container by 1px, without having to adjust each one individually? .wrap{ margin-top: 169px; .element1{ font-size:31px; } .element2{ ...

Offspring component fails to reverse the skew as intended

Is it possible to skew a navigation bar without affecting the text inside it? I tried skewing the main div of the navigation bar and using a negative skew value on the text, but it didn't work as expected. How can I achieve this effect successfully? ...

What is the best way to refresh a video within an image carousel?

I'm encountering an issue with my image carousel that contains a video. The first time the video plays normally, transitioning to another slide at the end. However, on subsequent plays, the video remains paused at the end and requires manual intervent ...

Completing forms and tracking browser history when the document is ready

In my current webpage, I have code that automatically submits the form when the DOM is ready: $(function () { $('form').submit(); }); However, I've noticed that when a user clicks the back button on their browser on the next page, it t ...

Align the present domain using XPath

Is there a way, possibly with a newer version of XPath, to make the following code work: //a/@href[not contains("DOMAIN OF THE CURRENT PAGE")] The DOMAIN OF THE CURRENT PAGE should function as a variable that retrieves the domain - similar to something l ...

Automatically change div background image based on window resizing

.step-1-4 { background:url('../images/gadget-4-sprite.png') no-repeat; width:950px; height:70px; margin-left: 15px; } The code above sets the CSS for a div containing a background image. The dimensions of the div match that of the imag ...

Select the dropdown menu to access the last line of the table

My custom dropdown is causing a scroll to appear at the bottom of the table when it's open, making it hard to view all the elements. I want to find a way to either expand the body of the dropdown or enlarge it so that this doesn't happen. Can any ...

When context.getImgData() is invoked, it triggers a noticeable flickering effect on the canvas

Currently, I am integrating a webcam feed into a video element and then projecting it onto a canvas element. Subsequently, I am implementing face detection on the canvas to highlight faces with a square. The issue at hand arises when I call the context.ge ...

Problematic: BS4 Cards cannot be accommodated within the parent div.Improved: The

Within a dynamic-height parent div, I have two cards stacked on top of each other. However, the issue arises when these two cards do not completely fit inside the parent div. The problem likely stems from the table within the lower card, which is not respo ...

Implement a shadow effect on a customized image using Tailwind CSS

Can someone help me with this code snippet I have written: <script src="https://cdn.tailwindcss.com"></script> <div class="m-6 space-x-3"> <div v-for="m in media" class="w-[200px] h-[200px] inline-block"> <img class=" ...

The Dropdownlist menu from Metro UI CSS does not function properly when placed in an ASP page within a subfolder

I'm currently facing an issue with my asp.net application in C# that utilizes Metro UI CSS for the Dropdownlist menu. The problem arises when the Dropdownlist menu works properly on pages within the same folder as the master page, but fails to functio ...

Issues with html5 dropdown menu not displaying properly when hovered over

As a beginner in programming, I have been tasked with creating a website using HTML5 and CSS. The main issue I am encountering is with my horizontal menu bar that has vertical sub-menus appearing on hover. The menu consists of 3 main tabs: Home, Health, a ...

What is the alternative for * in CSS?

I have integrated a plugin into my project that necessitates the inclusion of the following code in its CSS file: *, *:after, *::before { -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; } However, t ...

Using React.js to create table cells with varying background colors

For my React application, I am working with a table that utilizes semantic ui. My goal is to modify the bgcolor based on a condition. In most cases, examples demonstrate something like bgcolor={(condition)?'red':'blue'}. However, I requ ...

Perform Jquery trigger on mobile by clicking, and on desktop by hovering

Despite encountering this question numerous times, I am still unable to find a solution. I have a dropdown menu and I want it to open on hover for desktop and on click for mobile devices. I attempted using the provided code, however, it only works after r ...

How can one import files from an external CSS template in CakePHP 2.x?

I recently acquired an external HTML template that I purchased from a website called themeforest: https://i.sstatic.net/UIu6g.png The folder structure is as follows: base/ - css/ - fonts/ - images/ - img/ - js/ - index.html The template file Index.html ...

How can I locate a div element using multiple class names?

<div class="value test" /> I am trying to locate this specific element on the web page which has two classes assigned to it. Since className does not accept space-separated values, I am exploring alternative ways to achieve this. Any suggestions? ...