Content Before first p [closed] - css

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
Before only in the first paragraph
I try to do the following:
.answer p::first-letter:before{
content:'A';
}
How could you achieve the desired result.
I try to place the content only in the first paragraph of the container, which I think is like this:
nswer p:first-child:before{
content:'R';}
But it does not respect the first paragraph, but instead includes it in others in the same container.

If you simply need to insert something before a <p> element, then there is no need to specify the ::first-letter pseudo selector. A simple :before is enough.
.container > p:first-child:before {
content: "A";
}
.container > p:not(first-child) {
text-transform: capitalize;
}
<div class="container">
<p>typical</p>
<p>typical</p>
<p>typical</p>
</div>
Codepen here.

CSS is very specific, it will alter what you are selecting. If you want to change something before the first <p> in your html you should try and find that in your html and write a css selector for that element i.e. is if a <div> what is the class name of that div - that is what you want to select with the css. Maybe create a div, add a class name to it, put your <p> into it and write css for that new class. Hope that makes sense.

Im not sure exactly what you mean, but if its just the first paragraph you want a :before on then just add the class to your first p;
<div>
<p class="first_paragraph">
This is paragraph 1
</p>
<p>
this is paragraph 2
</p>
</div>
then apply your content.
.first_paragraph:before {
content: 'A_1';
}
JSFiddle
Alternatively, if your content is dynamic and you cant apply the css.
Then you can use the first-child combined with the before.
.paragraph_list p:first-child:before {
content: 'A_1';
}
Second Example JSFiddle

You were close!
Try this:
.answer p:first-child:before{
content:'A';
}

Related

