What is the best way to combine a border with some text like so:
----------- sometext ------------
| |
| form |
| |
---------------------------------
As it's for a form, you should use a fieldset element.
See: http://jsfiddle.net/thirtydot/AVGsr/
METHOD:
For use with anything even when not using the forms fieldset, you can use my method in this JSFiddle (It does NOT use Javascript, JSFiddle can be used for pure HTML & CSS), I will explain what it does in here:
What the fiddle demonstrates is having 3 divs as the top single border area, made up of 2 divs either side with a 1px border in the middle, and one on each side, and the middle div having text only, aligned to the center and padded as needed.
There is then a div placed underneath that which is the main content, but it only has 3 borders (left, right and bottom. The top has been made by the side div's).
The CSS and HTML is here, and JSFiddle link underneath.
FEATURES:
This method should fit all your criteria
Border text is in the place of part of the top border
Border text is central, can be placed anywhere along by modifying the CSS
Easy to change dimensions of the bordered area
CSS:
.wrapper-box { float:left; width:500px; height:150px; }
.side-border { float:left; height:24px; width:199px; border-top: solid black 1px; margin-top:25px; }
.side-border.l { float:left; border-left: solid black 1px; }
.side-border.r { float:left; border-right: solid black 1px; }
.border-text { float:left; height:35px; margin-top:15px; width:100px; text-align:center; }
.box-content { float:left; width:498px; height: 100px; border-left: solid black 1px; border-right: solid black 1px; border-bottom: solid black 1px; }
HTML:
<div class="wrapper-box">
<div class="side-border l"></div>
<div class="border-text">Border Text</div>
<div class="side-border r"></div>
<div class="box-content"></div>
</div>
EXTRA INFO:
To modify the CSS for longer text, just reduce the width of the border-text, and increase the width of the side-border.
JSFiddle Example Here
Hope this helps you out, I'll be keeping this for future reference myself :).
Define a division with border and put a heading in that division.
To make the heading overlap the top border, define a negative top-margin appropriately.
To make the line around the heading disappear define the background color of the heading same as the original background.
Here goes the code:
<div class="container" style="border: 1px solid black;">
<h4 style="margin-top:-1%; background: white;">Heading</h4>
</div>
Very similar to this discussion: How to center the <legend> element - what to use instead of align:center attribute?
As was said there, using the tag is a pain if you want consistent results across browsers. To achieve this effect, I'd use a <h> tag or <div> instead for the legend.
Here's a example: http://jsfiddle.net/CddE7/
Tested in Firefox, Chrome and IE 7,8,9 for PC. The vertical placement of the <h3> varies slightly by IE version but only by a little (and probably could be refined for more uniformity).
Since I assume people will complain about using an <h3> instead of a <legend>, yes, it's not as semantically correct. But it works.
Supporting the previous answer, the fieldset element came in html 4 and it helps to group like items within a form and creates a set or a field of like items or you can wrap all the items contained in your form..
e.g.
<form><fieldset><legend>Name of your field/Some Text(your case)</legend>
Then you can add your labels and inputs in p tags or table, but the p tag is more preferable. At the end close your fieldset and form tags.. and add this type of code to your css
fieldset{
border: thin dashed #000;
}
You can add border to your form elements in this way..
Related
Before flagging this as already asked, pls read the whole scenario. Thanks
SHORT VERSION :
Just to clearly state what i am trying to achieve, here's the page https://www.facebook.com/MercedesBenzPolska/ and I want to add border to the target element (on which i am hovering), whether it be <div> or <img> or <p>, without the shaking
DETAILED VERSION
Webpage in question: Any of Facebook's page.
Requirement: Moving a cursor over an element should add border to the target element [only on hover therefore temporary border not permanent]. Permanent border will be added ONLY if I click on that element. [Simply, if I hover over an element it will be highlighted with, say, pink border and only when i click on it, a green border would be added]
Initial problem: adding border on elements on hover would make the whole page's structure shaky, since I am constantly adding and removing the border. For that what I did was add a transparent 1 px border to all the elements of the page, and on hover just change the color of the border from transparent to pink; thus no shaky.
Present problem: The above solution was working for all the pages till I encountered Facebook's page. It turns out adding the initial 1 px border totally disrupts the structure i.e. the look and feel of the page. DIVs move from somewhere to somewhere else.
How do I now solve my original problem? Is there a way of, maybe like, applying a negative margin or border, so that adding the extra 1 px border does not dirupt the page's structure? I don't know I am just suggesting. Pls help
[SCREENSHOTS]
1. this is when the page loads [without applying the border]
2. Now when I hover over the div containing image ie adding 1 px border on hover, the divs move here and there
css I am using
* { border: 1px solid transparent !important;} //when page loads
.hover-selected{ border: 1px solid #e42a78 !important;} //on hover border
.option-selected:hover { border: 3px solid #529c56 !important;cursor: default;} //when option is selected
The images and the css both reflect towards the same problem, the default 1px transparent border disrupts the page's css and If I don't do that, the on hover border application becomes shaky and the page's css anyway gets disrupt
box-shadow: 0px 0px 0px 1px #000;
Use box shadow instead border. Box-shadow don't take up space.
div {
width:300px;
height:300px;
background: red;
}
div:hover {
box-shadow: 0px 0px 0px 1px #000 inset;
}
<div> Test </div>
outline is perfect for this. It works in a very similar way to border but does not effect layout at all.
div:hover {
outline: 1px solid orange;
}
<div>
Lorem ipsum sit amet.
</div>
<div>
<img src="https://placehold.it/200x100">
</div>
<div>
Lorem ipsum sit amet.
</div>
you can use box-sizing property in css. Try below code with and without box-sizing property
<div class="item">
</div>
.item {
box-sizing: border-box;
height: 50px;
width:50px;
background:red;
}
.item:hover{
border:1px solid black;
}
I would start from something like this and move from there:
*:hover:last-child:before {
display:block;
content:"";
position:absolute;
top:0;
bottom:0;
left:0;
right:0;
border:2px solid red !important;
}
Using a pseudo-element instead of putting a border on the actual object might not create as many issues with the initial layout. Still not exactly what you asked for, but I believe it's at least a bit closer. :-)
EDIT
I believe that the only way to achieve this as good as possible would be to be less greedy when selecting elements in the CSS, and specify a list like so:
a:hover:before,
img:hover:before{
display:block !important;
content:"" !important;
position:absolute !important;
top:0 !important;
bottom:0 !important;
left:0 !important;
right:0 !important;
border:2px solid red !important;
}
Okay, I am working on a custom parser for a personal variant of the Creole markup language, and I'm having trouble with a macro I added, which centers text.
Given the following CSS code:
.boxsection {
text-align:left;
border:1px solid #333;
padding:10px;
margin:10px;
background:1px solid #ccc;
}
and the following HTML code output by the parser:
<div class='boxsection'>
<span style='text-align:center'>
<h4>Center</h4>
<pre><<center>>Some text in the middle<</center>></pre>
This macro causes the content inside of it to be centered.
</span>
</div>
The heading and the text in the block all renders centered, but the last line does not center at all, even though it is inside of the span. I have tried changing the span to another div, with display set to inline, but that didn't work.
The only thing that does work is using the tag, but that tag is deprecated and so I'd prefer to avoid using a solution that may stop working in a future browser update.
Edit: I've uploaded a small HTML page which demonstrates the problem: http://www.wuala.com/zauber.paracelsus/Public/centering_test.html/
It is because your HTML is invalid.
You can't adding elements with default display:block into elements which are by default display:inline.
Change your span to div and it will work.
HTML
<div class='boxsection'>
<h4>Center</h4>
<pre><<center>>Some text in the middle<</center>></pre>
This macro causes the content inside of it to be centered.
</div>
CSS
.boxsection {
text-align:center;
border:1px solid #333;
padding:10px;
margin:10px;
background:1px solid #ccc;
}
http://codepen.io/Chovanec/pen/Hyxqe
(This is question about CSS/HTML.)
If I have a single-line paragraph that doesn't extend to the right margin and I've turned it into a text box by putting border around it, how can I keep that border from being extended all the way to the right margin?
<p style="border: 1px solid black;">
This is a test.
</p>
looks like this:
+-----------------------------------------------------------------------------+
| This is a test. |
+-----------------------------------------------------------------------------+
when I want it to look like this (without me having to guess at hard-coding margin-right):
+-----------------+
| This is a test. |
+-----------------+
I'm speaking here, of course, from a left-to-right orientation (so, not Hebrew or Arabic).
Thanks very much for your help.
simply use display: inline-block; on that element. + apply your border.
You could try this (warning: will not work on IE7):
<p id='yourPara'>
This is a test.
</p>
CSS
#yourPara {
border: 1px solid black;
display: inline-block;
}
If you don't want to change the display value of the p, then either use a different element that defaults to inline or wrap the text in the p with an inline element (like span, for example) and put the border on that.
JSFiddle
try this
<p>
<span style="border: 1px solid black;">This is a test.</span>
</p>
What I would do is float the paragraphs and then clear them:
p.neatBox {
float: left;
clear: both;
padding: 5px;
border: 1px solid blue;
}
See for example: http://jsfiddle.net/audetwebdesign/8GbkJ/
The advantage here is that you don't have to worry about inline-block's following each other in succession and perhaps appearing two or more per line.
The only thing to watch out for is that margins don't collapse on floated elements, so you would need to set either the top margin or the bottom margin to control the inter-paragraph spacing.
I have a page where I am displaying subheadings styles like this:
This looks fine until the text to be displayed exceeds a single line, when it looks like this:
What I would like to get is this:
i.e. the height of the decorative orange rectangle at the left should vary according to the height of the text.
Because we have a requirement that the decorative rectangle can be any colour, it is not done using an image. This is what we currently render:
<div class="header">
<div class="decor"> </div>
<h3>Text goes here</h3>
</div>
Is there a way I can style this using CSS to get the desired look? I'm happy to change the HTML used too. My restrictions are:
It must be possible for us to set the rectangle to any colour via CSS.
The heading text can vary, so we cannot apply specific hard-coded heights to specific headings via their IDs, it needs to work automatically.
DEMO
CSS
h3{
border-left:5px solid #F1592A;
background-color:#EEEEEE;
padding:2px;
}
I don't recommend using for styling (and keeping space is styling).
Padding is used to create inner element-spacing. And that's what you need.
Try adding the following CSS styling:
h3 {
padding-left: 10px; /* You can change this number */
}
You can create the left "decoration" by adding a border:
h3 {
padding-left: 10px; /* You can change this number */
border-left: 3px solid orange; /* You can change the color and width */
}
You can do something like this, http://jsfiddle.net/5SaCt/ . Set the left border to any color you want.
HTML
<div id="content">
1,2,3,4 <br/>
5,6,7,8
</div>
CSS
#content {
border-left:5px solid orange;
padding:5px;
width:500px;
height:auto;
}
OUTPUT:
I have been using the examples here to setup a webpage that has columns with equal heights (using only HTML and CSS), and it is working relatively well. Here is the complete HTML and CSS code that I am using.
Newbie questions:
(1) As you can see, I tried to make the left column (id="column_bottom") have a white (#f5f5f5) background with black text, and the right column (id="content_bottom") with black background with white (#f5f5f5) text, but one side is always overriding the other. What can I do to make it what I want?
(2) Also, you can see in the CSS that I have defined fonts and background colors for body, but somehow that is not carrying through, what should I do?
Thanks!
P.S. I am looking for a pure HTML/CSS solution, and prefer not to use javascript.
You're close. In your code, just change your styling to the columns themselves, like so:
#content_bottom {
color: #f5f5f5;
background:#000000; /* right column background colour */
}
#column_bottom {
color: #000000;
background:#f5f5f5; /* left column background colour */
}
the code below will create two boxes side-by-side and the container will always wrap those boxes, no matter how tall they are. this should solve your issue of having columns of the same height.
html:
<div class="container">
<div class="box">blah</div>
<div class="box">blah<br/><br/>blah</div>
<div class="clear"></div>
</div>
css:
.container { position:relative; width:100px; border:1px solid red; }
.box { position:relative; float:left; width:40px; border:1px solid blue; }
.clear { clear:both }