简体   繁体   English

设置以位置为相对位置的div的最小宽度

[英]set minimum width of a div having position as relative

How to style this div both with a min-width and width 如何风格这个div都是具有最小宽度宽度

css CSS

#diva {
   position: relative;
   margin: 0 auto;
   min-width: 75px;
   width: auto;
   height: 50px;
   padding: 4px;
   color: white;
   background-color: red;
}

html HTML

<div id="diva">
    hello
</div>

When i set width to auto , this div occupies the full page width. 当我将width设置为auto时 ,该div占据了整个页面的宽度。

display:inline-block;

Just add display:inline-block; 只需添加display:inline-block; to the styles for the div. div的样式。 That should work :) 那应该工作:)

http://jsfiddle.net/432kxywu/ http://jsfiddle.net/432kxywu/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM