paragraph with border - css

I have paragraphs on a page which i would like to add a border.
<p class="valid">paragraph</p>
CSS
p.valid {
padding:5px;
border: 1px solid #ccc;
}
The Problem is this displays the paragrph as 100% of the page
I have also tried adding inline-block which wraps the text as i would like, but inline is like float left.
p.valid {
padding:5px;
border: 1px solid #ccc;
display: inline-block;
}

When you float the element, also set it to clear any (left) floating elements:
p.valid {
padding:5px;
border: 1px solid #ccc;
display: inline-block;
float: left;
clear: left;
}
From the MDN documentation:
The clear CSS property specifies whether an element can be next to floating elements that precede it or must be moved down (cleared) below them

I would use a <span> tag instead of <p> because a paragraph is supposed to extend across the entire page, and it looks like <span> will help you more with what you're trying to accomplish.

Related

Block border + text border of different color in CSS

I'm trying to achieve this in CSS:
I would like the green line to always be the width of the text (no fixed width). I have a constraint, the tex is contained in an H3 tag with no ability to add a span tag inside it.
you could maybe try this aproach also:
<div class="container">
<div class="line"></div>
<h3>RECENT EPISODES</h3>
</div>
.container {
width:100%;
position:relative;
}
h3 {
display:inline-block;
border-bottom:1px solid green;
padding-bottom:10px;
margin:0;
position:relative;
}
.line {
height:1px;
background-color:#ededed;
width:100%;
position:absolute;
bottom:0;
}
http://jsfiddle.net/az6pr1mz/
The grey line needs to go on a block level tag while the green needs to go on an inline tag. This means that you need two nested tags for it to work and that you must either add a span inside the h3 or a div surrounding it. An h3 can always be made inline if needed.
A slightly different approach would be to add the secondary element outside the h3 without surrounding it and position that so it lies directly under the h3.
In any case, you will need a minimum of two elements for the borders to cling to.
Update:
I missed that you don't need span inside the h3. I added a workaround. I am not sure whether this is the only solution. But I think it can be improved though. In the below code, I am using css content property to hide the border of the container.
NOTE: Use as many dots . as you can use to make it work on all resolutions.
CSS
.container {
border-bottom: 1px solid red;
padding-bottom: 10px;
position: relative;
max-width: 100%;
word-break: break-all;
}
.container:after {
content:"....................................................................................................................";
color: transparent;
border-bottom: 1px solid green;
padding-bottom: 10px;
position: absolute;
bottom: -1px;
}
Working Fiddle
For example this code: (is clearly and not uses absolute positions)
HTML:
<h3><span>Recent episodes</span></h3>
CSS:
h3{
text-transform:uppercase;
border-bottom:1px solid #ccc;
}
h3 span{
display:inline-block;
border-bottom:1px solid #080;
margin:0 0 -1px 0;
}
http://jsfiddle.net/tp0nnapu

Why isn't this CSS :after triangle appearing correctly?

I am trying to make a CSS :after triangle the usual way. But it does not look as a triangle at all, please see http://jsfiddle.net/lborgman/eX3HL/:
/* triangle after */
#st:after {
position: relative;
margin-left: 10px;
content:"";
border-top:4px solid transparent;
border-bottom:4px solid transparent;
border-left:4px solid black;
}
#st {
line-height: 2em;
}
If I change "position:relative" to "position:absolute" the triangle will become a triangle. But that does not work where I want it (because it is on a float div).
What can I do?
Add display:inline-block to fix the triangle
#st:after {
position: relative;
margin-left: 10px;
content:"";
border-top:4px solid transparent;
border-bottom:4px solid transparent;
border-left:4px solid black;
display: inline-block;
}
JS Fiddle: http://jsfiddle.net/eX3HL/2/
It's a phenomenon that has to do with the native display of an object. The native display property of span is inline. Inline elements behave like plain text, while block elements behave more like images.
In your example when you do not override the default property of the span your element behaves like text and thus has also an font-size shadow-property which is set to inherit. It's an unexpected behavior since the shadow-properties are not visible to developers directly, so causing a lot of unclarities. You don't have to just believe my words, here is a proof: http://jsfiddle.net/eX3HL/5/

Border ignores an element

