English 中文(简体)
容器底部附于容器底部的元素
原标题:Element attaching to the bottom of container
I m trying to center a dot inside a div. When I try margin-bottom: 50%;, it pushes the other stuff around. I ve also tried setting justify-content and align-items to center. .slider{ width: 20px; height: 100px; display: flex; flex-direction: column; justify-content: space-evenly;a position: relative; border: 2px solid black; border-radius: 20px; } .line{ border-bottom: 2px solid black; display: flex; justify-content: center; align-items: center; } .selector{ width: 0px; height: 0px; border: 2px solid black; }
问题回答
You can eliminate the .line divs entirely, div element should be for content, not styling. Just use a repeating-linear-gradient to create the lines and then center as usual. Here I have added red lines at the horizontal and vertical centers to show the centered element. * { margin: 0; padding: 0; min-width: 0; min-height: 0; box-sizing: border-box; } .slider { margin: 1em; width: 20px; height: 100px; display: flex; flex-direction: column; align-items: center; justify-content: space-evenly; background: linear-gradient(black 0.1em, transparent 0.1em); background-size: 100% 20px; /* 100px / 5 */ background-position: 0 -2px; /* adjust for border size */ border: 2px solid black; border-radius: 20px; position: relative; } .selector { width: 4px; height: 4px; background: black; } /* demo only */ .slider:before { /* horizontal line */ content: ""; position: absolute; height: 1px; width: 100%; background: red; left: 0%; top: 50%; translate: 0 -50%; } .slider:after { /* vertical line */ content: ""; position: absolute; height: 100%; width: 1px; background: red; left: 50%; top: 0; translate: -50% }
You can set the height to 100% for line and margin: auto for the dot: .line{ border-bottom: 2px solid black; display: flex; height: 100%; } .selector{ border: 2px solid black; margin: auto; } .slider{ width: 20px; height: 100px; display: flex; flex-direction: column; justify-content: space-evenly;a position: relative; border: 2px solid black; border-radius: 20px; } .line{ border-bottom: 2px solid black; display: flex; height: 100%; } .selector{ border: 2px solid black; margin: auto; }




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

Drop down background url in Safari Issue

selectBox.selectCSS { background: url(/Images/replacementSelectBackground.png) top left no-repeat height:auto; } I have an issue in Safari only where the image is not rendering on top ...

CSS specific for Safari

How do you target specifically safari in css with styles?

Aligning textarea in a form

Ive used the following css code to align my form elements: form { position:relative; } form input { position:absolute; left:11em; } However, the textarea element is not aligned correctly with the ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

CSS problem with page footer

I have defined my page footer in the css file as: #footer { position: absolute; height: 50px; text-align: center; background: #66CCCC; bottom: 0px; left: 0px; width: 100%; height: ...

热门标签