css translate div to their parent [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I have a back-end background and I'm actually learning the front
my problem is with css transition
I'm trying to make a translation on all elements inside a div to join the top of this specific div
the best I could accomplish is moving them with a specific value or move them on X-axe wich don't interest me
you can see an example of the expected behavior in this fiddle( sorry for the code it's a learning state so lots of words)
https://jsfiddle.net/49gptnad/3878/
<div>
<p1>
<p2>
<p3>
<p4>
</div>
I understand the fact if I can move them on X-axe its because they can move inside their element but ...
I simply want them to all join the position of p1 (the highter p) when I click, it must be simple but as it's all new to me they must have something I missed
thanks in advance
The easiest way here is to adjust the height to 0 and keep overflow to have the needed effect. But since we cannot animate height from auto to 0 we can use max-height instead (also don't forget the default margin of p).
Here is a simplified example where I use hover:
.anime {
display:inline-block;
min-height:100px;/*to avoid flickering*/
}
.anime p {
transition:1s all;
max-height:50px;
}
.anime:hover p {
max-height:0;
margin:0;
}
<div class="anime">
<p>Photo 1</p>
<p>Photo 2</p>
<p>Photo 3</p>
<p>Photo 4</p>
</div>

How to add a space between paragraphs when using css reset? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
What is the safest/no height change cross-browser way to add a space between paragraphs when using css reset?
<div>
<p class="text">paragraph1</p>
<p> </p>
<p class="text">paragraph2</p>
</div>
<div>
<p class="text">paragraph1</p>
<br>
<br>
<p class="text">paragraph2</p>
</div>
http://jsfiddle.net/unknown601/0ewvk3c9/
I find it useful to include space between adjacent paragraphs.
Example: http://jsfiddle.net/kppb0nLx/3/
/* a paragraph proceeded by another paragraph will have a top margin */
p + p {
margin-top: 8px;
}
This allows you to keep paragraphs flush with the top/bottom of your container while still having space between them.
The options you listed (br and p purely for spacing) are not considered good practice. They don't represent the your content semantically and they create extra markup that can easily be replaced with CSS.
More Reading
The <br> tag should only be used to break line i.e <p>This is first line <br> This is second line.</p>
For spacing i would have to say on based on my personal experience & on observation of most of the frameworks margin is the best practice to create spacing between paragraph.
DEMO
CSS:
p{
margin: 0 0 10px;
}
Edit: I like #Tim Medora solution much better: p + p { margin-top: 8px; } by adding top margin to adjacent p tags we eliminate the first and last p tag margin issues commonly faced.

How to use CSS class/id to change other classes attributes? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
So I want to :hover on an element and I want the hovering to change an attribute of another class. How do I do it? I want to hover on to a button and it to change other div's display to display: block. I use only HTML and CSS.
You are limited by css, but there are possibilities with css selectors. I've made you a jsfiddle with a possible solution:
http://jsfiddle.net/6rT3Q/
CSS:
.item1:hover ~ .item3 {
background-color: red;
}
HTML
<div class="item1">
Hoverable item
</div>
<div class="item2">
Dummy item
</div>
<div class="item3">
Item to change
</div>
Here the ~ tells to look for succeeding elements. If you want the immediate next element you can use +.
More info about selectors:
http://www.w3.org/TR/2001/CR-css3-selectors-20011113/
Without using JS, you can change a child node of the element being hovered. For example if you had:
<div class="container">
<div class="box">Content</div>
</div>
You could use the below code to change the .box properties:
.container:hover .box
You can use javascript for this. Put your button in a div and use the following:
document.getElementById("buttonDiv").onmouseover = function() {
document.getElementById["divToHide"].style.display = "block";
};
For this you would use Javascript. For example with jQuery you could do:
$( "#hoveredElement" ).mouseover(function() {
$( "#otherDiv" ).css("display", "block"); //or just use .show() if it is
//initially hidden
});

non breaking white space between text and <a> [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 8 years ago.
Improve this question
How do i provide a non breaking white space between a text element and <a> tag all nested within a span
<span>
<label> this is xyz</label>
<a href ="">
</span>
I want to do this using CSS and not with
Also I have tried using all combinations of white-space, but it wasn't any good.
Please use follwing CSS and HTML:--
HTML:-
<span>xyzLINK</span>
CSS:-
a:before
{
content:" ";
}
a{text-decoration:none;}
See the fiddle:--
http://jsfiddle.net/npsingh/TJhh7/2/show
you can set a margin for the tag, and set white-space:nowrap to prevent breaking, if white-space property isnt working then there might be other styles that might be interfering with it, or even other html elements, as your current code in the question is not complete we cannot see what the full markup looks like and tell.
for instance if some style is setting your anchor tags to be block element (display:block;), this would cause it to break to new line even with white-space property. Try adding in display:inline to the style as well to see if it helps
html
<span>
<label> this is xyz</label>
some text
</span>
css
span {
white-space:nowrap;
}
span a {
margin-left:10px;
margin-right:10px;
display:inline;
}
JSFiddle Demo
If you want to use CSS, see the white-space property:
<span style="white-space:nowrap">
<label>this is xyz</label>
Stack Overflow
</span>

I want the P tag text on the same line next to each other [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I've been trying to align the P tag text left and right next to each other but can't get it to do so. They are both within the same divs and I'm coding in ems and % could anyone help?
You should use span instead of p which has a default display of inline
<span>Your text here</span>
The p element is default display block. If you insist on using p, then you need to dive into some CSS. Set a class for the p element (or ID if it is unique) like so
<p class="inline-p">Your text here </p>
Then in a separate CSS file, use a selector to reference that class. Please try to avoid inline CSS in your HTML. It can become a nightmare to maintain later.
.inline-p {
// Modify display for this class
display: inline;
}
You should avoid modifying the properties of HTML tags when there is an existing HTML tag that can accomplish what you are looking to do. Nevertheless, both your options are presented here. Good luck with your website.
make display:inline; for p tag
You can't align text left and right in the same p tag unless you use span. But you could do it using the CSS float property
<p style="float: left">Some text on the left</p>
<p style="float: right">Some text on the right</p>
You haven't posted any code for us to analyze, so speaking generally... you can mess with the "display" CSS style and floats to get them lined up as you need, or you could use a more appropriate tag that is already inline, like a span.

Resources