Ok so i have text inside a border that's inside a bigger border. The text inside the border is in a row of 2 but the problem is the larger border doesn't go around them. Here's a picture.
The problem i'm pretty sure is either the width or the float of the inside border which makes it a row.
Here is the css:
.fifty {
width: 45%;
float: left;
}
Here is the css for the actual border:
.newspaper3 {
border-top: 3px solid #EEEEEE;
border-bottom: 1px solid #EEEEEE;
border-left: 1px solid #EEEEEE;
border-right: 1px solid #EEEEEE;
padding: 5px;
margin-right: 3px;
}
Here's part of the html:
<div class="count">
<div class="fifty">
<div class="newspaper3">
text
</div>
</div>
</div>
Here's all the html and css http://jsfiddle.net/ELSaV/
Thanks for the help!
Is this what you are looking for?
http://jsfiddle.net/gespinha/ELSaV/4/
Basically your issue is caused by the float: left CSS attribute on the .fifty element. Using the float attribute removes the element from the actual document flow, so its position is ignored by other elements.
To reassign its position to the document flow, you should add an element that has a clear attribute after the one that has the float attribute. This clear should have the value which you wish to clear. In this case it should be left, but in case you need to reuse this element later in your project, you should create a class that clears both.
So, to solve your problem, and reassign .fifty to the document flow I created an empty div element with a class name .clear, and in the CSS I attributed this class a clear: both.
.clear {
clear: both;
}
In order for .fifty children to be displayed in a row, you simply need to assign them the same float attribute, which pushes them in the same direction, forcing their alignment within the parent element.
.newspaper3 {
border-top: 3px solid #EEEEEE;
border-bottom: 1px solid #EEEEEE;
border-left: 1px solid #EEEEEE;
border-right: 1px solid #EEEEEE;
padding: 5px;
margin-right: 3px;
float:left; /* ADD THIS */
}
Note: as I said I just attributed the value of both to this clear element, because I am assuming you could need it later in your project, although, in this case, you only need to clear the left float. There are other ways of establishing a clear on your floats, this is just one strategy.

a href ruins div button gives random border

I added a CSS button like this:
http://pastebin.com/UZCgmqSN
Why can't I use simple HTML code?..
The link href gives the button a blue border + text color, and whenever I removed <A> from it, it still stays the same.
I want the whole button to be one link, not like you need to hover on the text to go to that link.
Basically I don't want the a style affect my button(s).
solution could be: disable Link styling on specify divs
thank you.
Add a padding to the this will make the area around the text also clickable.
Also, apply the following style:
a {
text-decoration:none;
}
a div {
background:#444;
color:#fff;
border:1px solid #333;
text-align:center;
padding:5px;
width:100px;
}
This should do it.
check this out : http://jsfiddle.net/yFZ4y/
EDIT : Using a div or ANY block level element inside an INLINE element (like a) is bad practice. Please use a span instead.
here is an example of a link/button http://jsfiddle.net/CRjrz/
<div>
link text
</div>ā€‹
a
{
display: block;
width: 100px;
height: 35px;
text-decoration: none;
color: black;
text-align: center;
line-height: 35px;
}
div
{
border: solid 1px black;
width: 100px;
height: 35px;
}ā€‹

How can I make an underline some pixels longer than the headline?

I am currently trying to make a custom underline with border-bottom. However, currently the underline is going all the way of my block-element (whole page).
Iā€™d prefer to have it being only 50px longer than my headline (however the text is flexible and I do not know the length).
Can I do this without adding another <span> tag within the <h2> somehow? I do not wannt to add a <span> element to each <h2> just to change my design.
Current HTML is:
<h1>My title</h1>
CSS:
h1 {
font-size: 18px;
color: #b62525;
border-bottom: 2px solid #c68181;
}
Is it possible to adjust the border-bottom length to my text length? (e.g. behave like inline element for border, but like block for newlines, padding and margin)
Using display: inline-block works, the only caveat being that the content after the <h1> tag must be the full width of the container element. The other solutions here also assume this. You can also use display: inline (supported by older browsers), but inline-block allows for setting of explicit widths, should you need it.
Here's a JSFiddle
CSS
h1
{
display: inline-block;
padding-right: 50px;
border-bottom: 1px dotted #888;
}
Inline or floating methods can be problematic if you're unable to compensate for them in other rules. One alternative is to use display:table
h1
{
display:table;
border-bottom:1px solid black;
padding-right:50px;
}
You can use
h1 {
font-size: 18px;
color: #b62525;
border-bottom: 2px solid #c68181;
float: left;
padding-right: 50px
}
Simply add one more property in css like this :
h1 {
display:inline;
font-size: 18px;
color: #b62525;
border-bottom: 2px solid #c68181;
}

Resources